[BUG] Fix/fp32 residual te layernorm linear - #5073
Open
yezhengmao1 wants to merge 3 commits into
Open
Conversation
…ar to unblock fp32_residual_connection When fp32_residual_connection=True the residual stream is fp32 and bias_dropout_add propagates that dtype to hidden_states. In the TE GPT layer spec input_layernorm/pre_mlp_layernorm is IdentityOp (folded into the fused TELayerNormColumnParallelLinear), so nothing casts back to params_dtype before this op. TE's set_activation_dtype strictly rejects input dtype != param dtype outside autocast, so the forward dies on the very first layer of a bf16 model with --fp32-residual-connection. Downcast input to layer_norm_weight.dtype at the top of forward. Residual-accumulation precision is preserved upstream in bias_dropout_add (fixed by NVIDIA#3504); only the input to LN+GEMM is brought back to params_dtype, which is what the op is configured to run in anyway. Add TestFp32ResidualTELayerNormLinear covering the path: SelfAttention from the TE submodules with bf16 params, fed an fp32 hidden_states. Without this fix the forward raises in TE; with the fix it returns a bf16 output of the expected shape.
svcnvidia-nemo-ci
marked this pull request as draft
May 30, 2026 09:27
Contributor
|
This PR has been automatically converted to draft because all PRs must start as drafts. When you are ready for review, click Ready for Review to begin the review process. This will:
See the contribution guide for more details. |
yezhengmao1
marked this pull request as ready for review
June 11, 2026 03:35
Contributor
|
/ok to test 0b5aa07 |
Contributor
|
@yezhengmao1 To fix the linting issue, you can check |
Co-Authored-By: Claude Fable 5 <noreply@anthropic.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.
What does this PR do ?
Cast fp32 input to params_dtype inside
TELayerNormColumnParallelLinear.forwardso thatfp32_residual_connection=Trueno longer trips TE'sset_activation_dtypecheck on the fused LN+GEMM path.Issue tracking
Linked issue: Related to #1402
The residual-stream part of #1402 was fixed by #3504, but with the TE GPT layer spec
linear_qkv/linear_fc1areTELayerNormColumnParallelLinearand the matching*_layernormisIdentityOp, so fp32hidden_states flow straight into TE which strictly rejects
input.dtype != param.dtypeoutside autocast. This PR downcasts the input tolayer_norm_weight.dtype; residual precision is preserved upstream inbias_dropout_add.Contribution process
Pre-checks