Repository navigation
Closed
Labels
area:architectureArchitecture and code structure changesarea:modelsModel architectures, weights, loading, metadatapriority:mediumMedium prioritystatus:doneCompletedtype:enhancementNew features, capabilities, or significant additions
Description
Parent and dependencies
- Parent epic: epic: OpenXLA multimodal / VLM architecture support (Qwen2-VL, Gemma3n, Phi4MM, Molmo, and more) #566
- Blocked by refactor(vlm): extract a host multimodal preprocessor for XLA #859 and test(xla): validate a LLaVA reference architecture end to end #862
- Host-first oracle: test(xla): validate a LLaVA reference architecture end to end #862
- Existing MLX vision components:
src/vision/encoders/siglip.rsandsrc/vision/connectors/mlp.rs
Problem
The first XLA multimodal path deliberately keeps the LLaVA-style vision tower and projector on the host/MLX side. That proves correctness but does not satisfy backend parity for accelerator placement, and it leaves a second compute runtime in the serving path. The next step must move a representative vision encoder and projector into StableHLO/IREE without changing the already-qualified language-model prefill contract.
Goal
Emit and execute the LLaVA reference checkpoint's CLIP/SigLIP vision tower and MLP/linear projector through IREE, using the host-first implementation only as a numerical oracle and explicit fallback.
Graph contract
- Define a stable
vision.mainentry that accepts one documented, contiguous pixel tensor layout and produces projected image tokens with shape[num_image_tokens, text_hidden_size]in the dtype expected byprefill_embeddings.main. - Keep decode and the language-model prefill schemas unchanged. The canonical prepared-prefill merge contract remains the integration seam.
- Bind image size, patch size, channel count, encoder depth/width, head count, position-table behavior, and projector shape into the module compatibility fingerprint.
- Require processor metadata and compiled graph metadata to agree before invocation.
Required implementation
- Add reusable StableHLO primitives for patch convolution, class-token handling where applicable, learned position embeddings/interpolation policy, LayerNorm, biased self-attention projections, GELU MLP blocks, and the LLaVA projector sequence.
- Map existing checkpoint names and tensor layouts explicitly. Transpose convolution/linear weights only at one documented loading boundary and validate every expected tensor shape.
- Preserve the reference encoder's normalization epsilon, activation variant, attention scale, position handling, and class-token inclusion/exclusion exactly. Do not substitute a text-transformer default because the operation names look similar.
- Compile/load the vision module as part of the XLA multimodal runtime bundle and include it in atomic cleanup and compatibility checks.
- Upload normalized pixels to the selected IREE device and execute all vision/projector math there. If projected tokens are returned to the host for the canonical merge, make that transfer explicit and measured; no vision layer may silently fall back to MLX.
- Keep the host-first implementation behind an explicit backend/fallback choice for oracle comparison and devices where the vision module is unavailable. Capability reporting must distinguish host-first from IREE-vision support when useful to operators.
- Reject unsupported dynamic image sizes or patch grids unless a separately compiled shape exists. Do not resize inside the StableHLO graph in this issue.
Non-goals
- Qwen windowed/deepstack vision encoders, Gemma-specific masks, audio encoders, or arbitrary ViT variants.
- Moving image decode/resize/normalize into IREE.
- Changing the language-model decoder or M-RoPE.
Validation
- Compare patch embeddings, selected encoder-block outputs, final normalized features, projector outputs, and final greedy tokens against both the host-first path and the independent test(xla): validate a LLaVA reference architecture end to end #862 oracle.
- Set dtype-specific tolerances per stage and report the first divergent block.
- Cover the reference image size, invalid image/patch shapes, missing/mis-shaped weights, class-token behavior, and tied processor/graph metadata.
- Execute on CPU IREE where available and at least one Metal or CUDA target. Emitter-only tests are insufficient.
- Measure host memory, device memory, pixel upload bytes, projected-feature transfer bytes, prefill latency, and throughput against the host-first baseline.
- Run the full test(xla): validate a LLaVA reference architecture end to end #862 gate and existing text-only XLA validation.
Acceptance criteria
- The reference vision tower and projector execute entirely through IREE math kernels.
- The graph schema and artifact identity include every shape/config value that affects compatibility.
- Intermediate and projected features match the host/oracle paths within documented tolerances.
- Final greedy output remains token-exact with test(xla): validate a LLaVA reference architecture end to end #862.
- Unsupported shapes and weight mismatches fail before native execution.
- Host-first fallback is explicit, observable, and cannot occur silently.
- Accelerator execution and transfer/memory measurements are recorded.
Metadata
Metadata
Assignees
Labels
area:architectureArchitecture and code structure changesarea:modelsModel architectures, weights, loading, metadatapriority:mediumMedium prioritystatus:doneCompletedtype:enhancementNew features, capabilities, or significant additions
Activity