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
Cast vision/audio inputs f32 to model dtype for GenAI compatibility (#265)
## Summary
Keep vision/audio encoder graph inputs as float32 (matching GenAI
image/audio processor output) and add a Cast(f32→model_dtype) at the
graph entry. Encoder weights use the requested f16/bf16 dtype for memory
efficiency.
## Problem
GenAI multimodal processor outputs float32 pixel values and audio
features. When building with `--dtype f16` or `--dtype bf16`, the
vision/audio encoder graph inputs were also cast to f16/bf16, creating a
type mismatch: GenAI sends f32, encoder expects f16, ORT produces
all-zero output (silent failure).
## Solution: Cast at graph entry
Instead of keeping entire vision/audio encoders at f32 (wasteful), add a
`Cast` op at the start of each encoder graph:
```
pixel_values (f32, from GenAI) → Cast(f32→f16) → vision encoder (f16 weights) → image_features
```
This gives both **GenAI compatibility** (f32 input) and **memory
efficiency** (f16/bf16 weights).
## Changes
- `_gemma4.py`: Vision/audio encoder inputs always `ir.DataType.FLOAT`,
with `op.Cast` to `config.dtype` when dtype ≠ f32
- `_builder.py`: No changes needed — all parameters cast to requested
dtype as before
## Testing
13 gemma4 tests pass. Verified f16 build: vision input=f32, first
node=Cast, weights=f16.
---------
Signed-off-by: Justin Chu <justinchu@microsoft.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
0 commit comments