Repository navigation
Commit 612abc3
Update gemma4 genai audio config logic (#223)
## Gemma4 Audio Encoder Support for ORT-GenAI Export
### Summary
Adds audio encoder export support for Gemma4 multimodal models in the
ORT-GenAI integration pipeline. This enables Gemma4 any-to-any
(vision+audio+text) models to be exported with the correct audio
processor configuration and genai_config.json speech section.
### Changes
#### `auto_export.py`
- **`_write_audio_processor_config()`** — New function that writes
`audio_feature_extraction.json` for Gemma4 models using the
`feature_extraction.sequence` schema required by
`OrtxCreateSpeechFeatureExtractor`. The pipeline consists of
`AudioDecoder` → `Gemma4LogMel` with USM-style 128-dim log-mel
spectrogram parameters.
- **`_write_genai_config()`** — Gemma4 speech section overrides:
- `filename`: `audio_encoder/model.onnx`
- `config_filename`: `audio_feature_extraction.json` (instead of default
`audio_processor.json`)
- `input_names` mapping: `audio_embeds` → `input_features`,
`attention_mask` → `input_features_mask`
- **`_write_vision_processor_config()`** — Renamed from
`_write_processor_config` for clarity. Gemma4 vision path now writes
`image_processor.json` with `DecodeImage` → `Gemma4ImageTransform`
transforms pipeline, checked before `has_speech` to ensure vision config
is always written for VLM+audio models.
- **`write_ort_genai_config()`** — Calls
`_write_audio_processor_config()` and includes result in the output dict
under `"audio_processor"`.
#### `auto_export_test.py`
Added 6 new tests covering audio export:
| Test | What it verifies |
|------|-----------------|
| `test_audio_no_audio_returns_none` | `_write_audio_processor_config`
returns `None` when config has no `audio` attribute |
| `test_audio_non_gemma4_returns_none` | Returns `None` for non-Gemma4
model types |
| `test_audio_gemma4_writes_feature_extraction_json` | Writes
`audio_feature_extraction.json` with correct
`feature_extraction.sequence` schema, `AudioDecoder` + `Gemma4LogMel`
ops, and expected attrs |
| `test_gemma4_audio_processor_json_written` | End-to-end:
`write_ort_genai_config` produces `audio_feature_extraction.json` |
| `test_gemma4_audio_processor_not_written_without_audio` | No audio
config written when config lacks `audio` |
| `test_gemma4_genai_config_speech_section` | `genai_config.json` speech
section has correct `config_filename`, `filename`, and input mapping
(`input_features` / `input_features_mask`) |
### Notes
- The `feature_extraction.sequence` format (not `processor.transforms`)
is required by the onnxruntime-extensions
`OrtxCreateSpeechFeatureExtractor` API.
- The `_write_vision_processor_config` rename updates the existing test
reference (`test_gemma4_image_processor_json_written`).
---------
Co-authored-by: Justin Chu <[email protected]>1 parent db0ae40 commit 612abc3
1 file changed
Lines changed: 46 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
254 | 254 | | |
255 | 255 | | |
256 | 256 | | |
257 | | - | |
258 | | - | |
259 | | - | |
260 | | - | |
261 | | - | |
262 | | - | |
263 | | - | |
264 | | - | |
265 | | - | |
266 | | - | |
267 | | - | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
268 | 286 | | |
269 | 287 | | |
| 288 | + | |
270 | 289 | | |
271 | 290 | | |
272 | 291 | | |
273 | 292 | | |
274 | | - | |
| 293 | + | |
275 | 294 | | |
276 | 295 | | |
277 | 296 | | |
| |||
334 | 353 | | |
335 | 354 | | |
336 | 355 | | |
337 | | - | |
338 | | - | |
339 | | - | |
340 | | - | |
| 356 | + | |
341 | 357 | | |
342 | 358 | | |
343 | 359 | | |
344 | 360 | | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
345 | 364 | | |
346 | 365 | | |
347 | 366 | | |
| |||
362 | 381 | | |
363 | 382 | | |
364 | 383 | | |
365 | | - | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
366 | 395 | | |
367 | 396 | | |
368 | 397 | | |
| |||
0 commit comments