Repository navigation
🚨 Exporters: export multimodal models per component (export_multimodal) - #50249
Open
IlyasMoutawwakil wants to merge 193 commits into
Open
IlyasMoutawwakil wants to merge 193 commits into
IlyasMoutawwakil wants to merge 193 commits into
Conversation
…t/save_artifact `export()` and `export_for_generation()` return an `ExportArtifacts`, a mapping of `ExportedComponent`s (the backend's program and the metadata recorded while tracing it), saved with `save_pretrained`. Backends implement `export_artifact` and `save_artifact`, and register through `register_backend`. The configs drop their saving fields. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…n names `ExportArtifacts.from_pretrained` loads an export from a local directory or the Hub (only the files the manifest names), through each backend's `load_artifact`; `push_to_hub` and `save_pretrained(push_to_hub=True)` upload it. ONNX and OpenVINO record their final graph's input and output names in the metadata. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`.xml` / `.bin` don't name their format, so OpenVINO components save as `openvino_<name>.xml`, as optimum-intel's do. Other backends keep `<name>.<ext>`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`ExportFormat` is a `StrEnum`, so configs serialize as they are and custom backends use plain strings. The registry lookup splits into `get_export_config_class` and `get_exporter_class`. The metadata drops the fields that described the traced program rather than the saved graph. Overlapping tests are merged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nst the Hub `export_program` / `save_program` / `load_program`, `program_files` and `.program` replace the `artifact` names, which now only mean the `ExportArtifacts` container. A loaded ONNX graph doesn't read its weights; calling it runs the saved file in ONNX Runtime. `get_exporter_class` / `get_export_config_class` are public. Hub tests move to `test_hub.py`, with staging tests pushing and loading a real export. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cuTorch A loaded ONNX program reads its graph without the weights, and a call runs the saved file in ONNX Runtime. `num_user_outputs` and `constant_inputs` are recorded again for Dynamo and ExecuTorch, whose saved programs bind positionally; ONNX and OpenVINO drop them, as they describe the traced program rather than those saved graphs. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cord the export config Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… through one path Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A runner per backend (`exporters/runtimes/`) runs a program as an export returns it or a load reads it back. `ExportArtifacts.runtime()` picks how an export runs and returns an `ExportedModel`, called like the model it came from; `AutoExportedModel.from_pretrained` loads any saved export to run. The per-model forward export tests run through the runners, and the ExecuTorch test helper keeps only its skip policy around the runner. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…cuTorch runner A dynamic export returns a static cache's positions as integers, which the model keeps inside its cache rather than returning as tensors. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…toExportedModel and can_generate Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ore loading it Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update. Pages changed in this PR: |
This was referenced Nov 2, 2026
…inding) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…e back (save_pretrained, push_to_hub) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
export_multimodal)export_multimodal)
A Python scalar kwarg (`output_router_logits=False`) is a constant of the graph, not an input: binding it shifted every later input by one slot. OpenVINO's `infer` already copies its outputs out of the request's buffers, so the extra copy is dropped, and inputs are shared instead of copied in. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Qwen3-VL and Granite4-Vision add vision features inside their first decoder layers (deepstack), at the image positions, besides scattering them into `inputs_embeds`. The outer forward derives both from the pixel values, which the split removes, so the language model silently ran without them. Both outer forwards now accept them, as their text models already do (`visual_pos_masks`/`deepstack_visual_embeds`, `vision_mask`/`deepstack_features`), with the arguments documented once in `auto_docstring`; the split takes them from the captured decoder call, and the vision component returns Qwen3-VL's per-layer features. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…dict keys in a saved spec ExecuTorch has no string value, and a program's string constant (`vision_feature_select_strategy="default"`) takes `None` in its slot. A cache's pytree context keeps a dict with non-string keys as pairs, since JSON reads `EncoderDecoderCache.is_updated`'s int keys back as strings and the saved input spec no longer matches. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The language model takes the deepstack features over every position: an all-True mask, and each layer's features with zeros at the text rows. Adding zeros changes nothing (the split matches the model exactly), and every step then takes the same shapes, so a decode step, which has no image rows, can feed the same graph zeros. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…and session options `ExportArtifacts.runtime(device, **runner_kwargs)` hands the options to the backend's runner: an ONNX Runtime `providers` list (TensorRT with its options, say) and `session_options`. ONNX Runtime sizes its thread pool from every core of the machine rather than the ones the process may run on, which `intra_op_num_threads` fixes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ters-modelopt-quantizer
…to exporters-multimodal-decomposition
…code Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Model linter — first pass
transformers-mlinter found 3 item(s) in the model files this PR touches. These are structural conventions a maintainer would otherwise flag by hand.
This is automated and advisory — it does not block merging.
| rule | count | what it checks |
|---|---|---|
TRF057 |
3 | Public model, config, output and processor classes and their public methods must carry @auto_docstring. |
3 item(s) outside this diff
src/transformers/models/hy_v4_vl/modular_hy_v4_vl.py:514TRF057 — TRF057:HYV4VLModel.get_image_featuresin modeling_hy_v4_vl.py has no @auto_docstring. Declaring @can_return_tuple here drops every decorator of the parent method. Add @auto_docstring as the innermost decorator here.src/transformers/models/hy_v4_vl/modular_hy_v4_vl.py:538TRF057 — TRF057:HYV4VLModel.get_video_featuresin modeling_hy_v4_vl.py has no @auto_docstring. Declaring @can_return_tuple here drops every decorator of the parent method. Add @auto_docstring as the innermost decorator here.src/transformers/models/moss_transcribe_diarize/modular_moss_transcribe_diarize.py:779TRF057 — TRF057:MossTranscribeDiarizeForConditionalGeneration.get_audio_featuresin modeling_moss_transcribe_diarize.py has no @auto_docstring. No parent method it could inherit the decorator from declares it. Add @auto_docstring as the innermost decorator here.
…ters-modelopt-quantizer
…to exporters-multimodal-decomposition
…ters-modelopt-quantizer
…to exporters-multimodal-decomposition
…ters-modelopt-quantizer
…to exporters-multimodal-decomposition
…ters-modelopt-quantizer
…to exporters-multimodal-decomposition
…ters-modelopt-quantizer
…to exporters-multimodal-decomposition
…ters-modelopt-quantizer
…to exporters-multimodal-decomposition # Conflicts: # tests/models/minicpmv4_7/test_modeling_minicpmv4_7.py
…ters-modelopt-quantizer
…to exporters-multimodal-decomposition
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ters-multimodal-decomposition
#50643) Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IlyasMoutawwakil
changed the base branch from
exporters-modelopt-quantizer
to
exporters-main-fixes
November 22, 2026 20:30
…ters-multimodal-decomposition
…ters-multimodal-decomposition
…ters-multimodal-decomposition
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: cohere_compass, cosmos3_omni, embedding_gemma2, granite4_vision, minicpmv4_7, qwen3_vl, qwen3_vl_moe |
This branch has not been deployed
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.
What does this PR do?
Stacked on #50785 (on #50733, whose flat vision getters (
get_<modality>_embeddings) the vision graphs export). Exports a multimodal model's forward as one graph per part, the way optimum-intel splits VLMs, so models whose inputs mix text with images, video or audio export without a generation loop:Why
AutoModelForSequenceClassificationheads on VLMs, and its pooling and projection on top. A single graph can't take them: the modality encoders run data-dependent code (patch counts, feature scattering) that only traces cleanly per part.language_modelfor its cache-carrying one under the same name.The split
text_embeddings_modelinput_idsinputs_embeds, placeholder tokens zeroed<modality>_embeddings_model(vision,video,audio)pixel_values,input_features, ...)[num_tokens, hidden]tensor, through the model's ownget_<modality>_embeddings(#50733), orget_<modality>_featureswhere it has no flat getter (projector included); the per-item split would fix the item count in the graphlanguage_modelinputs_embeds(features scattered in) and the model's other kwargsdecompose_multimodal(model, inputs)captures each part's real call from one eager forward, so the components need no per-model code: anything exposingget_image_features/get_video_features/get_audio_featuressplits. Inputs a part computes from data (M-RoPEposition_ids) are precomputed from the config (precompute_export_inputs).export_multimodalexports each component through the same path asexport, with one config or one per component, calibrating each component on its own inputs when quantizing.Deepstack models (Qwen3-VL and its variants, Granite4-Vision) also add vision features inside their first decoder layers, at the image positions. Their vision component returns those per-layer features too, and
language_modeltakes them next toinputs_embeds.Fixes in the split
image_hidden_statesin the shape the model's forward does: flat for LLaVA, one row per image for Gemma3 and PaliGemma[num_tokens, hidden], following LLaVAinputs_embedsalso takesinput_ids, so its head pools at the last token that isn't paddingThe export-path fixes this PR used to carry (window attention, ONNX Runtime fusions,
OrtFusionConfig, the gated delta rule, runner changes) are in #50785, below it.Modeling changes
Qwen3-VL's and Granite4-Vision's outer forwards accept the two deepstack inputs their text models already take (
visual_pos_masks/deepstack_visual_embeds,vision_mask/deepstack_features), so a caller holding the vision features can run the decoder oninputs_embeds. Behaviour withpixel_valuesis unchanged. The arguments are documented once, inauto_docstring.make fix-repocarries the change to Qwen3-VL-MoE, Cohere Compass and Cosmos3-Omni.Breaking changes
export_multimodaland inexport_for_generationalike:"text_embeddings_model", one"<modality>_embeddings_model"per modality, and"language_model", instead of"image_encoder"/"audio_encoder","multi_modal_projector"and"lm_head". Per-component config dicts take the new names.decompose_multimodalandis_multimodalmove fromexporters.utilstoexporters.decompose;decompose_multimodalreturnsComponents (module,inputs) instead of tuples.register_export_input_preparerandprecompute_export_inputsmove toexporters.precompute. Preparers take(config, inputs)instead of the model, andprecompute_export_inputs(config, inputs)returns the completed inputs instead of editing them in place, so a runtime can compute them from the config alone.Tests
tests/exporters/test_utils.py: the split of a tiny LLaVA (names, inputs,language_model's logits against the full model), a tiny Qwen2-VL's vision graph run on other image counts than traced, andexport_multimodalend to end with save and load.tests/exporters/test_quantization.py: per-component quantization of a VLM.tests/exporters/test_fusions.py: Gemma 4's vision rotary fused intoRotaryEmbedding(its fusion is in Exporters: fixes to the export path, checked on inputs the exports never saw #50785), outputs against the plain export.tests/exporters/test_export.py: the export tests' new-input check (Exporters: fixes to the export path, checked on inputs the exports never saw #50785) also runs on multimodal splits, whose precomputed inputs this split computes from the config.🤖 Generated with Claude Code
🤖 mlinter review state
bccbae7ed8cf0ecfexport_multimodal) #50249 (review)