Skip to content

Commit d6ed956

Browse files
authored
Update garbage collection assertion (#1959)
* Update garbage collection assertion to a more reliable one Signed-off-by: Behrooz <[email protected]> * Remove print Signed-off-by: Behrooz <[email protected]>
1 parent 0813ae5 commit d6ed956

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tests/test_handler_garbage_collector.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,16 @@ def _train_func(engine, batch):
6060
GarbageCollector(trigger_event=trigger_event, log_level=30).attach(engine)
6161

6262
engine.run(data_loader, max_epochs=5)
63-
print(gb_count_dict)
6463

6564
first_count = 0
66-
for epoch, gb_count in gb_count_dict.items():
67-
# At least one zero-generation object
65+
for iter, gb_count in gb_count_dict.items():
66+
# At least one zero-generation object is collected
6867
self.assertGreater(gb_count[0], 0)
69-
if epoch == 1:
70-
first_count = gb_count[0]
71-
else:
72-
# The should be less number of collected objects in the next calls.
73-
self.assertLess(gb_count[0], first_count)
68+
if iter > 1:
69+
# Since we are collecting all objects from all generations manually at each call,
70+
# starting from the second call, there shouldn't be any 1st and 2nd generation objects available to collect.
71+
self.assertEqual(gb_count[1], first_count)
72+
self.assertEqual(gb_count[2], first_count)
7473

7574

7675
if __name__ == "__main__":

0 commit comments

Comments
 (0)