Skip to content

Commit 2d1fed0

Browse files
Copilotjustinchuby
andauthored
Fix integration test: use cache API to pre-fill states instead of direct 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]>
1 parent f5de896 commit 2d1fed0

1 file changed

Lines changed: 8 additions & 8 deletions

File tree

‎tests/integration_test.py‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3929,15 +3929,15 @@ def test_qwen35_deltanet_single_layer_parity():
39293929

39303930
# HF forward (single-token decode with pre-filled cache)
39313931
cache = DynamicCache(config=tc)
3932+
# Use the cache API to pre-fill states so that dtype/device/initialized flags
3933+
# are all set correctly. Direct attribute assignment bypasses lazy_initialization
3934+
# and leaves 'dtype' unset, causing AttributeError on the first update call.
39323935
# HF conv_state shape is (batch, conv_dim, conv_kernel_size) —
3933-
# pad with one extra left position vs ONNX (kernel_size - 1)
3934-
cache.layers[0].conv_states = torch.from_numpy(
3935-
np.pad(conv_np, ((0, 0), (0, 0), (1, 0))),
3936-
).float()
3937-
cache.layers[0].recurrent_states = torch.from_numpy(rec_np).float()
3938-
# Signal that previous state exists so the forward uses decode-mode path.
3939-
# In newer transformers the flag is not set automatically by direct assignment.
3940-
cache.layers[0].has_previous_state = True
3936+
# pad with one extra left position vs ONNX (kernel_size - 1).
3937+
# update_conv_state also sets has_previous_state = True (decode-mode trigger).
3938+
padded_conv = torch.from_numpy(np.pad(conv_np, ((0, 0), (0, 0), (1, 0)))).float()
3939+
cache.update_conv_state(padded_conv, layer_idx=0)
3940+
cache.update_recurrent_state(torch.from_numpy(rec_np).float(), layer_idx=0)
39413941

39423942
with torch.no_grad():
39433943
hf_output = hf_dn(

0 commit comments

Comments
 (0)