Skip to content

Commit

Permalink
add a test that reproduces a memory leak in learner (skipped state)
Browse files Browse the repository at this point in the history
  • Loading branch information
stas00 committed Nov 12, 2018
1 parent f6e6c84 commit 2f9697a
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/test_text_train.py
Expand Up @@ -51,3 +51,23 @@ def test_classifier():
assert last_layer(classifier.model).out_features == n_labels if n_labels > 1 else n_labels+1
finally:
shutil.rmtree(path)

# XXX: may be move into its own test module?
import gc
# everything created by this function should be freed at its exit
def clean_destroy_block():
path, df_trn, df_val = prep_human_numbers()
data = TextLMDataBunch.from_df(path, df_trn, df_val, tokenizer=Tokenizer(BaseTokenizer))
learn = language_model_learner(data, emb_sz=100, nl=1, drop_mult=0.)
learn.lr_find()

@pytest.mark.skip(reason="memory leak to be fixed")
def test_mem_leak():
gc.collect()
garbage_before = len(gc.garbage) # should be 0 already, or something leaked earlier
assert garbage_before == 0
clean_destroy_block()
gc_collected = gc.collect() # should be 0 too - !0 means we have circular references
assert gc_collected == 0
garbage_after = len(gc.garbage) # again, should be 0, or == garbage_before
assert garbage_after == 0

0 comments on commit 2f9697a

Please sign in to comment.