Repository navigation
Compress exported Kineto profiler traces as .json.gz - #3483
Merged
Merged
Conversation
Chrome trace JSON is highly compressible but was written uncompressed, which wastes disk on multi-rank profiling runs. PyTorch's `export_chrome_trace()` already supports `.gz` paths, and Perfetto accepts the compressed files unchanged.
niyunsheng
requested review from
fegin,
tianyu-l,
wconstab and
wwwjn
as code owners
June 2, 2026 13:16
|
|
SherlockNoMad
added a commit
that referenced
this pull request
Jun 4, 2026
…erics test (#3528) ## Why Both GraphTrainer scheduled CI workflows were red. The workflows run their test stages under `set -eux`, so the first failing command aborts the rest — which means fixing one failure unmasks the next. ### Default workflow — gzip trace regression (real bug, masked by a stale test) [#3483](#3483) switched the profiler to write gzip-compressed traces (`rank0_trace.json.gz`), but the consumer wasn't audited. `_cudagraph_annotate_trace_file` in `cudagraph.py` — attached to **every** graph_trainer run via `configs.py` — still read the trace with plain `open()` + `json.load()`, which raises `UnicodeDecodeError` on the gzip magic byte (`0x8b`). So any profiled run with CUDA-graph annotations would crash in the post-processor. `test_profiler.py` only flagged the path-suffix change (`.json` → `.json.gz`) because its `TestTracePostProcessorConfig` test used a **dummy callback** that just records the path and never exercises the real post-processor — so it masked the actual regression. ### Default workflow — `test_trace_module.py` optimizer Config drift (unmasked by the fix above) Once the profiler test stopped aborting the script early, the next stage surfaced its own failure: `test_trace_module.py::TestReparametrizeOptimizer::test_titan_optimizers_container` raised `TypeError: OptimizersContainer.Config.__init__() got an unexpected keyword argument 'name'`. [#3269](#3269) ("support mixed optimizers") reworked `OptimizersContainer.Config`: the flat `name=`/`lr=` fields were replaced by a `param_groups` list of `ParamGroupConfig` (`pattern` + `optimizer_name` + `optimizer_kwargs`). The test still used the old API. ### H100 workflow — flaky DSv3 MoE-EP crash `test_moe_dsv3_aot_fx_trace_vs_eager` fails as a flaky single-rank crash: aot_fx_trace losses match the eager baseline **bitwise through ~step 12**, then one EP rank hard-crashes (others SIGTERM). Root cause is unconfirmed — the crashing rank's traceback isn't captured because the numerics tests run through `loss_compare.py` → `run_train.sh --local-ranks-filter 0`, which tees only rank 0. (Note: the earlier "input_splits D2H race" theory is ruled out — [#3459](#3459) made that copy non-blocking intentionally, and the following blocking `output_splits` copy fences the stream.) ## What - `cudagraph.py`: make `_cudagraph_annotate_trace_file` read/write `.json.gz` via `gzip` (falls back to plain text for non-`.gz` paths). - `test_profiler.py`: fix the stale assertion and add `test_annotate_post_processor_round_trips_gzip_trace`, which drives the **real** post-processor over a gzip trace so this path is actually covered. - `test_trace_module.py`: update `test_titan_optimizers_container` to the new mixed-optimizer `OptimizersContainer.Config` API (`param_groups=[ParamGroupConfig(pattern=r".*", optimizer_name="AdamW", optimizer_kwargs={"lr": 1e-3})]`). - `test_numerics.py`: `@unittest.skip` the flaky `test_moe_dsv3_aot_fx_trace_vs_eager` to unblock CI, with a documented reason for re-enabling after diagnosis. ## Test - Default GraphTrainer 8-GPU workflow is **green** on this branch (all previously-masked stages now run: `test_trace_module`, `test_precompile`, precompile integration, `test_bitwise_deterministic`, `test_sac_peak_memory`). - Locally: `test_profiler.py` post-processor tests pass (E2E skips on CUDA < 13.1); `test_titan_optimizers_container` passes; `test_moe_dsv3_aot_fx_trace_vs_eager` skips. Verified the old `open()` path raises `UnicodeDecodeError` on the gzip file and the new path reads it. - `pre-commit` clean on all changed files.
ngimel
added a commit
to ngimel/torchtitan
that referenced
this pull request
Sep 3, 2026
torch is removing torch/cuda/_annotate_cuda_graph_trace.py, the offline joiner that merged CUDA-graph kernel annotations into an already-written trace. Its replacement is a cuda_graph_annotations argument on export_chrome_trace, which splices the annotations in during the export pass, so the trace is never read back and re-written -- for the gzipped traces the profiler has produced since pytorch#3483 that was paying the compression cost twice. The trace handler now passes get_cudagraph_annotations() straight to export_chrome_trace, and cudagraph_annotate_trace_post_processor goes away with its import. Passing an empty mapping is defined to mean the same as passing none, so the handler no longer needs the early return the post-processor had. The two post-processor tests are replaced by one that checks the handler hands the captured annotations to the export of the .json.gz path. The gzip round-trip case they covered is now torch's exporter picking compression off the file suffix, tested there rather than here. The argument is passed only when the installed torch accepts it, checked once against the export_chrome_trace signature. On an older torch the trace is still written, without the annotations, and a warning says so -- so this does not have to wait for the torch-side change to reach a nightly. Authored with assistance from Claude Code.
ngimel
added a commit
to ngimel/torchtitan
that referenced
this pull request
Sep 3, 2026
torch is removing torch/cuda/_annotate_cuda_graph_trace.py, the offline joiner that merged CUDA-graph kernel annotations into an already-written trace. Its replacement is a cuda_graph_annotations argument on export_chrome_trace, which splices the annotations in during the export pass, so the trace is never read back and re-written -- for the gzipped traces the profiler has produced since pytorch#3483 that was paying the compression cost twice. The trace handler now passes get_cudagraph_annotations() straight to export_chrome_trace, and cudagraph_annotate_trace_post_processor goes away with its import. Passing an empty mapping is defined to mean the same as passing none, so the handler no longer needs the early return the post-processor had. The two post-processor tests are replaced by one that checks the handler hands the captured annotations to the export of the .json.gz path. The gzip round-trip case they covered is now torch's exporter picking compression off the file suffix, tested there rather than here. The argument is passed only when the installed torch accepts it, checked once against the export_chrome_trace signature. On an older torch the trace is still written, without the annotations, and a warning says so -- so this does not have to wait for the torch-side change to reach a nightly. Authored with assistance from Claude Code.
tianyu-l
pushed a commit
that referenced
this pull request
Sep 3, 2026
torch is removing torch/cuda/_annotate_cuda_graph_trace.py, the offline joiner that merged CUDA-graph kernel annotations into an already-written trace. Its replacement is a cuda_graph_annotations argument on export_chrome_trace, which splices the annotations in during the export pass, so the trace is never read back and re-written -- for the gzipped traces the profiler has produced since #3483 that was paying the compression cost twice. The trace handler now passes get_cudagraph_annotations() straight to export_chrome_trace, and cudagraph_annotate_trace_post_processor goes away with its import. Passing an empty mapping is defined to mean the same as passing none, so the handler no longer needs the early return the post-processor had. The two post-processor tests are replaced by one that checks the handler hands the captured annotations to the export of the .json.gz path. The gzip round-trip case they covered is now torch's exporter picking compression off the file suffix, tested there rather than here. Depends on the torch-side change; until it lands in a nightly, export_chrome_trace does not accept cuda_graph_annotations. Authored with assistance from Claude Code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
.json.gzinstead of.json.export_chrome_trace()handles gzip natively; Perfetto loads them correctly.Test plan
outputs/profiling/traces/iteration_*/rank*_trace.json.gz~5 MB → ~302 KB(>16×compression)rank0_trace.json.gzin https://ui.perfetto.dev/ — loads and parses correctly