[distributed][tools] Fix MemoryTracker.load not restoring the operati… · pytorch/pytorch@b28aee9 · GitHub
Skip to content

Commit b28aee9

Browse files
ousamabenyounespytorchmergebot
authored andcommitted
[distributed][tools] Fix MemoryTracker.load not restoring the operation count (#192476)
Fixes #191397 ### Problem `MemoryTracker.save_stats()` did not persist `_op_index`, and `load()` did not restore it. After `load()`, `_op_index` stayed `0`, so `summary()`/`show_traces()` (which iterate `range(1, self._op_index)`) produced no output on a loaded tracker. ### Fix Persist `op_index` in `save_stats()` and restore it in `load()`, with a backward-compatible fallback (`stats.get("op_index", len(self.memories_allocated))`) for stats files written before this key existed. ### Test verification (RED → GREEN) New test `test_save_load_preserves_op_index`: ``` # RED (unmodified main): FAILED test_save_load_preserves_op_index # GREEN (with fix): 1 passed ``` > **Disclosure (per [AI_POLICY.md](https://github.com/pytorch/pytorch/blob/main/AI_POLICY.md)):** this change was prepared with AI assistance and was reviewed, tested, and is submitted by me. Happy to iterate on any feedback. Pull Request resolved: #192476 Approved by: https://github.com/d4l3k
1 parent 7da85ca commit b28aee9

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

‎test/distributed/_tools/test_memory_tracker.py‎

Lines changed: 34 additions & 0 deletions

‎torch/distributed/_tools/memory_tracker.py‎

Lines changed: 5 additions & 1 deletion

0 commit comments

Comments
 (0)