Repository navigation
tasks: declare vision/audio encoder inputs at config.dtype - #319
Conversation
…2 cast pattern Revert PR #275 (and the matching original change for _gemma4.py and _vision_language_3model.py). Per discussion with the ORT GenAI team, the runtime does not require encoder inputs to be float32 — it can deliver vision / audio inputs at the same dtype the model was built with (f16 / bf16). Declaring the graph input at config.dtype matches the model's internal compute and removes the extra Cast node at graph entry. Changes: * tasks: replace the f32+Cast pattern with dtype=config.dtype across _vision_language.py, _vision_language_3model.py, _multimodal.py, _audio_ctc.py, _speech_language.py, _hunyuan_vl_mot.py, _phi4mm_multimodal.py, _fun_asr_speech_language.py, _gemma4.py. * tasks/_base.py: drop the now-unused _cast_encoder_input helper. * tests/build_graph_test.py: rewrite test_multimodal_encoder_inputs_* and test_gemma4_encoder_inputs_* to assert encoder graph inputs match config.dtype and that there is no Cast at graph entry. Single-model encoder-only tasks (_image_classification.py, _audio_feature_extraction.py) still declare FLOAT because they have no separate compute dtype — the whole model is f32 and the input goes straight to the encoder. L1 + unit suite: 2763 passed, 43 skipped (no regressions). Signed-off-by: justinchuby <[email protected]>
Performance Comparison
|
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
🏗️ Architecture Diff
No architecture changes detected. ✅ Legend: ⚪ No change · 🔵 Minor (attrs/inits) · 🟡 Moderate (nodes added/removed) · 🔴 Major (interface changed) |
There was a problem hiding this comment.
Pull request overview
Reverts the prior pattern of declaring vision/audio encoder graph inputs as FLOAT with a Cast at graph entry. Per the ORT GenAI team, the runtime can deliver vision/audio inputs at the model's compute dtype directly, so declaring inputs at config.dtype removes an extra Cast op per inference and aligns encoder inputs with the convention already used for decoder/embedding/KV cache inputs.
Changes:
- Replace
dtype=ir.DataType.FLOAT+_cast_encoder_input(...)withdtype=config.dtypeacross all multi-model vision/audio task builders. - Drop the now-unused
_cast_encoder_inputhelper fromtasks/_base.py. - Rewrite the
test_*_encoder_inputs_*tests to assert encoder inputs matchconfig.dtypeand that there is noCastconsumingpixel_valuesat graph entry.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| src/mobius/tasks/_base.py | Removes the _cast_encoder_input helper. |
| src/mobius/tasks/_vision_language.py | pixel_values declared at config.dtype; helper import dropped. |
| src/mobius/tasks/_vision_language_3model.py | Base/Qwen/Pixtral VL pixel_values declared at config.dtype. |
| src/mobius/tasks/_multimodal.py | pixel_values and audio_features declared at config.dtype. |
| src/mobius/tasks/_speech_language.py | input_features declared at config.dtype. |
| src/mobius/tasks/_audio_ctc.py | input_features declared at config.dtype. |
| src/mobius/tasks/_fun_asr_speech_language.py | input_features declared at config.dtype. |
| src/mobius/tasks/_hunyuan_vl_mot.py | pixel_values declared at config.dtype. |
| src/mobius/tasks/_phi4mm_multimodal.py | Vision pixel_values and speech audio_embeds declared at config.dtype. |
| src/mobius/tasks/_gemma4.py | Vision pixel_values and audio input_features declared at config.dtype. |
| tests/build_graph_test.py | Tests now assert encoder inputs match config.dtype with no entry-Cast. |
Summary
Revert PR #275 (and the matching original change for
_gemma4.py/_vision_language_3model.py) that declared vision/audio encoder graph inputs asFLOATwith aCastat graph entry. Per discussion with the ORT GenAI team, the runtime does not require encoder inputs to be float32 — it can deliver vision / audio inputs at the same dtype the model was built with (f16/bf16).Declaring the graph input at
config.dtypedirectly:Castnode at graph entry (one fewer op per inference)np.float32Before
After
Files changed
tasks/_vision_language.py,_vision_language_3model.py,_multimodal.py,_audio_ctc.py,_speech_language.py,_hunyuan_vl_mot.py,_phi4mm_multimodal.py,_fun_asr_speech_language.py,_gemma4.py: replace f32+Cast pattern withdtype=config.dtypetasks/_base.py: drop the now-unused_cast_encoder_inputhelpertests/build_graph_test.py: rewritetest_multimodal_encoder_inputs_*/test_gemma4_encoder_inputs_*to assert encoder inputs matchconfig.dtypeand that there is noCastat graph entryOut of scope
Single-model encoder-only tasks (
_image_classification.py,_audio_feature_extraction.py) still declareFLOATbecause they have no separate compute dtype — the whole model is f32 and inputs go straight to the encoder.Tests
L1 + unit suite: 2763 passed, 43 skipped (no regressions).
ruff check+ruff format --checkboth pass.