Skip to content

Fix residual gradient in non-learnable LayerNorm backward - #449

Merged
shijieliu merged 2 commits into
NVIDIA:mainfrom
rocketbastard:main
Sep 1, 2026
Merged

shijieliu merged 2 commits into
NVIDIA:mainfrom
rocketbastard:main

Conversation

@rocketbastard

Copy link
Copy Markdown
Contributor

Description

Fix residual gradient accumulation in the non-learnable LayerNorm backward path.

  • Fuse dx_accumulate into the _layer_norm_bwd_dx Triton kernel.
  • Remove the separate PyTorch dx.add_() operation.
  • Add focused numerical unit tests for the LayerNorm operator.

Supersedes #447 because the original fork was deleted.
Fixes #446

Testing

The added unit tests passed successfully in the local GPU environment.

Checklist

  • I am familiar with the Contributing Guidelines.
  • New or existing tests cover these changes.
  • The documentation is up to date with these changes.

@greptile-apps

greptile-apps Bot commented Aug 6, 2026 •

Copy link
Copy Markdown
Contributor

Greptile Summary

The PR moves residual-gradient accumulation into the non-learnable Triton LayerNorm backward kernel and adds focused numerical coverage.

  • Passes the optional accumulation tensor and row stride into the backward kernel.
  • Adds the residual gradient before storing the computed input gradient.
  • Tests float32 and bfloat16 behavior across contiguous-feature tensors with padded row strides.

Confidence Score: 4/5

The kernel fix appears sound, but the unresolved test import must be corrected before merging because it prevents the new test module from being collected in the standard repository test environment.

The current test still imports ops from a package located under examples/hstu, while the surrounding test configuration does not add that directory to Python's import path, leaving the previously reported collection failure outstanding.

Files Needing Attention: examples/tests/commons/test_triton_layer_norm.py

Important Files Changed

Filename Overview
examples/hstu/ops/triton_ops/triton_layer_norm.py Fuses optional residual-gradient accumulation into the non-learnable LayerNorm backward kernel.
examples/tests/commons/test_triton_layer_norm.py Adds numerical backward tests, but the previously reported unresolved top-level ops import remains.

Reviews (2): Last reviewed commit: "Add gradient accumulation support in lay..." | Re-trigger Greptile

@JacoCheung

Copy link
Copy Markdown
Collaborator

/build

@JacoCheung

Copy link
Copy Markdown
Collaborator

Hi @rocketbastard could you move the test code to hstu-specific test file ?

@JacoCheung

JacoCheung commented Aug 20, 2026 •

Copy link
Copy Markdown
Collaborator

❌ Pipeline #63652527 -- failed

Job Status Log
pre_check ❌ failed view
train_build_x86 ✅ success view
train_build_arm64 ✅ success view
prepare-jet-b200-smoke ✅ success view
prepare-jet-b200-inference ✅ success view
prepare-jet-cw-dfw-e2e-benchmark ✅ success view
build_whl ✅ success view
dynamicemb_test_fwd_bwd_8gpus ✅ success view
dynamicemb_test_load_dump_8gpus ✅ success view
unit_test_1gpu_a100 ❌ failed view
unit_test_1gpu_h100 ❌ failed view
unit_test_4gpu ❌ failed view
unit_test_tp_4gpu ❌ failed view
L20_unit_test_1gpu ✅ success view
inference_unit_test_1gpu ✅ success view
inference_test_1gpu ✅ success view

Result: 11/16 jobs passed

View full pipeline

Move dx_accumulate handling into the Triton backward kernel and add focused numerical unit tests.
@shijieliu
shijieliu merged commit 584e20f into NVIDIA:main Sep 1, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]Non-learnable LayerNorm backward drops residual gradient

3 participants