Skip to content

fix(xla): bound prefill positions in the C entry points - #2957

Merged
inureyes merged 2 commits into
mainfrom
fix/issue-2954-prefill-position-bounds
Nov 11, 2026
Merged

inureyes merged 2 commits into
mainfrom
fix/issue-2954-prefill-position-bounds

Conversation

@inureyes

Copy link
Copy Markdown
Member

Summary

Bound every prefill position to [0, context_capacity) in the four C prefill entry points and NULL-check xla_llama_prefill, so a direct C caller cannot drive an out-of-bounds RoPE-table read through the padded tail. Valid inputs take the previous path and produce the same output.

What changed

  • src/lib/mlxcel-xla/csrc/xla_iree.c: add xla_check_prefill_positions and call it before any IREE call from xla_llama_prefill, xla_llama_prefill_slot_logits, xla_llama_prefill_diagnostics_slot, and xla_llama_prefill_embeddings_impl. Each call covers every axis and every padded-tail slot, and the first violation prints the caller, axis, index, value, and capacity. xla_llama_prefill now NULL-checks its context, tokens, positions, and output, and the diagnostics entry NULL-checks tokens and positions.
  • src/lib/mlxcel-xla/src/iree.rs: declare two test-support forwarders and expose test_prefill_with_positions / test_prefill_slot_logits_with_positions on the engines.
  • src/lib/mlxcel-xla/src/lib.rs: re-export IreeLlama under test-support, matching IreeRaggedLlama.
  • tests/xla_ragged_hardening.rs: one ignored device test drives the boundary with an out-of-range 1D position and an out-of-range M-RoPE axis, then shows the same tokens succeed when every value is in range.

The hooks are minimal by design. The public Rust API synthesizes canonical positions, and PreparedIreePrefill::prepare_for_mode rejects explicit out-of-range positions, so only a C-level forwarder reaches the boundary under test. Two forwarders cover the entry points a device test can drive; the diagnostics and embeddings entries share the same helper and are covered by the four-call-site grep.

Test plan

  • cargo fmt --all -- --check
  • cargo clippy -p mlxcel-xla --features iree --lib --tests -- -D warnings
  • cargo test -p mlxcel-xla --lib validation::tests::emit_all_reproduces_registered_goldens
  • cargo check --features xla-iree,test-utils --test xla_ragged_hardening
  • cargo test --release --features xla-iree,test-utils --test xla_ragged_hardening -- --ignored --nocapture (5 passed)
  • git diff --stat src/lib/mlxcel-xla/assets is empty, so no golden was edited
  • grep shows exactly four call sites of xla_check_prefill_positions

Closes #2954

A prefill position outside [0, context_capacity) is an out-of-bounds device read, not an error the graph can report: the emitted graph indexes the RoPE table with the caller values and clamps nothing, and the padded tail (real_len < lp) reaches the same gather. PR #2936 bounded decode at the Rust wrapper and the C decode entry points; the four prefill C entry points still forwarded caller positions unchecked.

Add one shared xla_check_prefill_positions helper and call it before any IREE call from xla_llama_prefill, xla_llama_prefill_slot_logits, xla_llama_prefill_diagnostics_slot, and xla_llama_prefill_embeddings_impl, covering every axis and every padded-tail slot. xla_llama_prefill also NULL-checks its context, tokens, positions, and output; the diagnostics entry gains the token/position NULL checks. The first violation returns 1 and prints the caller, axis, index, value, and capacity.

The public Rust API synthesizes canonical positions and rejects explicit out-of-range ones before C, so two test-support forwarders drive the boundary directly. One device test feeds an out-of-range 1D position and an out-of-range M-RoPE axis through the same tokens that succeed when every value is in range.

Validated with cargo fmt, clippy -D warnings on mlxcel-xla, the registered-golden test (no golden edited), a test-target check, and the full ignored xla_ragged_hardening suite on the ROCm host (5 passed).

Closes #2954
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:high High priority area:inference Generation, sampling, decoding (incl. speculative, DRY) status:done Completed and removed status:review Under review labels Nov 11, 2026
@inureyes
inureyes marked this pull request as ready for review November 11, 2026 03:44
@inureyes
inureyes merged commit 3750d8f into main Nov 11, 2026
31 checks passed
@inureyes
inureyes deleted the fix/issue-2954-prefill-position-bounds branch November 11, 2026 03:44
@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:inference Generation, sampling, decoding (incl. speculative, DRY) priority:high High 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(xla): bound prefill position values in the C entry points

1 participant