Skip to content

fix(xla): read eos_token_id from config.json when generation_config is absent - #3313

Merged
inureyes merged 3 commits into
mainfrom
fix/issue-3292-xla-eos-config-fallback
Nov 23, 2026
Merged

inureyes merged 3 commits into
mainfrom
fix/issue-3292-xla-eos-config-fallback

Conversation

@inureyes

@inureyes inureyes commented Nov 23, 2026 •

Copy link
Copy Markdown
Member

Summary

The XLA backend read EOS only from generation_config.json, so checkpoints without one (qwen2.5-vl-3b-instruct-4bit) generated past EOS 151645 while eager stopped.

  • XLA sessions, batch engines and bucket sets now stop on the same set as eager: the root crate merges mlxcel_xla::config_eos_token_ids (union of generation_config.json, config.json and text_config eos_token_id) with read_eos_token_ids (which also resolves the tokenizer's eos_token via tokenizer_config.json or tokenizer.json) and passes it through the new set_eos_token_ids in both production paths: the single-session builder and the XLA serving worker.
  • Callers that set nothing (tests, examples) keep the crate's own config-derived ids. Eager resolution is unchanged.

Test plan

  • cargo test -p mlxcel-xla --lib --profile test-fast eos_resolution: 8 passed (generation_config present, only config.json, only text_config, neither, union and de-dup, malformed file). The resolver is not iree-gated because the iree lib test build fails to link iree_runtime_* on main.
  • cargo test --profile test-fast --lib --features cuda,xla-backend backend::xla::eos_parity_tests: 3 passed; the XLA stop set equals read_eos_token_ids on fixtures where generation_config, tokenizer_config and config.json declare different ids, including the tokenizer.json lookup.
  • Qwen2.5-VL on CUDA, test_image.png, "Describe this image.", -n 64 --temp 0: XLA and eager both print "The image is a solid orange color." and stop after 8 tokens.
  • cargo check --features cuda,xla-iree --all-targets, cargo check --no-default-features --features xla-diagnostics --all-targets, clippy -D warnings on mlxcel-xla (with and without iree) and the root lib.

Closes #3292

…s absent

The XLA backend read EOS only from generation_config.json. Checkpoints such as qwen2.5-vl-3b-instruct-4bit ship none, so the decode loop ran past EOS 151645 while the eager path stopped.

read_eos now resolves through a pure resolve_eos_ids: generation_config.json eos_token_id, else config.json eos_token_id, else config.json text_config.eos_token_id, accepting an int or a list. Missing or malformed files count as absent, and ids outside i32 are skipped instead of wrapping. The resolver is not iree-gated, so its unit tests run without the IREE link.

Verified on qwen2.5-vl-3b-instruct-4bit (CUDA, test_image.png, -n 64 --temp 0): XLA now stops at EOS with the same 8-token output as eager. cargo check passes for cuda,xla-iree and for xla-diagnostics.

Refs #3292
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:medium Medium priority labels Nov 23, 2026
The first fix took the first non-empty of generation_config, config.json and text_config, while eager stops on the de-duplicated union of generation_config, the tokenizer's eos_token (tokenizer_config.json, falling back to tokenizer.json) and config.json. A checkpoint whose sources disagree let the XLA loop run past a token eager stops on.

mlxcel-xla now resolves the union of its three config sources through a public config_eos_token_ids, and its sessions, batch engines and bucket sets gain set_eos_token_ids. The root crate passes the eager stop set (merged_eos_token_ids over those ids, as the LLaVA loader does for text_config) into both production paths: the single-session builder and the XLA serving worker's bucket set. Callers that set nothing keep the crate's own config ids.

Root tests pin the XLA stop set to read_eos_token_ids on fixtures whose generation_config, tokenizer_config and config.json declare different ids, including the tokenizer.json lookup.

Refs #3292
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Make the XLA backend stop on the same EOS ids as eager when generation_config.json is absent (#3292).

Findings Addressed

  • XLA took the first non-empty of generation_config, config.json and text_config, while eager stops on the union of generation_config, the tokenizer's eos_token (tokenizer_config.json, then tokenizer.json) and config.json, so XLA could run past a stop token eager honors. Fixed in eaa6ff7: the root crate passes the eager stop set into both XLA construction paths (HIGH)

Remaining Items

  • None. The iree-feature mlxcel-xla lib test link failure is pre-existing on main and out of scope.

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

@inureyes

Copy link
Copy Markdown
Member Author

Security and performance review of the EOS id resolution (#3292): no CRITICAL or HIGH findings, no code changes pushed.

  • Out-of-range and malformed ids: eos_ids_of drops non-integers and values outside i32 (tested), and the ids are only compared with contains against sampled tokens. Nothing indexes the vocab or logits with them, so a hostile id cannot go out of bounds. Negative ids are inert.
  • Malformed or missing JSON counts as absent in both readers. No panics or unwraps on the new path.
  • Locking and races: set_eos_token_ids takes &mut, and both call sites run on the loading thread before the engine serves a request. A bucket that failed to load is already dropped from the set, so every live bucket gets the ids. There is no shared state and no lock.
  • Per-step cost: none added. pump already cloned the small eos Vec each step before this PR, and the lookup stays a linear contains over a handful of ids.

MEDIUM (not fixed, matches eager): the sidecar files are read with read_to_string and parsed whole, with no size cap. A very large tokenizer.json is read once at load. config.json and generation_config.json are now read a second time on the XLA path. Checkpoints are operator-supplied and the eager loader behaves the same way, so I left it.

LOW: the mlxcel-xla crate parses config.json strictly while the root crate has sanitize_config_json. read_eos_token_ids also parses strictly, so the result is the same today.

Tests run: cargo test -p mlxcel-xla --lib --profile test-fast eos_resolution (8 passed) and backend::xla::eos_parity_tests with --features cuda,xla-backend (3 passed).

@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 23, 2026
@inureyes
inureyes marked this pull request as ready for review November 23, 2026 06:58
@inureyes
inureyes merged commit 67dc909 into main Nov 23, 2026
33 checks passed
@inureyes
inureyes deleted the fix/issue-3292-xla-eos-config-fallback branch November 23, 2026 07:42
@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

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: read eos_token_id from config.json when the XLA backend has no generation_config.json

1 participant