Skip to content

Fix integration test: remove dropped cache_position kwarg from Qwen3_5GatedDeltaNet.forward() - #229

Merged
justinchuby merged 3 commits into
mainfrom
copilot/fix-integration-test
May 1, 2026
Merged

justinchuby merged 3 commits into
mainfrom
copilot/fix-integration-test

Conversation

Copilot AI commented May 1, 2026 •

Copy link
Copy Markdown
Contributor

test_qwen35_deltanet_single_layer_parity fails on transformers 5.x because Qwen3_5GatedDeltaNet.forward() no longer accepts cache_position, and has_previous_state is no longer implicitly set when assigning cache states directly.

Changes

  • Remove cache_position kwarg — dropped from the HF forward signature in transformers 5.x; decode vs. prefill mode is now determined solely via cache_params.has_previous_state(layer_idx).
  • Explicitly set cache.layers[0].has_previous_state = True — in the old API this flag was implicitly set when conv_states was assigned directly on the layer; in 5.x it is a plain bool defaulting to False and only set via update_conv_state(). The test bypasses that method, so the flag must be set manually to put the forward into decode mode and consume the pre-filled states.
# Before
cache.layers[0].recurrent_states = torch.from_numpy(rec_np).float()
# has_previous_state is True once conv_states[0] is set  ← no longer true

hf_output = hf_dn(
    hidden_states=...,
    cache_params=cache,
    cache_position=torch.tensor([conv_kernel - 1]),  # ← TypeError in 5.x
).numpy()

# After
cache.layers[0].recurrent_states = torch.from_numpy(rec_np).float()
cache.layers[0].has_previous_state = True  # explicit in 5.x

hf_output = hf_dn(
    hidden_states=...,
    cache_params=cache,
).numpy()

Copilot AI linked an issue May 1, 2026 that may be closed by this pull request
… has_previous_state flag

The Qwen3_5GatedDeltaNet.forward() in newer transformers (5.x) no longer
accepts cache_position. The decode-mode flag has_previous_state must also
now be set explicitly when directly assigning cache layer states.

Fixes: test_qwen35_deltanet_single_layer_parity TypeError

Agent-Logs-Url: https://github.com/onnxruntime/mobius/sessions/7a0ec434-f0af-41ab-a0d3-b41282eaef17

Co-authored-by: justinchuby <[email protected]>
Copilot AI changed the title [WIP] Fix integration test for Qwen3_5GatedDeltaNet Fix integration test: remove dropped cache_position kwarg from Qwen3_5GatedDeltaNet.forward() May 1, 2026
Copilot AI requested a review from justinchuby May 1, 2026 14:25
@github-actions

github-actions Bot commented May 1, 2026 •

Copy link
Copy Markdown

Performance Comparison

Comparing e73e0a5 → 2d1fed0

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0% ⚪
bert (feature-extraction) num_nodes 60 60 +0.0% ⚪
falcon model_size_bytes 364 KB 364 KB +0.0% ⚪
falcon num_nodes 66 66 +0.0% ⚪
gemma2 model_size_bytes 428 KB 428 KB +0.0% ⚪
gemma2 num_nodes 107 107 +0.0% ⚪
gpt2 model_size_bytes 388 KB 388 KB +0.0% ⚪
gpt2 num_nodes 53 53 +0.0% ⚪
llama model_size_bytes 425 KB 425 KB +0.0% ⚪
llama num_nodes 61 61 +0.0% ⚪
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
llama (static-cache) num_nodes 58 58 +0.0% ⚪
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0% ⚪
mamba (ssm-text-generation) num_nodes 98 98 +0.0% ⚪
phi3 model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 num_nodes 59 59 +0.0% ⚪
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0% ⚪
phi3 (static-cache) num_nodes 56 56 +0.0% ⚪
qwen2 model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 num_nodes 61 61 +0.0% ⚪
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0% ⚪
qwen2 (static-cache) num_nodes 58 58 +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0% ⚪
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0% ⚪
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0% ⚪
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0% ⚪
qwen3_5_vl (hybrid-qwen-vl) num_nodes 408 408 +0.0% ⚪
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0% ⚪
t5 (seq2seq) num_nodes 166 166 +0.0% ⚪
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0% ⚪
whisper (speech-to-text) num_nodes 128 128 +0.0% ⚪

No performance regressions.

@codecov

codecov Bot commented May 1, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@justinchuby
justinchuby marked this pull request as ready for review May 1, 2026 16:45
@justinchuby
justinchuby requested review from a team and Copilot May 1, 2026 16:45
@justinchuby

Copy link
Copy Markdown
Member

@copilot FAILED tests/integration_test.py::test_qwen35_deltanet_single_layer_parity - AttributeError: 'LinearAttentionLayer' object has no attribute 'dtype'

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a failing integration parity test against HuggingFace transformers 5.x by aligning the test’s HF Qwen3_5GatedDeltaNet.forward() invocation and cache semantics with the updated upstream API.

Changes:

  • Remove the dropped cache_position keyword argument from the HF forward call.
  • Explicitly set cache.layers[0].has_previous_state = True so HF takes the decode-mode path when the test pre-fills cache tensors via direct assignment.

…ect assignment

Direct assignment of cache.layers[0].conv_states bypassed lazy_initialization,
leaving 'dtype' unset on LinearAttentionLayer. When the forward called
update_recurrent_state, it triggered lazy_initialization which accessed
self.dtype -> AttributeError.

Use cache.update_conv_state/update_recurrent_state API instead, which
properly initializes dtype/device/initialized flags and sets
has_previous_state=True automatically.

Agent-Logs-Url: https://github.com/onnxruntime/mobius/sessions/b064a982-b980-41f9-b630-622c7a7b65c0

Co-authored-by: justinchuby <[email protected]>

Copilot AI commented May 1, 2026

Copy link
Copy Markdown
Contributor Author

@copilot FAILED tests/integration_test.py::test_qwen35_deltanet_single_layer_parity - AttributeError: 'LinearAttentionLayer' object has no attribute 'dtype'

Fixed in 2d1fed0. The AttributeError was caused by direct assignment (cache.layers[0].conv_states = ...) bypassing lazy_initialization(), which is the only place dtype and device are set on LinearAttentionLayer. When the forward then called cache_params.update_recurrent_state(...), it tried lazy_initialization(recurrent_states=...) which accessed self.dtype — but that attribute was never set.

Replaced the direct assignments with cache.update_conv_state(padded_conv, layer_idx=0) and cache.update_recurrent_state(rec_tensor, layer_idx=0), which properly initialize all internal attributes and also set has_previous_state = True automatically.

@justinchuby
justinchuby merged commit 4de6bb7 into main May 1, 2026
22 checks passed
@justinchuby
justinchuby deleted the copilot/fix-integration-test branch May 1, 2026 17:35
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.

Fix integration test

3 participants