[PyTorch] [torch.compile] Prepare the custom-op framework and LayerNorm modules for compile wiring - #44
Open
pggPL wants to merge 1 commit into
Open
Conversation
…rm modules for compile wiring Behavior-neutral groundwork for registering LayerNormLinear and LayerNormMLP as torch.compile custom ops (follows the Linear split NVIDIA#2967 / NVIDIA#3053). dynamo/custom_op.py: - A bwd args dataclass may declare GRAD_OUTPUT_FIELDS naming one grad field per user output; the LN modules have two differentiable outputs (out and the returned norm output), so a single grad_output slot is not enough. - Dict[str, <simple>] annotations are bundle-simple (activation_params). module/_common.py: sp_out_leading / sp_inp_leading / fake_workspace_valid shared by Linear and the LN modules (moved out of linear.py). layernorm_linear.py / layernorm_mlp.py: - GRAD_OUTPUT_FIELDS on the bwd args; fp8_output carried in the fwd args. - inp_shape is rederived from grad_output in backward instead of being stored on the bwd args (SymInt dims are not hashable in the value bundle). - LayerNormMLP: the recipe object no longer rides on the backward args; the properties the backward needs (float8_block_scaling, custom, dbias-dact fusion availability) are bools computed in Module.forward. The activation tables are split into per-activation (act, dact) pairs plus the fused dbias kernels so the backward looks them up without a recipe. - The returned-norm-output grad is tolerated as None in backward. No functional change. Signed-off-by: Pawel Gadzinski <pgadzinski@nvidia.com>
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
Behavior-neutral groundwork for registering
LayerNormLinearandLayerNormMLPastorch.compilecustom ops (framework from NVIDIA#3053). Part 2 of 3: sits on #42 (the module restructuring) and is the base of the wiring PR (#43).Type of change
Changes
dynamo/custom_op.pyGRAD_OUTPUT_FIELDS, naming one grad field per user output. The LN modules have two differentiable outputs (outand the optionally returned norm output), so a singlegrad_outputslot is not enough.Dict[str, <simple>]annotations are bundle-simple (needed foractivation_params).module/_common.py:sp_out_leading/sp_inp_leading/fake_workspace_validshared byLinearand the LN modules (moved out oflinear.py,linear.pyupdated to import them).layernorm_linear.py/layernorm_mlp.pyGRAD_OUTPUT_FIELDSon the bwd args;fp8_outputcarried in the fwd args (the compile gate needs it).inp_shapeis rederived fromgrad_outputin backward instead of being stored on the bwd args (SymInt dims are not hashable in the value bundle underdynamic=True).LayerNormMLP: the recipe object no longer rides on the backward args; the properties the backward needs (float8_block_scaling,custom, dbias-dact fusion availability) are bools computed inModule.forward. The activation tables are split into per-activation(act, dact)pairs plus the fused dbias kernels, so the backward looks them up without a recipe object.Nonein backward.Testing (RTX Ada, single GPU)
Same suites as #42, unchanged results:
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 passed; existingtest_torch_compile.py(Linear / DPA) unchanged; pylint 10/10.Checklist: