Skip to content

fix: guard save_for_backward on grad_bias not bias in fused linear CE forward - #1157

Merged
Tcc0403 merged 2 commits into
linkedin:mainfrom
aryanputta:patch-1
Mar 23, 2026
Merged

Tcc0403 merged 2 commits into
linkedin:mainfrom
aryanputta:patch-1

Conversation

@aryanputta

Copy link
Copy Markdown

Summary

Fixes a bug in LigerFusedLinearCrossEntropyFunction.forward where ctx.save_for_backward checks bias is not None instead of grad_bias is not None before calling .detach().

When input_requires_grad=False, fused_linear_cross_entropy_forward sets grad_bias = None regardless of whether bias is provided. The stale check then calls None.detach() and raises AttributeError.

Fixes #1156

Details

One-line fix in src/liger_kernel/ops/fused_linear_cross_entropy.py:

Before: grad_bias.detach() if bias is not None else None,
After: grad_bias.detach() if grad_bias is not None else None,

Testing Done

  • Hardware Type: CPU (logic-only fix, no GPU kernel change)
  • run make test to ensure correctness
  • run make checkstyle to ensure code style
  • run make test-convergence to ensure convergence

… forward

When input_requires_grad is False, fused_linear_cross_entropy_forward sets grad_bias to None regardless of whether bias is provided. The save_for_backward call was checking `bias is not None` instead of `grad_bias is not None`, causing an AttributeError when bias is provided but grad_bias is None.

Fixes linkedin#1156

@Tcc0403 Tcc0403 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thank you!

@Tcc0403
Tcc0403 added this pull request to the merge queue Mar 23, 2026
Merged via the queue into linkedin:main with commit d8d6630 Mar 23, 2026
5 of 7 checks 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.

LigerFusedLinearCrossEntropyFunction uses wrong None check

2 participants