Skip to content

Commit ed2bbc0

Browse files
authored
Refine GC logging (#1234)
Improve the code based on the #1230 (comment)
1 parent f8f545c commit ed2bbc0

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

torchtitan/tools/utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,18 @@ def __init__(self, gc_freq: int = 1000, debug: bool = False):
5050

5151
def run(self, step_count: int):
5252
if self.debug:
53-
logger.info("Force GC to perform collection to obtain debug information.")
53+
self.collect(
54+
"Force GC to perform collection to obtain debug information.",
55+
generation=2,
56+
)
5457
gc.collect()
5558
elif step_count > 1 and step_count % self.gc_freq == 0:
5659
self.collect("Peforming periodical GC collection.")
5760

5861
@staticmethod
59-
def collect(reason: str):
62+
def collect(reason: str, generation: int = 1):
6063
begin = time.monotonic()
61-
gc.collect(1)
64+
gc.collect(generation)
6265
logger.info("[GC] %s %.2f seconds.", reason, time.monotonic() - begin)
6366

6467

0 commit comments

Comments
 (0)