[PyTorch] [torch.compile] torch.compile support for LayerNormLinear and LayerNormMLP - #43
Open
pggPL wants to merge 1 commit into
Open
[PyTorch] [torch.compile] torch.compile support for LayerNormLinear and LayerNormMLP#43pggPL wants to merge 1 commit into
pggPL wants to merge 1 commit into
Conversation
8 tasks
pggPL
force-pushed
the
layernorm_compile
branch
from
September 3, 2026 12:42
90f05e3 to
9422845
Compare
pggPL
changed the base branch from
layernorm_compile_refactor
to
layernorm_compile_prep
September 3, 2026 12:42
8 tasks
…nd LayerNormMLP Register the LayerNormLinear and LayerNormMLP forward/backward as torch.library custom ops on top of the framework from NVIDIA#3053, so both trace under fullgraph compile with the FP8/MXFP8/NVFP4 recipes. Builds on the module restructuring and the framework groundwork in the two preceding PRs. layernorm_linear.py / layernorm_mlp.py: - compile_unsupported_reason gate, data-free forward/backward fakes on TensorSpec, register_custom_op, @no_torch_dynamo eager wrapper, compiled dispatch and eager fallback in Module.forward, mirroring Linear. - Eager fallbacks: debug, quantized input, fsdp_group, differentiable fp8_output, CPU offload, delayed wgrad, FP8 weight caching, fuse_wgrad_accumulation, non-opaque quantizers; MLP also activation checkpointing and gemm_gelu_fusion under FP8. tests/pytorch/test_torch_compile.py: LN module coverage (recipes x compile modes, norm/activation/return_layernorm_output variants, FP8 primary weight, frozen weights / no bias, dynamic shapes, eager fallbacks). Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
pggPL
force-pushed
the
layernorm_compile
branch
from
September 3, 2026 12:49
9422845 to
4cfffaf
Compare
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.
Description
Register
LayerNormLinearandLayerNormMLPastorch.compilecustom ops on top of the framework merged in NVIDIA#3053, so both trace underfullgraph=Truewith the FP8 / MXFP8 / NVFP4 recipes. Part 3 of 3: sits on #44 (framework + module groundwork), which sits on #42 (module restructuring). This PR is only the compile wiring itself.Type of change
Changes
layernorm_linear.py/layernorm_mlp.py(mirrorsLinear)compile_unsupported_reasongate on the fwd args._*_forward_fake/_*_backward_fakeonTensorSpec, mirroring the impls' saved-tensor layout and alias dedup.register_custom_op(...),@no_torch_dynamoeager wrapper (_*_eager), compiled dispatch +_compile_eager_fallback_reason/_forward_eager_fallbackinModule.forward;@no_torch_dynamocomes offModule.forward.fullgraph=True): debug, quantized input,fsdp_group, differentiablefp8_output, CPU offload, delayed wgrad, FP8 weight caching (is_first_microbatch),fuse_wgrad_accumulation, non-opaque quantizers; MLP additionallycheckpoint=Trueandgemm_gelu_fusionunder FP8.Tests (
tests/pytorch/test_torch_compile.py): recipes x compile modes (default, reduce-overhead) for both modules, norm / activation /return_layernorm_output/zero_centered_gammavariants, FP8 primary weight, no-bias and frozen-weight slots, dynamic shapes, eager fallbacks.Testing (RTX Ada, single GPU)
tests/pytorch/test_torch_compile.py: 160 passed, 46 skipped, 1 xpassed (43 new LN tests)test_sanity.py -k "layernorm_linear or layernorm_mlp"7344 passed,test_numerics.py -k "layernorm_linear or layernorm_mlp"738 passed,test_backward_override.py1316 passed,test_cuda_graphs.py -k "layernorm or mlp"105 passedNot covered on a single GPU: TP/SP and Userbuffers under compile.
Checklist: