Commit fe6d687
Fix gemma4 audio-encoder audio_features export rank (#570)
The gemma4 audio dataflow edge
`audio_encoder.audio_features -> embedding.audio_features` was rank-3 on the
producer side but rank-2 on the consumer side, so onnx-genai pipeline admission
rejected every gemma4 audio (E2B/E4B) package:
'audio_encoder.audio_features -> embedding.audio_features' has incompatible
ranks: producer rank 3, consumer rank 2.
HF selects `audio_features[audio_mask]` (a boolean-mask gather) that both drops
padding frames and flattens the batch axis to rank-2
`[num_valid_frames, text_hidden_size]` before scattering rows into the
language-model embeddings.
Move that mask-selection into `_Gemma4AudioEncoderModel.forward`: after the
projector, flatten `[B, T//4, H] -> [-1, H]` and reuse the shared bf16-safe
`_dtype_safe_compress` helper to emit rank-2 `[num_valid_frames, H]`, matching
the `embedding` consumer and the encoder-free `_Gemma4UnifiedAudioEmbedderModel`.
The task builder `_build_audio` no longer duplicates the flatten+Compress. This
covers all gemma4 Conformer-audio variants since they share the module.
Add `TestGemma4AudioEncoderRank` locking the rank-2 contract: producer rank ==
consumer rank == 2 (trailing dim == hidden_size) and a Compress node is present
so the reduction is a real mask-select, not a bare reshape.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent 8a565d7 commit fe6d687
3 files changed
Lines changed: 111 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2639 | 2639 | | |
2640 | 2640 | | |
2641 | 2641 | | |
| 2642 | + | |
2642 | 2643 | | |
2643 | 2644 | | |
2644 | | - | |
| 2645 | + | |
| 2646 | + | |
| 2647 | + | |
| 2648 | + | |
| 2649 | + | |
| 2650 | + | |
| 2651 | + | |
| 2652 | + | |
| 2653 | + | |
| 2654 | + | |
2645 | 2655 | | |
2646 | 2656 | | |
2647 | 2657 | | |
| |||
2701 | 2711 | | |
2702 | 2712 | | |
2703 | 2713 | | |
2704 | | - | |
| 2714 | + | |
| 2715 | + | |
| 2716 | + | |
| 2717 | + | |
| 2718 | + | |
| 2719 | + | |
| 2720 | + | |
| 2721 | + | |
| 2722 | + | |
| 2723 | + | |
| 2724 | + | |
| 2725 | + | |
| 2726 | + | |
| 2727 | + | |
| 2728 | + | |
| 2729 | + | |
| 2730 | + | |
2705 | 2731 | | |
2706 | 2732 | | |
2707 | 2733 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
284 | 284 | | |
285 | 285 | | |
286 | 286 | | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
287 | 367 | | |
288 | 368 | | |
289 | 369 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
666 | 666 | | |
667 | 667 | | |
668 | 668 | | |
669 | | - | |
670 | | - | |
671 | | - | |
672 | | - | |
673 | | - | |
674 | | - | |
675 | | - | |
676 | | - | |
677 | | - | |
678 | | - | |
679 | | - | |
680 | | - | |
681 | | - | |
| 669 | + | |
| 670 | + | |
| 671 | + | |
682 | 672 | | |
683 | 673 | | |
684 | 674 | | |
| |||
0 commit comments