Enable CudaGraph Annotations - #4359
Conversation
| ) | ||
| self.fwd_bwd_fn = self._forward_backward_body | ||
| if not config.training.disable_cuda_graphs: | ||
| enable_cudagraph_annotations() |
There was a problem hiding this comment.
if it's always enabled, don't need this function -- just always set with torch.cuda.graph(..., enable_annotations=True)
| self.fwd_bwd_fn = self._forward_backward_body | ||
| if not config.training.disable_cuda_graphs: | ||
| enable_cudagraph_annotations() | ||
| config.profiler.trace_post_processor = ( |
There was a problem hiding this comment.
This probably should go to config, rather than being ad hoc-ly changed in trainer build. E.g. if there had been other processors, they'll be overwritten silently.
There was a problem hiding this comment.
I have removed trace_post_processor as a config. it was originally added to support annotation_post_processing. since we are have enable_annotations=True, we can just always run the post_processing.
it's a no-op when there is no annotation collected.
dd1fe05 to
67e06c7
Compare
| @unittest.skip( | ||
| "Precompiled artifacts do not provide example inputs for CUDA graph setup" | ||
| ) |
There was a problem hiding this comment.
will be fixed in the following PR.
|
|
||
| if post_processor is not None: | ||
| post_processor(output_file) | ||
| cudagraph_annotate_trace_post_processor(output_file) |
There was a problem hiding this comment.
need to make sure this doesn't fail on non-nvidia chips
Human Note: this is for enabling the mark_kernels, so that we see annotations in profiling trace when cudagraph is used.
Also removed the duplicated implementation in GraphTrainer.
Summary
Graph Trainer maintained its own CUDA graph manager and wrapper even though core TorchTitan already provided the same capture, warmup, input-copy, replay, and teardown behavior. The two implementations had begun to diverge, which made CUDA graph fixes and profiler annotation support harder to maintain.
This PR:
tensor_input_indicessupport to the coreCUDAGraphWrappertrace_post_processorconfiguration fieldtest_precompile_vs_trace, because loaded precompile artifacts currently provide no example inputs for CUDA graph setupThe precompile test will be fixed and re-enabled in a follow-up by constructing the wrapper with live inputs from the training loop instead of serializing inputs in the artifact.
Test plan
pytest -q tests/unit_tests/cpu/test_cudagraph.py torchtitan/experiments/graph_trainer/tests/test_precompile.py torchtitan/experiments/graph_trainer/tests/test_profiler.pypytest -q torchtitan/experiments/graph_trainer/tests/test_passes.py -k cudagraphpytest -q torchtitan/experiments/graph_trainer/tests/test_trace_module.py -k cudagraphpytest -q torchtitan/experiments/graph_trainer/tests/test_bitwise_deterministic.py::TestLlama3BitwiseDeterministic::test_aot_fx_trace_vs_eagerufmtandflake8checks