Skip to content

Commit 18c4c8b

Browse files
justinchubyCopilot
andcommitted
Fix L4/L5 golden regressions across 7 broken models
An L4/L5 golden-test regression sweep found seven models failing at build or run time. Root-cause and fix each: - diffllama: create_padding_mask now returns a 4D bool [B,1,S,Sk] mask, but DiffLlamaAttention still unsqueezed it again, producing a rank-5 bias that broke ORT Split. Add the (already-4D) pad bias directly. - gemma-4 audio encoder (e2b + e4b): (1) op.Range got a 1-D [1] limit from op.Shape; squeeze to a scalar at both Range sites. (2) the mask-downsample Slice used INT64_MAX as ends; shape inference did not clamp it to the symbolic time dim and derived a 2^62 length that overflowed the downstream Reshape at load. Bound the Slice ends to the dynamic time length. - gemma-4 assistant drafter: the generic Attention path built the sliding- window bias from the full buffer-width attention_mask (kv_len + 1) while K is only the shared KV (kv_len), so ORT rejected an inconsistent total_sequence_length. Slice the mask to kv_len first. - qwen3-asr / qwen3-asr-en: thinker_config ships as a plain dict, so the text_config-unwrap branch in build() missed it and the decoder config kept hidden_size=0. Convert the dict via _dict_to_pretrained_config before unwrapping text_config. - nemotron-h: build() without trust_remote_code mis-detected layer_types as linear_attention (TypeError). Add trust_remote_code and a clear None-guard in linear_attention_dims. The build now succeeds with correct mamba2 layer types, but the HF reference needs trust_remote_code custom modeling plus mamba-ssm CUDA kernels that are unavailable in CI golden generation (same as jamba-v0_1 / granitemoehybrid-tiny), and the previously committed golden was generated without trust_remote_code (wrong native config). Documented skip_reason added until a valid golden can be produced. - sensevoice-small: audio-ctc L4/L5 is not wired into the e2e harness (custom LFR-fbank input_features + language_id, FunASR reference, no audio-ctc golden generator). Documented skip_reason added. Verified on GPU (CUDA EP): diffllama, qwen3-asr, qwen3-asr-en, gemma-4-e2b-it-audio, gemma-4-e4b-it-audio, gemma-4-e2b-it-assistant all pass L4 and L5; nemotron-h and sensevoice-small skip. Regression-checked gemma-4-e2b, llama-3_2-1b, qwen3-0_6b (unchanged, still pass). Co-authored-by: Copilot <[email protected]> Signed-off-by: justinchuby <[email protected]>
1 parent 9b22d8d commit 18c4c8b

7 files changed

Lines changed: 66 additions & 10 deletions

File tree

‎src/mobius/_builder.py‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ def build(
447447
from mobius._config_resolver import (
448448
_config_from_hf,
449449
_default_task_for_model,
450+
_dict_to_pretrained_config,
450451
_try_load_config_json,
451452
)
452453
from mobius._diffusers_builder import build_diffusers_pipeline
@@ -481,7 +482,13 @@ def build(
481482
hf_config = hf_config.talker_config
482483
elif hasattr(hf_config, "thinker_config"):
483484
thinker = hf_config.thinker_config
484-
if hasattr(thinker, "text_config"):
485+
# Some checkpoints (e.g. Qwen3-ASR) ship ``thinker_config`` as a plain
486+
# dict rather than a nested ``PretrainedConfig``. Convert it so the
487+
# decoder ``text_config`` (and its scalar fields such as hidden_size)
488+
# is reachable via attribute access.
489+
if isinstance(thinker, dict):
490+
thinker = _dict_to_pretrained_config(thinker)
491+
if getattr(thinker, "text_config", None) is not None:
485492
hf_config = thinker.text_config
486493
elif hasattr(hf_config, "decoder_config") and model_type == "qwen3_tts_tokenizer_12hz":
487494
# Codec tokenizer: use decoder_config as the primary config source

‎src/mobius/components/_gemma4_assistant.py‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,10 +205,20 @@ def forward(
205205
if self.sliding_window and attention_mask is not None:
206206
from mobius._build_context import get_build_dtype
207207

208+
# The shared KV holds ``kv_len`` real positions, but ``attention_mask``
209+
# is the target's full buffer-width mask (kv_len + 1 for the slot of
210+
# the token being predicted — GQA consumes that extra slot via
211+
# ``total_seq_len`` while the generic path passes only the shared KV
212+
# as K). Slice the mask to ``kv_len`` so the additive bias width
213+
# matches the Attention op's total_sequence_length (= K's seq dim);
214+
# otherwise ORT rejects the model with an inconsistent
215+
# total_sequence_length error.
216+
kv_len = op.Shape(shared_key, start=2, end=3) # [1] = shared KV seq len
217+
mask_kv = op.Slice(attention_mask, [0], kv_len, [1], [1]) # [B, kv_len]
208218
attn_bias = create_attention_bias(
209219
op,
210220
input_ids=q,
211-
attention_mask=attention_mask,
221+
attention_mask=mask_kv,
212222
sliding_window=self.sliding_window,
213223
dtype=get_build_dtype(),
214224
)

‎src/mobius/components/_gemma4_audio.py‎

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
import onnx_ir as ir
4747
from onnxscript import OpBuilder, nn
4848

49-
from mobius.components._common import INT64_MAX, LayerNormNoBias, Linear
49+
from mobius.components._common import LayerNormNoBias, Linear
5050
from mobius.components._conv import CausalDepthwiseConv1d, Conv2dNoBias
5151
from mobius.components._rms_norm import RMSNorm
5252

@@ -211,11 +211,16 @@ def _mask_and_downsample(
211211
# Broadcast mask [B, T] → [B, 1, T, 1] over C and F dims
212212
mask_4d = op.Unsqueeze(mask, [1, 3]) # [B, 1, T, 1]
213213
x = op.Mul(x, op.CastLike(mask_4d, x))
214-
# Downsample mask by conv stride (2): mask[:, ::2]
214+
# Downsample mask by conv stride (2): mask[:, ::2]. Bound the slice
215+
# ``ends`` to the dynamic time length rather than ``INT64_MAX``: shape
216+
# inference does not clamp a concrete ``INT64_MAX`` end to the (symbolic)
217+
# input dim, so it derives an output length of ``INT64_MAX // 2`` (2^62),
218+
# which then overflows the downstream flatten Reshape at model load.
219+
mask_len = op.Shape(mask, start=1, end=2) # [1] — the time dim size
215220
mask = op.Slice(
216221
mask,
217222
[0], # starts
218-
[INT64_MAX], # ends
223+
mask_len, # ends (clamped to the real length)
219224
[1], # axes
220225
[2], # steps
221226
) # [B, T//2]
@@ -477,7 +482,10 @@ def _build_causal_window_mask(self, op: OpBuilder, seq_len: ir.Value) -> ir.Valu
477482
"""Build [1, 1, T, T] causal sliding-window attention bias."""
478483
zero = op.Constant(value_int=0)
479484
one = op.Constant(value_int=1)
480-
positions = op.Range(zero, seq_len, one) # [T] int64
485+
# ``seq_len`` is a 1-D [1] tensor from op.Shape; Range requires a
486+
# scalar limit, so squeeze the singleton axis.
487+
seq_len_scalar = op.Squeeze(seq_len, [0])
488+
positions = op.Range(zero, seq_len_scalar, one) # [T] int64
481489
q_pos = op.Unsqueeze(positions, [1]) # [T, 1]
482490
k_pos = op.Unsqueeze(positions, [0]) # [1, T]
483491
diff = op.Sub(q_pos, k_pos) # [T, T]: i - j
@@ -570,7 +578,9 @@ def forward(
570578
# pos_embed is ordered [ctx_left-1, ..., 0], so distance d maps to index ctx_left-1-d
571579
zero_i = op.Constant(value_int=0)
572580
one_i = op.Constant(value_int=1)
573-
positions = op.Range(zero_i, seq_len, one_i) # [T]
581+
# Range requires a scalar limit; ``seq_len`` is a 1-D [1] shape tensor.
582+
seq_len_scalar = op.Squeeze(seq_len, [0])
583+
positions = op.Range(zero_i, seq_len_scalar, one_i) # [T]
574584
q_pos_i = op.Unsqueeze(positions, [1]) # [T, 1]
575585
k_pos_i = op.Unsqueeze(positions, [0]) # [1, T]
576586
diff_i = op.Sub(q_pos_i, k_pos_i) # [T, T]: i-j

‎src/mobius/models/diffllama.py‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,15 @@ def forward(
194194
# Unsqueeze to [1, 1, S, Sk] and add to scores [B, H, S, Sk]
195195
attn_scores = op.Add(attn_scores, op.Unsqueeze(causal_bias, [0, 1]))
196196

197-
# Padding mask (3D bool [B, S, Sk]) → additive bias [B, 1, S, Sk]
197+
# Padding mask: ``create_padding_mask`` yields a 4D bool tensor
198+
# [B, 1, S, Sk] (the explicit singleton head dim prevents the batch
199+
# axis being misread as q_num_heads for batch > 1). Convert to an
200+
# additive bias and add directly — it broadcasts across the head axis.
198201
if attention_bias is not None:
199202
pad_zero = op.CastLike(0.0, q_4d)
200203
pad_neg_inf = op.CastLike(float("-inf"), q_4d)
201-
pad_bias = op.Where(attention_bias, pad_zero, pad_neg_inf)
202-
attn_scores = op.Add(attn_scores, op.Unsqueeze(pad_bias, [1]))
204+
pad_bias = op.Where(attention_bias, pad_zero, pad_neg_inf) # [B, 1, S, Sk]
205+
attn_scores = op.Add(attn_scores, pad_bias)
203206

204207
# Softmax and weighted sum with doubled V
205208
attn_weights = op.Softmax(attn_scores, axis=-1) # [B, H, S, Sk]

‎src/mobius/tasks/_cache_utils.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,24 @@ def linear_attention_dims(config: BaseModelConfig) -> LinearAttentionDims:
4949
head_k_dim = config.linear_key_head_dim
5050
head_v_dim = config.linear_value_head_dim
5151
conv_kernel = config.linear_conv_kernel_dim
52+
missing = [
53+
name
54+
for name, value in (
55+
("linear_num_key_heads", num_k_heads),
56+
("linear_num_value_heads", num_v_heads),
57+
("linear_key_head_dim", head_k_dim),
58+
("linear_value_head_dim", head_v_dim),
59+
("linear_conv_kernel_dim", conv_kernel),
60+
)
61+
if value is None
62+
]
63+
if missing:
64+
raise ValueError(
65+
"Linear-attention cache inputs requested but the following config "
66+
f"fields are unset: {', '.join(missing)}. This usually means the "
67+
"architecture's layer_types were mis-detected as 'linear_attention' "
68+
"(e.g. a hybrid model built without trust_remote_code)."
69+
)
5270
key_dim = head_k_dim * num_k_heads
5371
value_dim = head_v_dim * num_v_heads
5472
conv_dim = key_dim * 2 + value_dim

‎testdata/cases/causal-lm/nemotron-h-nano-4b.yaml‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ model_type: "nemotron_h"
33
revision: "main"
44
task_type: "text-generation"
55
dtype: "float32"
6+
trust_remote_code: true
7+
skip_reason: "Requires trust_remote_code custom modeling + mamba-ssm CUDA kernels for the HF reference, which are unavailable in CI golden generation (same limitation as jamba-v0_1 and granitemoehybrid-tiny). The mobius build now succeeds (correct mamba2 layer_types via trust_remote_code), but a valid golden cannot be regenerated here; the previously committed golden was produced without trust_remote_code and reflects the wrong native `linear_attention` config."
68

79
inputs:
810
prompts:

‎testdata/cases/speech/sensevoice-small.yaml‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ inputs:
1010

1111
level: "L4+L5"
1212

13+
skip_reason: >
14+
audio-ctc L4/L5 is not wired into the e2e harness: the encoder needs
15+
custom LFR-fbank ``input_features`` (560-dim) plus a ``language_id``,
16+
and the reference is FunASR (no transformers class), so
17+
generate_golden.py has no audio-ctc generator. Tracked as a follow-up.
18+
1319
notes: >
1420
SenseVoiceSmall CTC encoder-only ASR. Single model: SANM encoder + CTC head.
1521
Audio input is LFR fbank features (batch, seq_len, 560) with language ID.

0 commit comments

Comments
 (0)