Repository navigation
🚨 Exporters: decompose generative models into one decode graph - #50252
Draft
IlyasMoutawwakil wants to merge 74 commits into
Draft
IlyasMoutawwakil wants to merge 74 commits into
IlyasMoutawwakil wants to merge 74 commits into
Conversation
… init Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…iding cross-attention cache Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…er on the base method Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
…o exporters-generation-decomposition # Conflicts: # src/transformers/configuration_utils.py
…exporters-generation-decomposition # Conflicts: # src/transformers/models/t5gemma2/modular_t5gemma2.py
…ion changes Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Rebuilt from #50038 on the multimodal runtime: one decode graph serving the prefill step, optimum-intel component names, a generation flag in the manifest, and the shared multimodal split. 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: |
…it from the model's Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-decomposition # Conflicts: # src/transformers/exporters/runtimes/runner_executorch.py
…-decomposition # Conflicts: # src/transformers/exporters/decompose.py
…-decomposition # Conflicts: # src/transformers/exporters/decompose.py
A decode step has no image rows: the decode capture takes `dense_deepstack` zeros and the prompt's call the split's dense features, so the one decode graph serves both, as for any other model. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…s kernels on the query length Qwen3.5's (and Qwen3-Next's) gated delta rule runs a chunked kernel beyond one query token and a recurrent one for a single token: a decode graph traced on several tokens keeps the chunked kernel, which a one-token step then runs wrong. Such a model's dynamic export now defaults to a one-token decode graph. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… asks for The capture runs `generate` for a few steps only, so a static cache came out sized for the prompt plus those steps, and generating the config's `max_new_tokens` at runtime overflowed it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…-decomposition # Conflicts: # src/transformers/exporters/quantizers/utils.py
…decode_model` Beside a prompt graph, the decode graph is `decode_model` whatever the model (a causal LM's `model`, a multimodal model's `language_model`, an encoder-decoder's `decoder_model`); the embedding and encoder graphs keep their names. Calibration samples follow. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Their selective scan runs as a `while_loop` under export (#50785), so the multi-token decode graph takes the prefill call: the skips go. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…to exporters-generation-decomposition
…to exporters-generation-decomposition # Conflicts: # src/transformers/exporters/base.py # src/transformers/exporters/exporter_openvino.py # src/transformers/exporters/utils.py
…to exporters-generation-decomposition
…to exporters-generation-decomposition
…to exporters-generation-decomposition
…to exporters-generation-decomposition
…to exporters-generation-decomposition
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: unlimited_ocr |
…to exporters-generation-decomposition
…to exporters-generation-decomposition
…to exporters-generation-decomposition
…to exporters-generation-decomposition
…to exporters-generation-decomposition
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 the multimodal runtime PR (#50251), and supersedes #50038, rebuilt on the reworked stack. It also merges #49601 and #49602, which encoder-decoder and cross-attention models need; their diffs show here until they land on
main.Exports generative models the way inference runs them, so a runtime drives them with as little glue as possible: the fewest graphs to load, each graph called the way
generatecalls the model, no work repeated per step, and no weight exported twice.What an export contains
export_for_generationreturns only what a generation loop calls, under Optimum Intel's component names (an OpenVINO export savesopenvino_model.xml,openvino_language_model.xml, ...):"model", an encoder-decoder's"decoder_model", a multi-modal model's"language_model". With a dynamic export it takes several tokens at once, so it also serves the prompt, in one call on an empty cache, and no prompt graph duplicates the weights; with a static export its query axis is one token, and the prompt gets a graph of its own (below), the pair named"prefill_model"and"decode_model"."encoder_model"for an encoder-decoder, which also computes the decoder's cross-attention cache once per input, so the decode graph only reads it. Withdecoder_writes_cross_cachethe decode graph writes it on its first call instead (OpenVINO's default, which keeps the cache as model state)."text_embeddings_model"and one"<modality>_embeddings_model"per modality for a multi-modal model: the same split asexport_multimodal(🚨 Exporters: export multimodal models per component (export_multimodal) #50249), with"language_model"swapped for the cache-carrying decode graph under the same name.A prompt graph beside a decode graph taking one token
A decode graph taking one token (any static export, or
multi_token_decode=False) would take the prompt a token at a time.export_for_generationexports the prompt's call as a graph of its own: prefill and decode are disaggregated, as"prefill_model"and"decode_model"(a multi-modal model's embedding graphs stay as they are):"prefill_model"for the prompt,"decode_model"for the steps"prefill_model"for the prompt;"decode_model"continues from a copy of its stateWith a single config the prompt graph is dynamic even behind a static decode graph, so a static export takes prompts of any length; a per-component config dict keeps full control. Quantization calibrates
"prefill_model"on the prompt's call. The runtime that drives these graphs is #50254.What each graph does
logits_to_keepis fixed in the graph, so a long prompt doesn't return[batch, tokens, vocab]logits.keep_all_logits=Truereturns every position, for assisted decoding.One graph for both calls, on every backend
A decode graph serving the prefill step must not be guarded on the traced step's shapes:
index_copyfor static-cache writes.EncoderDecoderCache.is_updated) into string keys.Decomposition
exporters/decompose.pygains the generation decomposition: it captures what each stage is really called with from onegeneratecall and returnsComponents, plus"prefill", the prefill step's call to the decode graph as the runtime makes it (cache shaped like the decode capture's, prefill mask, embeddings)."prefill"isn't a graph:export_for_generationdrops it, and calibration and the tests use it.exporters/cache.pyholds the cache helpers it shares with the runtime.Changes outside
exporters/For cache and mask reviewers:
cache_utils.py: caches start as zero-length 4D tensors rather than empty 1D ones, and their counters and the sliding window are created inlazy_initialization, on the cache's device;Cache.early_initializationtakes avalue_head_dimfor latent-attention caches.masking_utils.py: under export, the block-sequence-id padding is a pad ofmax(length, 0)rather than a branch, and the causal-skip shortcut never applies (it would bakeis_causalinto the graph for the traced length).Breaking changes
"model","encoder_model"/"decoder_model","language_model", ...), a disaggregated export's"prefill_model"/"decode_model", andexport_for_generationreturns no"prefill"component.export.json("generation": true): a causal LM's generation and forward exports both hold one"model".runtime()refuses a generation export until the generation runtime lands.decompose_for_generationanddecompose_prefill_decodemove fromexporters.utilstoexporters.decomposeand returnComponents;multi_token_decodefollows whether the export is dynamic, and is refused on a static one.Tests
while_loopunder export since Exporters: fixes to the export path, checked on inputs the exports never saw #50785.torch.export, ONNX, OpenVINO, ExecuTorch) of Llama, BERT, T5, Whisper, Gemma3, Qwen2-VL, LLaVA, PaliGemma and EmbeddingGemma2, andtests/exporters/.🤖 Generated with Claude Code
🤖 mlinter review state
350153929ebd4a47