[graph_trainer] Add remat pass and torch.no_grad() execution to minimal_fx_tracer#2767
Closed
tugsbayasgalan wants to merge 1 commit intogh/tugsbayasgalan/12/basefrom
Closed
[graph_trainer] Add remat pass and torch.no_grad() execution to minimal_fx_tracer#2767tugsbayasgalan wants to merge 1 commit intogh/tugsbayasgalan/12/basefrom
tugsbayasgalan wants to merge 1 commit intogh/tugsbayasgalan/12/basefrom
Conversation
…al_fx_tracer
- Annotate backward FX nodes with {"remat_pass_tag": "is_backward"} during
_patch_engine_run_backward so remat_using_tags_for_fwd_loss_bwd_graph can
identify the forward/backward boundary.
- Apply remat_using_tags_for_fwd_loss_bwd_graph as a default post-trace pass.
Nodes tagged PREFER_RECOMPUTE (from selective AC) are duplicated before
backward and the forward copies are DCE'd, reducing peak memory.
- Execute traced graph under torch.no_grad() since the graph already contains
explicit backward ops. Without this, PyTorch builds a redundant autograd
graph keeping all forward intermediates alive via grad_fn references.
- Add test_llama_1b_peak_memory: verifies traced+AC peak memory is within 20%
of eager+AC on Llama 1B (BS=2, seq=2048, bf16).
[ghstack-poisoned]
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.
Stack from ghstack (oldest at bottom):
_patch_engine_run_backward so remat_using_tags_for_fwd_loss_bwd_graph can
identify the forward/backward boundary.
Nodes tagged PREFER_RECOMPUTE (from selective AC) are duplicated before
backward and the forward copies are DCE'd, reducing peak memory.
explicit backward ops. Without this, PyTorch builds a redundant autograd
graph keeping all forward intermediates alive via grad_fn references.
of eager+AC on Llama 1B (BS=2, seq=2048, bf16).