You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit fdf2c2e
Browse filesBrowse the repository at this point in the historyBrowse files
authored
Qwen3-ASR: feature_attention_mask + chunked conv for HF parity (#264)
Fixes two bugs in the audio encoder export that caused Qwen3-ASR ONNX
outputs to drift on long audio:
1. feature_attention_mask was missing from the audio encoder graph, so
padded mel frames produced finite values that fed the LLM and triggered
runaway repetition
- AudioEncoderLayer / AudioAttention now plumb attention_mask through to
op.Attention as the 4th positional arg.
- _build_audio_encoder declares feature_attention_mask (INT64) as graph
input and audio_feature_lengths as output.
- examples/qwen3_asr.py uses processor with return_attention_mask and
crops audio_features by audio_feature_lengths.
2. The audio encoder used a single-shot conv over the full mel
spectrogram (375 tokens / 30s) instead of HF's chunked conv with
per-chunk positional embeddings and block-diagonal attention mask (390
tokens / 30s, 100-frame chunks, 13 tokens/chunk, 8-chunk blocks). This
caused the 1.7B model to drift on 30s clips
- AudioConfig gains n_window / n_window_infer fields, derived from the
HF config in _extract_audio_config.
- Qwen3ASRAudioEncoder now reshapes mel into chunks, runs Conv2d batched
across (B*num_chunks), broadcasts PE[0:tokens_per_chunk] over chunks,
computes per-batch audio_feature_lengths via HF's
_get_feat_extract_output_lengths formula, and builds an (B, S, S)
block-diagonal attention mask. Empty rows for padded queries are OR'd
with the identity matrix to avoid NaN in ORT softmax; padded outputs are
cropped by callers.
Validated against HF reference on a 30s Chinese clip: mobius's 1.7B ONNX
output now matches HF's reference output near byte-for-byte.
All 1201 build_graph tests pass.
Tests added:
- test_audio_encoder_attention_uses_mask: every Attention op has 4
inputs with non-null attn_mask.
- test_3model_pipeline_runs_with_ort updated to feed mask + crop by
audio_feature_lengths.
---------
Signed-off-by: Justin Chu <[email protected]>
Signed-off-by: Justin Chu <[email protected]>
Co-authored-by: copilot-swe-agent[bot] <[email protected]>
Co-authored-by: Justin Chu <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Justin Chu <[email protected]>
0 commit comments