memory leak ctc_beam_search_decoder
Created by: mrfox321
If I repeatedly call the swig decoder ctc_beam_search_decoder,
I get a memory leak of around 10MB per iteration.
def score():
scorer = Scorer(alpha,beta,language_model_path,vocab)
best_path = ctc_beam_search_decoder(probs_seq2,vocab,beam_size,
cutoff_prob=cutoff_p,cutoff_top_n=cutoff_n,
ext_scoring_func=scorer)
print best_path[0][1]
for i in range(num_iter):
score()
Here is the memory profiler output after the first iteration:
Line Mem usage Increment Line Contents ================================================ 21 35.6 MiB 35.6 MiB @profile 22 def score(): 23
24 878.4 MiB 842.7 MiB scorer = Scorer(alpha,beta,language_model_path,vocab) 25 878.4 MiB 0.0 MiB best_path = ctc_beam_search_decoder(probs_seq2,vocab,beam_size, 26 878.4 MiB 0.0 MiB cutoff_prob=cutoff_p,cutoff_top_n=cutoff_n, 27 878.7 MiB 0.4 MiB ext_scoring_func=scorer) 28 878.7 MiB 0.0 MiB print best_path[0][1]
and after N iterations:
Line # Mem usage Increment Line Contents ================================================ 21 1446.4 MiB 1446.4 MiB @profile 22 def score(): 23
24 2061.3 MiB 614.9 MiB scorer = Scorer(alpha,beta,language_model_path,vocab) 25 2061.3 MiB 0.0 MiB best_path = ctc_beam_search_decoder(probs_seq2,vocab,beam_size, 26 2061.3 MiB 0.0 MiB cutoff_prob=cutoff_p,cutoff_top_n=cutoff_n, 27 2061.3 MiB 0.0 MiB ext_scoring_func=scorer) 28 2061.3 MiB 0.0 MiB print best_path[0][1]
it seems that when I change the loop to:
for j in range(100):
scorer = Scorer(alpha,beta,language_model_path,vocab)
for i in range(num_iter):
score()
del scorer
The memory leak occurs in the outer loop associated with the construction of the scorer. The memory is roughly constant in each inner loop iteration.
Additionally, if I do not run score(),
the construction of scorer
does not leak.