Skip to content

Document f32 input casting for vision/audio encoders in multimodal skill - #271

Merged
justinchuby merged 6 commits into
mainfrom
skill-multimodal-f32-cast
May 6, 2026
Merged

Document f32 input casting for vision/audio encoders in multimodal skill#271
justinchuby merged 6 commits into
mainfrom
skill-multimodal-f32-cast

Conversation

@justinchuby

Copy link
Copy Markdown
Member

Update the multimodal-models skill to document why vision/audio encoder graphs accept f32 inputs and Cast to model dtype at graph entry.

What this adds

New section in .agents/skills/multimodal-models/SKILL.md:

  • Why: ORT GenAI image/audio processors always output f32, regardless of model dtype
  • How: Encoder graph adds Cast(f32 → model_dtype) at entry; weights remain in f16/bf16
  • When: Handled automatically by mobius with --runtime ort-genai
  • Error without it: Type Error: Type parameter (T) bound to different types

This documents the pattern introduced in PR #265.

Add section to multimodal-models skill explaining why vision and
audio encoder graphs accept f32 inputs and Cast to model dtype:
- ORT GenAI processors always output f32
- Encoder adds Cast(f32 → f16/bf16) at graph entry
- Weights remain in requested dtype for memory efficiency
- Handled automatically by mobius with --runtime ort-genai
- Explains the type mismatch error users see without the Cast

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
@github-actions

github-actions Bot commented May 6, 2026

Copy link
Copy Markdown

Performance Comparison

Comparing f027a8e34e0cba

Model Metric Baseline Current Delta
bert (feature-extraction) model_size_bytes 359 KB 359 KB +0.0%
bert (feature-extraction) num_nodes 60 60 +0.0%
falcon model_size_bytes 364 KB 364 KB +0.0%
falcon num_nodes 66 66 +0.0%
gemma2 model_size_bytes 428 KB 428 KB +0.0%
gemma2 num_nodes 107 107 +0.0%
gpt2 model_size_bytes 388 KB 388 KB +0.0%
gpt2 num_nodes 53 53 +0.0%
llama model_size_bytes 425 KB 425 KB +0.0%
llama num_nodes 61 61 +0.0%
llama (static-cache) model_size_bytes 425 KB 425 KB +0.0%
llama (static-cache) num_nodes 58 58 +0.0%
mamba (ssm-text-generation) model_size_bytes 296 KB 296 KB +0.0%
mamba (ssm-text-generation) num_nodes 98 98 +0.0%
phi3 model_size_bytes 421 KB 421 KB +0.0%
phi3 num_nodes 59 59 +0.0%
phi3 (static-cache) model_size_bytes 421 KB 421 KB +0.0%
phi3 (static-cache) num_nodes 56 56 +0.0%
qwen2 model_size_bytes 425 KB 425 KB +0.0%
qwen2 num_nodes 61 61 +0.0%
qwen2 (static-cache) model_size_bytes 425 KB 425 KB +0.0%
qwen2 (static-cache) num_nodes 58 58 +0.0%
qwen3_5_moe (hybrid-text-generation) model_size_bytes 506 KB 506 KB +0.0%
qwen3_5_moe (hybrid-text-generation) num_nodes 275 275 +0.0%
qwen3_5_text (hybrid-text-generation) model_size_bytes 458 KB 458 KB +0.0%
qwen3_5_text (hybrid-text-generation) num_nodes 129 129 +0.0%
qwen3_5_vl (hybrid-qwen-vl) model_size_bytes 977 KB 977 KB +0.0%
qwen3_5_vl (hybrid-qwen-vl) num_nodes 408 408 +0.0%
t5 (seq2seq) model_size_bytes 836 KB 836 KB +0.0%
t5 (seq2seq) num_nodes 166 166 +0.0%
whisper (speech-to-text) model_size_bytes 1008 KB 1008 KB +0.0%
whisper (speech-to-text) num_nodes 128 128 +0.0%

No performance regressions.

@codecov

codecov Bot commented May 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

justinchuby and others added 5 commits May 6, 2026 16:07
Add callout clarifying the Cast-at-input pattern is universal for
all vision/audio models (Gemma3, Gemma4, LLaVA, Phi-3-Vision,
Qwen-VL, Whisper, etc.), not architecture-specific.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
Rewrite the f32 input casting section to explain this is a universal
pattern across ALL inference paths (ORT Python API, Foundry Local,
custom runtimes), not GenAI-specific. f32 is the natural preprocessing
dtype because PIL, torchaudio, librosa, and all preprocessing
libraries output f32. The Cast-at-input is always inserted by mobius
regardless of --runtime flag.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
Document which tasks have the f32+Cast pattern (5 tasks), which
still use config.dtype as input (VisionLanguageTask), and which
single-model tasks correctly use hardcoded FLOAT (7 tasks).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
Add MultimodalTask (pixel_values + audio_features) and AudioCTCTask
(input_features) to the needs-migration list. Move AudioCTCTask out
of the single-model correct list. 3 tasks need migration total.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
Remove per-task migration status table. The section now explains
the general principle concisely without listing internal task status.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Signed-off-by: Justin Chu <justinchu@microsoft.com>
@justinchuby
justinchuby merged commit 6025fbb into main May 6, 2026
20 checks passed
@justinchuby
justinchuby deleted the skill-multimodal-f32-cast branch May 6, 2026 16:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant