Repository navigation
Keep vision/audio inputs f32 in single-model tasks for f16/bf16 builds - #275
Merged
Merged
Conversation
Apply the f32+Cast-at-input pattern to 3 remaining task files: - _vision_language.py: pixel_values (Qwen3-VL single-model) - _multimodal.py: pixel_values + audio_features (generic multimodal) - _audio_ctc.py: input_features (SenseVoiceSmall CTC) Image/audio processors output f32. Declaring graph inputs as FLOAT with a Cast to config.dtype at entry ensures correct type matching regardless of the model's compute precision. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Performance Comparison
|
Codecov Report❌ Patch coverage is
📢 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) |
Add _cast_encoder_input(op, tensor, config) to _base.py and replace all 13 inline if-config.dtype-Cast blocks across 8 task files. The helper encapsulates the pattern: vision/audio graph inputs are declared as FLOAT (matching processor output), and Cast to config.dtype is added when the model uses f16/bf16. Co-authored-by: Copilot <[email protected]> Signed-off-by: Justin Chu <[email protected]>
Member
Author
|
Added DRY refactor: extracted Commit: 26f1c0c |
This was referenced May 6, 2026
justinchuby
added a commit
that referenced
this pull request
May 27, 2026
## Summary Revert PR #275 (and the matching original change for `_gemma4.py` / `_vision_language_3model.py`) that declared vision/audio encoder graph inputs as `FLOAT` with a `Cast` at 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.dtype` directly: - matches the model's internal compute dtype - removes the extra `Cast` node at graph entry (one fewer op per inference) - simplifies test harnesses that previously had to cast feature-extractor output to `np.float32` ## Before ```python pixel_values = builder.input("pixel_values", dtype=ir.DataType.FLOAT, shape=[...]) pixel_values = _cast_encoder_input(op, pixel_values, config) # adds Cast when config.dtype != FLOAT ``` ## After ```python pixel_values = builder.input("pixel_values", dtype=config.dtype, shape=[...]) ``` ## 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 with `dtype=config.dtype` - `tasks/_base.py`: drop the now-unused `_cast_encoder_input` helper - `tests/build_graph_test.py`: rewrite `test_multimodal_encoder_inputs_*` / `test_gemma4_encoder_inputs_*` to assert encoder inputs match `config.dtype` and that there is no `Cast` at graph entry ## Out of scope 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 inputs go straight to the encoder. ## Tests L1 + unit suite: 2763 passed, 43 skipped (no regressions). `ruff check` + `ruff format --check` both pass. Signed-off-by: justinchuby <[email protected]> Co-authored-by: justinchuby <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Apply the f32+Cast-at-input pattern to 3 remaining task files that still used
config.dtypefor vision/audio graph inputs.Problem
When building with
--dtype bf16or--dtype f16, image/audio processor outputs are always f32. If graph inputs are declared atconfig.dtype(e.g. bf16), ORT raises type mismatches at load time.Fix
Declare vision/audio graph inputs as
ir.DataType.FLOATand add aCasttoconfig.dtypeat graph entry, matching the pattern already used in_gemma4.pyand_vision_language_3model.py.Files changed:
_vision_language.py:pixel_values(Qwen3-VL single-model task)_multimodal.py:pixel_values+audio_features(generic multimodal task)_audio_ctc.py:input_features(SenseVoiceSmall CTC task)Tests
1204 passed, 40 skipped — no regressions.