Skip to content

fix: apply HF Llama text_config defaults for LLaVA-1.5 on OpenXLA - #3396

Merged
inureyes merged 6 commits into
mainfrom
fix/issue-3366-llava-xla-text-config-defaults
Nov 24, 2026
Merged

inureyes merged 6 commits into
mainfrom
fix/issue-3366-llava-xla-text-config-defaults

Conversation

@inureyes

@inureyes inureyes commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

llava-1.5-7b-4bit declares text_config.model_type = "llama" and leaves the Llama sizes implicit, so OpenXLA refused it with text_config.hidden_size is required. The fix applies the HF LlamaConfig defaults for the declared model type in one shared mlxcel-xla table, used by the text-graph emitter, the IREE vision config and both LLaVA host preprocessors. Explicit values win, and an unknown text model type still fails closed with an error naming the field and the model type.

One predicate, is_llava_text_defaults_wrapper (wrapper llava or llava_next, text model type llama or absent, as HF LlavaConfig/LlavaNextConfig do), gates the defaults in all three places so the host and emitter resolve the same config. LlavaVisionConfig still rejects llava_next (no anyres in the IREE vision graph), now pinned by a test. A review scan of every local LLaVA-family checkpoint found none relying on the old absent-means-tied behaviour.

The table also sets tie_word_embeddings=false. Without it the emitter's tied fallback replaced lm_head with the embedding table and the text came out as garbage once loading worked.

  • Real checkpoint (cuda, greedy, -n 16, --image tests/fixtures/test_image.png): OpenXLA token ids 450 1967 338 263 3802 29899 786 310 385 24841 3239 29892 10075 263 10090 470 equal eager's (MLXCEL_SDPA_DETERMINISTIC=1).
  • llava-interleave-qwen-0.5b-bf16 on OpenXLA is unchanged.
  • Known limit: this checkpoint's center-crop preprocessing is refused by IREE vision, so the vision step falls back to the host path (about 2 tok/s); out of scope here.
  • cargo test -p mlxcel-xla --lib llava (15 tests, including Config parsing for implicit llava and llava_next text configs and an explicit tie flag winning), cargo check --features cuda,xla-iree --all-targets, cargo check --no-default-features --features xla-diagnostics --all-targets and the license header check pass.

Closes #3366

llava-1.5-7b-4bit declares text_config.model_type "llama" and leaves hidden_size, layer and head counts implicit, so the XLA host preprocessor refused it. Eager recovers the same values from the checkpoint tensors; the XLA path reads only config.json.

A new ungated mlxcel-xla module holds one table of the transformers LlamaConfig defaults, applied (explicit values win) in the text-graph emitter config, the IREE vision config and both LLaVA host preprocessors. Besides the architecture sizes it sets tie_word_embeddings to false: the emitter's fallback for an absent key is tied, which replaced lm_head with the embedding table and made the text garbage once loading succeeded. A text model type without a known table still fails closed, and the error now names the field and the model type.

Verified on llava-1.5-7b-4bit (cuda, greedy, 16 tokens): the OpenXLA token ids equal eager's. llava-interleave-qwen-0.5b-bf16 is unchanged. Unit tests cover defaulting, explicit values, kv heads, and the unknown-type fail-closed case.

Refs #3366
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority labels Nov 24, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Load llava-1.5-7b-4bit on OpenXLA by applying HF LlamaConfig defaults to a LLaVA text_config that declares llama (or no type), keep fully spelled configs unchanged, and fail closed with a precise message for other text types (#3366).

Checkpoint scan (tie flag vs safetensors headers)

Checkpoint Wrapper text model_type text tie Separate lm_head Resolved tie on this PR OK
llava-1.5-7b-4bit llava llama absent yes false (table) yes, was tied before (wrong)
llava-interleave-qwen-0.5b-bf16 llava qwen2 true no true (explicit, table skipped) yes
llava-next-mistral-7b-4bit llava_next mistral absent yes table not applied unchanged
llava-v1.6-mistral-7b-4bit llava_next mistral absent yes table not applied unchanged
bunny, fastvlm, pixtral, mistral3, aya_vision other wrappers various various various not reached unchanged

No local LLaVA-wrapper checkpoint relies on the old "absent means tied" fallback. The only llava + llama checkpoint ships language_model.lm_head, matching HF LlamaConfig.tie_word_embeddings=False.

Verified

  • Defaults match transformers.LlamaConfig (vocab 32000, hidden 4096, intermediate 11008, layers 32, heads 32, kv heads = heads, max positions 2048, rms eps 1e-6, rope theta 10000, untied); explicit values win (entry().or_insert).
  • Fail closed: a llava config with text_config.model_type set to mistral, and an interleave config with hidden_size removed, both stop at load with LLaVA text_config.hidden_size is required: text_config.model_type="..." has no known Hugging Face default for it, with and without --image.
  • Eager untouched: load_llava_vlm still infers from weights; only the XLA host preprocessors changed.
  • GB10 cuda, greedy -n 16, tests/fixtures/test_image.png: OpenXLA and eager produce identical text for llava-1.5-7b-4bit and llava-interleave-qwen-0.5b-bf16. cargo test -p mlxcel-xla --lib llava passes (10 tests).
  • No security or performance concern: one map clone at load.

Remaining Items

  • (MEDIUM, follow-up) The host preprocessor applies the table for llava_next too, while the emitter (config.rs) and vision_config.rs gate on llava only. llava-hf/llava-v1.6-vicuna-7b-hf is llava_next + llama with no hidden_size and no tie flag, so the host would default while the text graph fails with the generic config.json missing integer error, and extending the gate would also need the untied default. No such checkpoint is local, so it was left alone. The default also shadows the root hidden_size fallback in the host path, which is HF-correct for LLaVA.
  • (LOW) No unit test drives Config or LlavaVisionConfig parsing for a llava wrapper with an implicit llama text_config, for example asserting tie_word_embeddings == false and hidden == 4096. The wiring is covered only by the real-checkpoint run.
  • (LOW, pre-existing) The emitter's tie_default for plain model_type: llama is true, unlike HF LlamaConfig. It is latent because standalone Llama configs spell the flag out.

The issue asked to reuse the eager helper. Eager infers these fields from the weights rather than from a table, so a config-only table is a reasonable alternative and the module doc says why.

Verification

  • All stated requirements implemented
  • No placeholder/mock code remaining
  • Integrated into project code flow
  • Project conventions followed
  • Existing modules reused where applicable
  • No unintended structural changes
  • Tests pass

The host preprocessor applied the llama text_config defaults to llava_next wrappers while the XLA text-graph emitter and vision config applied them to llava only, so a llava-hf/llava-v1.6-vicuna-7b-hf style config (llava_next wrapper, llama text, no hidden_size, no tie flag) resolved differently on the two sides.

Add is_llava_text_defaults_wrapper (llava or llava_next, matching HF LlavaConfig and LlavaNextConfig) and use it in the host resolver, emitter Config and LlavaVisionConfig. The untied default is the same everywhere. Checkpoints that spell text_config out, including the mistral llava-next ones, are unchanged. LlavaVisionConfig still rejects the llava_next wrapper itself because the IREE vision graph has no anyres support.

Tests cover implicit llama text for llava and llava_next (hidden 4096, tie false), an explicit tie flag winning, and the predicate.

Validation: cargo test -p mlxcel-xla --lib llava

Refs #3366
…xla-text-config-defaults

# Conflicts:
#	CHANGELOG.md
Name the (field, default constructor) row type so cargo clippy -p mlxcel-xla --lib --tests -- -D warnings passes.

Refs #3366
@inureyes inureyes added status:done Completed area:inference Generation, sampling, decoding (incl. speculative, DRY) area:architecture Architecture and code structure changes priority:low Low priority and removed status:review Under review labels Nov 24, 2026
@inureyes
inureyes marked this pull request as ready for review November 24, 2026 07:22
…xla-text-config-defaults

# Conflicts:
#	CHANGELOG.md
`mlxcel-xla` is an optional dependency of the root crate, so the default-feature build (CI cargo-clippy) failed to resolve `mlxcel_xla` in `src/loading/vlm_llava.rs`. The defaults table is applied only with `xla-backend`; without it the host config is left as declared and the missing-field error names the field.

Refs #3366
@inureyes
inureyes merged commit fc10c85 into main Nov 24, 2026
33 checks passed
@inureyes
inureyes deleted the fix/issue-3366-llava-xla-text-config-defaults branch November 24, 2026 11:57
@inureyes inureyes added this to the 0.9 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:architecture Architecture and code structure changes area:inference Generation, sampling, decoding (incl. speculative, DRY) priority:low Low priority priority:medium Medium priority status:done Completed type:bug Bug fixes, error corrections, or issue resolutions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix: apply HF text_config defaults for LLaVA-1.5 on the XLA path

1 participant