Repository navigation
[PyTorch] [torch.compile] Prepare LayerNormLinear and LayerNormMLP for torch.compile - #3493
Conversation
…r torch.compile Restructure the two modules the same way Linear was restructured in NVIDIA#2967, so the follow-up custom-op registration is a pure wiring change: - LayerNormLinearFwdArgs / LayerNormLinearBwdArgs and LayerNormMLPFwdArgs / LayerNormMLPBwdArgs dataclasses replace the positional non_tensor_args tuple and the ad-hoc ctx.<attr> plumbing. - The autograd Functions shrink to thin wrappers around module-level _layernorm_{linear,mlp}_forward_impl / _setup_ctx / _backward_impl that take one dataclass argument. Saved tensors that alias forward inputs or outputs are deduplicated by name and rebuilt in setup_ctx. - LayerNormMLP keeps activation checkpointing: the forward saves only its inputs, and _layernorm_mlp_recompute re-runs the forward impl in backward with recompute_for_bwd set, filling the backward args from the recomputed state. - The weight workspaces move from positional autograd inputs into the args bag and are returned as extra outputs; backward-only recipe knobs (split accumulators, backward_override, debug UB flags, delayed wgrad_store) are resolved in Module.forward. - check_fp8_reduce_and_update moves to module/_common.py and is shared with Linear. No functional change. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
setup_ctx rebuilds the inp/ln_out save slots as fresh views, which drop the activation-offload mark set in forward, so the V1 offload path kept these activations on GPU. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Pass the live weight-gradient store to LayerNormLinear and LayerNormMLP backward regardless of its state during forward. This preserves mode changes before backward and prevents backward_dw from reading an empty queue. Add numerical regressions for both toggle directions, including LayerNormMLP activation checkpointing. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
|
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
|
CPU-overhead check vs. base
|
|
LGTM, pending ci and merge confix fix Minor questions:
In #3343, which enables recipe update at runtime, I enforce recompilation with the recipe update. I wonder how much time it takes to re-compile some representable model e.g. DSv3. |
Preserve the MXFP8 cuBLASMp gradient gathering fixes in the extracted LayerNormMLP backward implementation. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
|
/te-ci pytorch |
Yes
It is not, but we aim to reducing cpu overhead of non-te parts of the model. My PRs will allow TE not to do graph break which adds addidtional cpu overhead and prevents as from using cuda graphs backend.
I haven't measure it, but it is one-time cost and everything is cached, so if we change recipe more than once the cost should be neglible. |
Description
Restructure
LayerNormLinearandLayerNormMLPthe same wayLinearwas restructured fortorch.compile, so that the follow-up PR registering them astorch.compilecustom ops is a pure wiring change.No functional change intended.
Type of change
Changes
LayerNormLinearFwdArgs/LayerNormLinearBwdArgsandLayerNormMLPFwdArgs/LayerNormMLPBwdArgsdataclasses replace the positionalnon_tensor_argstuple and the ad-hocctx.<attr>plumbing._layernorm_{linear,mlp}_forward_impl/_setup_ctx/_backward_implthat take one dataclass argument (the shape the custom-op framework expects). Saved tensors that alias forward inputs or outputs are deduplicated by name (saved_tensor_aliases) and rebuilt insetup_ctx.LayerNormMLPkeeps activation checkpointing: the forward saves only its inputs, and_layernorm_mlp_recomputere-runs the forward impl in backward withrecompute_for_bwdset, filling the backward args from the recomputed state.Linear). Backward-only recipe knobs (dgrad/wgrad_use_split_accumulator,backward_override, debug UB flags, delayedwgrad_store) are resolved inModule.forward.check_fp8_reduce_and_updatemoves tomodule/_common.pyand is shared withLinear.Testing (RTX Ada, single GPU)
tests/pytorch/test_sanity.py -k "layernorm_linear or layernorm_mlp": 7344 passedtests/pytorch/test_numerics.py -k "layernorm_linear or layernorm_mlp": 738 passedtests/pytorch/test_backward_override.py: 1316 passedtests/pytorch/test_cuda_graphs.py -k "layernorm or mlp": 105 passedtest_gpt_full_activation_recompute(checkpoint recompute path): same pass/fail pattern asmain(known Ada flakiness)Checklist: