Skip to content

Fix GatedDeltaNet hooked forward on transformers >= 5.15 - #1803

Merged
jlarson4 merged 2 commits into
TransformerLensOrg:devfrom
YHC66:fix-gated-delta-net-transformers-5-15
Sep 23, 2026
Merged

jlarson4 merged 2 commits into
TransformerLensOrg:devfrom
YHC66:fix-gated-delta-net-transformers-5-15

Conversation

@YHC66

@YHC66 YHC66 commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

Description

GatedDeltaNetBridge._hooked_forward reads hf.causal_conv1d_fn and hf.chunk_gated_delta_rule from the wrapped HF module. transformers 5.15 stopped setting those as instance attributes on Qwen3NextGatedDeltaNet / Qwen3_5GatedDeltaNet / Qwen3_5MoeGatedDeltaNet; they are now module-level functions (causal_conv1d_fn, torch_chunk_gated_delta_rule) wrapped by @use_kernelized_func. (5.14.0 still sets them; 5.15.0 is the first release without them.)

pyproject.toml allows transformers>=5.9.0 and CI is locked to 5.13.0, so this doesn't show up in CI, but with the current PyPI release (5.17.0) any non-generation forward through a Qwen3.5 / Qwen3Next / Qwen3.5-MoE bridge fails:

AttributeError: 'Qwen3_5GatedDeltaNet' object has no attribute 'causal_conv1d_fn'

Running the existing unit tests against transformers 5.17.0 reproduces it (10 failures + 7 errors under tests/unit/model_bridge in test_qwen3_5_adapter.py, test_qwen3_5_moe_adapter.py and test_ssm_hooked_forward_parity.py::test_gated_delta_net_hooked_forward_is_bit_exact).

Fix: look both attributes up with getattr. When causal_conv1d_fn is absent the existing torch conv path is used (it matches HF's torch implementation bit-for-bit). When chunk_gated_delta_rule is absent, the module-level torch_chunk_gated_delta_rule from the HF module's own modeling file is used. Behavior on older transformers versions is unchanged.

The new test in test_ssm_hooked_forward_parity.py removes the two instance attributes from the HF module before wiring it into the bridge and checks bit-exact parity against HF's native forward, so the 5.15+ code path is covered on the transformers version CI is locked to.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have commented my code, particularly in hard-to-understand areas
  • I have made corresponding changes to the documentation
  • My changes generate no new warnings
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes
  • I have not rewritten tests relating to key interfaces which would affect backward compatibility

Tested locally (macOS arm64, Python 3.12):

  • transformers 5.13.0 (lockfile version): full tests/unit passes (6559 passed, 54 skipped, 6 xfailed); the new test fails without the fix.
  • transformers 5.17.0: all Qwen3.5 / Qwen3Next / GatedDeltaNet unit tests pass (119 passed, previously 10 failed + 7 errors).

transformers 5.15 stopped setting causal_conv1d_fn and chunk_gated_delta_rule
on the GatedDeltaNet instance (they are now module-level functions wrapped by
use_kernelized_func), so the bridge's hooked forward raised AttributeError for
Qwen3Next / Qwen3.5 / Qwen3.5-MoE linear-attention layers.

Look the attributes up with getattr and fall back to the torch conv path and
the module-level torch_chunk_gated_delta_rule when they are absent.

@jlarson4 jlarson4 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.

Great catch on this @YHC66! I was able to reproduce this on transformers v5.17. Two comments on the convolution half of the fix.

@jlarson4

Copy link
Copy Markdown
Collaborator

Looks great, thanks for the quick resolution @YHC66

@jlarson4
jlarson4 merged commit 98b74dc into TransformerLensOrg:dev Sep 23, 2026
26 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.

2 participants