Tweak memory management in train_from_config

This commit is contained in:
Matthw Honnibal 2020-05-21 19:32:04 +02:00
parent f075655deb
commit 3b5cfec1fc
1 changed files with 6 additions and 0 deletions

View File

@ -213,6 +213,12 @@ def train_from_config(
if is_best_checkpoint and output_path is not None:
nlp.to_disk(output_path)
progress = tqdm.tqdm(total=training["eval_frequency"], leave=False)
# Clean up the objects to faciliate garbage collection.
for eg in batch:
eg.doc = None
eg.goldparse = None
eg.doc_annotation = None
eg.token_annotation = None
finally:
if output_path is not None:
final_model_path = output_path / "model-final"