Skip to content

[BUG]Non-learnable LayerNorm backward drops residual gradient #446

Closed

Description

@rocketbastard

Describe the bug

The non-learnable LayerNorm backward path in examples/hstu/ops/triton_ops/triton_layer_norm.py does not accumulate the residual gradient passed through dx_accumulate.

The learnable branch handles this gradient, but the non-learnable branch calls _layer_norm_bwd_dx() and returns immediately.

Steps/Code to reproduce bug

Use the non-learnable LayerNorm backward path with:

input_norm_weight = None
dx_accumulate = residual_grad

The relevant code path is:

_layer_norm_bwd_dx[(N,)](...)
return dx, None, None

dx_accumulate is not used before returning.

The returned gradient can be compared against:

expected_dx = layer_norm_dx + dx_accumulate

Expected behavior

When dx_accumulate is provided, the returned input gradient should be:

dx = layer_norm_dx + dx_accumulate

This should be consistent with the learnable LayerNorm backward path.

Environment details (please complete the following information):

  • Environment location: Not applicable; identified through source-code review
  • Method of recsys-examples install: From source
  • print_env.sh output: Not available because I do not have access to a CUDA-capable NVIDIA GPU environment

Additional context

The issue is in the non-learnable branch of triton_weighted_layer_norm_bwd().

A minimal fix would be:

if dx_accumulate is not None:
    dx.add_(dx_accumulate)

before returning dx.

Activity

  1. added
    bug
    on Aug 4, 2026
  2. rocketbastard commented on Aug 4, 2026

    @rocketbastard
    ContributorAuthor

    I am working on a fix and will submit a pull request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions