Add Qwen3-VL export support for multimodal text-to-text pipeline#214
Open
seyeong-han wants to merge 1 commit intohuggingface:mainfrom
Open
Add Qwen3-VL export support for multimodal text-to-text pipeline#214seyeong-han wants to merge 1 commit intohuggingface:mainfrom
seyeong-han wants to merge 1 commit intohuggingface:mainfrom
Conversation
…oading - Introduced pre-computation of position-related values for M-RoPE vision encoders in VisionExportableModule to enhance export efficiency. - Added a method to register a forward pre-hook for M-RoPE models to inject position_ids during text decoder export, preventing crashes due to missing input_ids. - Updated load_multimodal_text_to_text_model to fallback to AutoModelForImageTextToText when AutoModelForPreTraining fails, ensuring compatibility with various model types. - Enhanced modality detection logic to correctly identify the primary non-text modality for multimodal models, improving robustness in model loading.
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.
Overview
Enables exporting Qwen3-VL vision-language models through the multimodal-text-to-text task. Qwen3-VL uses M-RoPE (Multi-dimensional Rotary Position Embeddings) and a Conv3d-based vision encoder, both of which require special handling during torch.export.
Changes
Three changes to the export pipeline:
M-RoPE vision encoder positions — The Qwen3-VL visual encoder computes position embeddings via data-dependent ops (torch.linspace, repeat_interleave on image_grid_thw) that torch.export cannot trace. VisionExportableModule now pre-computes pos_embeds, rotary_pos_emb, and cu_seqlens eagerly and stores them as buffers so they become constants in the exported graph.
M-RoPE text decoder hook — During text decoder export only inputs_embeds and cache_position are provided (no input_ids). M-RoPE models call get_rope_index which requires input_ids and crashes. A forward pre-hook injects position_ids derived from cache_position so the model skips that code path.
Model loading / modality detection — AutoModelForPreTraining doesn't resolve Qwen3-VL, so we fall back to AutoModelForImageTextToText. Modality detection now handles models that report more than two modalities (Qwen3-VL reports ("image", "video", "text")) by picking the first supported non-text modality.
Quantized model is ~1.4 GB (down from ~4.4 GB bf16).
Text decoder runs at ~25-29 tok/s on Apple Silicon via XNNPACK.