Enhance embedding introspection for GenAI config - #321
Conversation
Performance Comparison
|
|
The author of this PR, apsonawane, is not an activated member of this organization on Codecov. |
There was a problem hiding this comment.
Pull request overview
This PR addresses Gemma4 multimodal ORT GenAI export issues by aligning vision input dtype handling, ensuring embedding outputs are represented in genai_config, and passing the selected execution provider through the example export flow.
Changes:
- Declares Gemma4 vision
pixel_valuesas float32 and casts internally to model dtype. - Adds embedding output-name overrides and graph-output introspection for ORT GenAI config generation.
- Propagates
--devicetomobius build --epin the Gemma4 example script.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/mobius/tasks/_gemma4.py |
Changes Gemma4 vision encoder pixel_values input dtype to float32. |
src/mobius/models/gemma4.py |
Casts float32 vision inputs to model dtype inside the vision encoder. |
src/mobius/integrations/ort_genai/genai_config.py |
Adds embedding_output_names support to vision config generation. |
src/mobius/integrations/ort_genai/auto_export.py |
Introspects embedding model outputs and forwards them into genai_config. |
examples/gemma4_genai.py |
Passes the selected device as the Mobius CLI execution provider. |
|
Wasn't the decision to cast inputs in genai? I just merged a PR for that behavior. Or is there a technical difficulty with vision (overflow etc. )? |
…d pass EP to export script
justinchuby
left a comment
There was a problem hiding this comment.
Approving to unblock. LMK the state of the input contract
de60ba3 to
0a9feb0
Compare
|
yes, sorry for the confusion. Casting is happening in genai. I reverted it here |
Summary
Two fixes for Gemma4 multimodal export and genai_config generation.
Introspect embedding model outputs in genai_config.json
The Gemma4 embedding model produces
per_layer_inputsalongsideinputs_embeds, butgenai_config.jsononly listedinputs_embedsin the embedding outputs section. This caused onnxruntime-genai to not bind theper_layer_inputsoutput, so ORT allocated a separate buffer and the decoder received uninitialized data.Added
_introspect_outputs()to auto-discover embedding model outputs from the ONNX graph, andembedding_output_namesparameter toGenaiConfigGenerator.with_vision().Files:
integrations/ort_genai/auto_export.py,integrations/ort_genai/genai_config.pyPass
--epto mobius CLI in export scriptbuild_and_export()ingemma4_genai.pydid not pass the execution provider tomobius build. This caused all exports to use the default EP (which has emptygqa_dtypes), so KV-shared layers fell back to standard Attention instead of GQA — leading topast_present_share_bufferfailures at runtime.Now
--device cudacorrectly maps to--ep cuda, producing all-GQA models.Files:
examples/gemma4_genai.pyTesting