Skip to content

[BUG] Fix/fp32 residual te layernorm linear - #5073

Open
yezhengmao1 wants to merge 3 commits into
NVIDIA:mainfrom
yezhengmao1:fix/fp32-residual-te-layernorm-linear
Open

[BUG] Fix/fp32 residual te layernorm linear#5073
yezhengmao1 wants to merge 3 commits into
NVIDIA:mainfrom
yezhengmao1:fix/fp32-residual-te-layernorm-linear

Conversation

@yezhengmao1

Copy link
Copy Markdown
Contributor

What does this PR do ?

Cast fp32 input to params_dtype inside TELayerNormColumnParallelLinear.forward so that fp32_residual_connection=True no longer trips TE's set_activation_dtype check 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_fc1 are TELayerNormColumnParallelLinear and the matching *_layernorm is IdentityOp, so fp32
hidden_states flow straight into TE which strictly rejects input.dtype != param.dtype outside autocast. This PR downcasts the input to layer_norm_weight.dtype; residual precision is preserved upstream in
bias_dropout_add.

Contribution process

Pre-checks

  • I have added relevant unit tests
  • I have added relevant functional tests
  • I have added proper typing to my code Typing guidelines
  • I have added relevant documentation
  • I have run the autoformatter.sh on my PR

…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.
@yezhengmao1
yezhengmao1 requested review from a team as code owners May 30, 2026 09:26
@copy-pr-bot

copy-pr-bot Bot commented May 30, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

@svcnvidia-nemo-ci
svcnvidia-nemo-ci marked this pull request as draft May 30, 2026 09:27
@github-actions

Copy link
Copy Markdown
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:

  1. Add the oncall reviewer (optional reviewer)
  2. Add required review teams based on your changes

See the contribution guide for more details.

@yezhengmao1
yezhengmao1 marked this pull request as ready for review June 11, 2026 03:35
@svcnvidia-nemo-ci
svcnvidia-nemo-ci requested a review from a team June 11, 2026 03:35
@svcnvidia-nemo-ci svcnvidia-nemo-ci added Final Review PR is in the "final review" stage waiting-on-maintainers Waiting on maintainers to respond labels Jun 11, 2026
@guihong-nv

Copy link
Copy Markdown
Contributor

/ok to test 0b5aa07

@guihong-nv

Copy link
Copy Markdown
Contributor

@yezhengmao1 To fix the linting issue, you can check tools/autoformat.sh

@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-maintainers Waiting on maintainers to respond waiting-on-customer Waiting on the original author to respond labels Jun 12, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond and removed waiting-on-customer Waiting on the original author to respond labels Jul 3, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-customer Waiting on the original author to respond and removed waiting-on-maintainers Waiting on maintainers to respond labels Jul 10, 2026
@svcnvidia-nemo-ci svcnvidia-nemo-ci added waiting-on-maintainers Waiting on maintainers to respond waiting-on-customer Waiting on the original author to respond and removed waiting-on-customer Waiting on the original author to respond waiting-on-maintainers Waiting on maintainers to respond labels Aug 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

community-request Final Review PR is in the "final review" stage waiting-on-customer Waiting on the original author to respond

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants