Repository navigation
Conversation
Register LayerNorm, RMSNorm and L2Normalization forward and backward as torch.compile custom ops with shape-only fake implementations. A same-named subclass, such as the module-level RMSNorm wrapper, shares its parent's custom ops instead of registering duplicates. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
…ompile tests Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
|
/te-ci pytorch L0 |
[Medium impact] The changes reach PyTorch normalization stacks and models compiled through `te.ops.Sequential`. The PR still needs a fix because eager normalization backward can empty the caller's input. Findings
SummaryAdds
Reviews (2) · Last reviewed commit: "Use explicit inherit_compile_ops and mir..." · Reviewed by Greptile |
| if not in_custom_op: | ||
| clear_tensor_data(args.input_, args.means, args.rstdevs) |
There was a problem hiding this comment.
When a contiguous input already has the compute dtype, LayerNorm now saves the original tensor. Eager backward passes that same object to clear_tensor_data, which replaces its .data with an empty tensor. Previously, it cleared a separate flattened view, leaving the caller's tensor intact. This can destroy a retained input or break another backward branch that needs it. RMSNorm and its fused backward path have the same problem. Keep a separate saved view, or avoid clearing the original input.
Knowledge Base Used: PyTorch tensor and operator abstractions
Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
|
/te-ci pytorch L0 |
Description
Add
torch.compilesupport for normalization operations (LayerNorm,RMSNorm,L2Normalization) inte.ops.Sequential, enabling full-graph compilation of normalized MLPs and standalone normalization stacks (including quantized outputs, autocast, dynamic shapes, and multi-dimensionalnormalized_shape).Type of change
Changes
te.ops.LayerNorm,te.ops.RMSNorm, andte.ops.L2Normalization, requiring contiguous forward inputs undertorch.compileand reporting CPU offloading as unsupported.inherit_compile_opsclass keyword argument toFusibleOperation.__init_subclass__and use it inte.LayerNormandte.RMSNormwrappers so they share their parent operation's custom ops.(-1, inner_dim)inBackwardAddRMSNormso multi-dimensionalnormalized_shapeworks in the fused backward path, and extendtest_backward_add_rmsnormwith a 2Dnormalized_shape.torch.compiletests intests/pytorch/test_torch_compile.pycovering normalized MLPs (with FP8/MXFP8/NVFP4 recipes),LayerNorm/RMSNorm/L2Normalizationvariants (dtypes, strided rejection, FP8 input, inference), autocast (zero_centered_gamma,te.LayerNorm/te.RMSNorm), dynamic shapes, and multi-dimensionalnormalized_shape(unquantized and FP8).Checklist: