Repository navigation
[distributed][tools] Fix MemoryTracker.load not restoring the operation count - #192476
ousamabenyounes wants to merge 1 commit into
Conversation
|
|
|
|
|
The following ciflow label(s) have been added but CI has not been triggered yet because the workflows are awaiting approval:
Once a maintainer approves the workflows (scroll to the bottom of the PR page), the corresponding CI jobs will be triggered automatically. Please ping one of the reviewers if you do not have access to approve and run workflows. |
5d9a5e3 to
3991310
Compare
|
@pytorchbot merge |
|
@pytorchbot merge -i |
Merge startedYour change will be merged while ignoring the following 4 checks: BC Lint, docs-build, pull, torchtitan-test / torchtitan-x-pytorch-test / test (torchtitan_models_integration, 1, 1, mt-l-x86aavx2-189-704-a10g-8) Learn more about merging in the wiki. Questions? Feedback? Please reach out to the PyTorch DevX Team |
Merge failedReason: Command Details for Dev Infra teamRaised by workflow job |
save_stats() persisted the memory traces but not _op_index, and load() restored the traces without reconstructing it. summary() and show_traces() bound their iteration with _op_index, so after a save/load round trip the loaded tracker reported no operator deltas even though the trace entries were present. Persist op_index in save_stats() and restore it in load(), falling back to the number of recorded operations for stats files written before op_index was saved. Add a CPU regression test asserting the restored op count and that summary() still emits the per-operator deltas. Fixes pytorch#191397
3991310 to
58c640c
Compare
|
@pytorchbot merge |
…on 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
…on count (pytorch#192476) Fixes pytorch#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: pytorch#192476 Approved by: https://github.com/d4l3k

Fixes #191397
Problem
MemoryTracker.save_stats()did not persist_op_index, andload()did not restore it. Afterload(),_op_indexstayed0, sosummary()/show_traces()(which iteraterange(1, self._op_index)) produced no output on a loaded tracker.Fix
Persist
op_indexinsave_stats()and restore it inload(), 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: