Port train CLI updates

Updates from #5362 and fix from #5387:

* `train`:

  * if training on GPU, only run evaluation/timing on CPU in the first
    iteration

  * if training is aborted, exit with a non-0 exit status
This commit is contained in:
Adriane Boyd 2020-06-03 14:03:43 +02:00
parent 581bda9f98
commit f1f9c8b417

View File

@ -458,6 +458,9 @@ def train(
cpu_wps = nwords / (end_time - start_time) cpu_wps = nwords / (end_time - start_time)
else: else:
gpu_wps = nwords / (end_time - start_time) gpu_wps = nwords / (end_time - start_time)
# Evaluate on CPU in the first iteration only (for
# timing) when GPU is enabled
if i == 0:
with use_ops("numpy"): with use_ops("numpy"):
nlp_loaded = util.load_model_from_path(epoch_model_path) nlp_loaded = util.load_model_from_path(epoch_model_path)
for name, component in nlp_loaded.pipeline: for name, component in nlp_loaded.pipeline:
@ -550,7 +553,7 @@ def train(
) )
break break
except Exception as e: except Exception as e:
msg.warn(f"Aborting and saving final best model. Encountered exception: {e}") msg.warn(f"Aborting and saving final best model. Encountered exception: {e}", exits=1)
finally: finally:
best_pipes = nlp.pipe_names best_pipes = nlp.pipe_names
if disabled_pipes: if disabled_pipes: