Skip to content

fix: close the LOW residuals left by #2787, #2788 and #2789 - #2792

Merged
inureyes merged 5 commits into
mainfrom
fix/issue-2790-low-residuals
Oct 31, 2026
Merged

inureyes merged 5 commits into
mainfrom
fix/issue-2790-low-residuals

Conversation

@inureyes

@inureyes inureyes commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Closes the five LOW residuals of #2787, #2788 and #2789 listed in #2790, in one PR.

Changes

  • KV storage report (item 1). kv_cache_storage_modes returns Option<Vec<Option<KVCacheMode>>>; a None entry is a layer with no KV. Families describe layers with LayerKv (Full, Sliding, Fp16Only, None) from the predicate their cache builder uses. Llama 4 reports chunked layers as FP16 (uses_chunked_cache now drives the builder, the masks and the report). Qwen3-Next, Qwen 3.5, Qwen4-Exp, Bailing linear, LFM2 and NemotronNAS report linear, convolution and skipped layers as stateless. Model-owned families without a mode table report real storage instead of None: DeepSeek V4, RecurrentGemma, Muse Glimmer, Mamba, Mamba2 and RWKV7 as listed, plus Nemotron-H, Jamba, Falcon-H1, Plamo2, GraniteMoeHybrid, Kimi Linear, Kimi K3 and Inkling, which had the same gap, and the five VLM wrappers around them. The server log adds kv_cache_mode_stateless_layers; logit_trace prints the stateless count.
  • Sliding window (item 2). validate_sliding_window (via cache_window, only when a layer slides) fails the load for 0 or values above i32::MAX in Gemma 3, Gemma 4, GPT-OSS, ExaOne 4, Laguna, Step 3.5, Ministral 3, Mellum and AFMoE; Gemma 3 also rejects sliding_window_pattern: 0. Gemma 3, GPT-OSS, Laguna, Mellum, ExaOne 4, Ministral 3 and AFMoE store the validated i32 for their builders. Gemma 4 validates in both the single-process load and the pipeline-stage load (Gemma4StageModel::from_filtered_weights) and keeps its casts on the shared TextConfig (dozens of sites), now lossless after the check.
  • IREE local-task (item 3). csrc/xla_local_task.c builds the device without the flag registry: executor with 8 MiB worker stacks over MLXCEL_XLA_LOCAL_TASK_WORKERS workers (1..=256, IREE's topology limit; anything else fails the load naming the variable) or the physical-core topology, all loaders, heap allocator, task driver, default device with the same proactor pool the runtime uses. Both device-creating entry points use it; other drivers are unchanged. Every IREE symbol used is exported by the pinned CUDA tree and by iree-dist-3.12.0rc20260721-linux-x86_64 (the only dist published for that release; there is no aarch64 dist), and the new C file compiles against both header trees.
  • Test support (item 4). XlaPreparedPrefillLogits needs mlxcel-xla test-support (root test-utils) or diagnostics, resets slots before each prefill, and Qwen25VlLanguageDiagnosticEngine wraps it. xla_prepared_prefill requires test-utils; the CI link step passes it.
  • Pipeline gate (item 5). Only StageUnreachable (timeout or failed send) opens the gate. A RunEntry timeout opens it unattributed, so the entry stage keeps its teardown wait and the next probe names the silent stage; a failed send logs "could not be reached", and a probe that reopens the gate logs its real cause (send failure or timeout). PipelineUnavailable.stage is Option<String>. docs/distributed.md describes the new rule.

Failing first

Each new test fails on main 1a257bc or, where it cannot compile there, under a mutation restoring main's behaviour:

  • Existing local-task tests, main binary: all three fail with thread creation failed with 22; [runtime-init] failed to open IREE HAL device 'local-task'.
  • local_task_executor_uses_8_mib_stacks_without_iree_flags, stack set back to 128 KiB: xla_local_task_probe failed: ... thread creation failed with 22.
  • llama4_chunked_layers_report_fp16_storage_under_int8: left: Some([Some(Int8) x8]) vs expected Int8 only at 3 and 7.
  • qwen3_next_linear_layers_report_no_kv_storage: eight Some(Int8) vs [None, None, None, Some(Int8), ...].
  • recurrent_gemma_reports_..., mamba_reports_every_layer_stateless, deepseek_v4_reports_fp16_storage_for_every_layer (override returning None): left: None / a storage report.
  • gemma3_rejects_zero_sliding_window_pattern_at_load, sliding_window_zero_is_a_load_error (validation off): the loads succeed.
  • run_entry_timeout_does_not_name_the_entry_stage (main attribution): failed_peer is Some("127.0.0.1:41749"), the entry stage.
  • send_failure_opens_the_gate_with_a_send_reason: the open line reads remote stage 127.0.0.1:40565 did not answer within 1s.

Verification (spark-102, GB10)

  • cargo fmt --all -- --check, make verify-env-var-docs: clean.
  • cargo clippy --profile test-fast --features cuda -p mlxcel -p mlxcel-core -p mlxcel-xla --lib --tests -- -D warnings and cargo clippy --release --features cuda,xla-iree,test-utils -p mlxcel-xla -p mlxcel --lib --test xla_prepared_prefill -- -D warnings: clean.
  • After the review fixes: clippy on mlxcel + mlxcel-xla lib and tests clean, distributed::pipeline:: 416 passed, mlxcel-xla local_task 6 passed.
  • Lib tests (--test-threads=1, gpu-lock): models:: + vision:: 3429 passed; distributed:: + server::batch::scheduler 1845 passed; mlxcel-core cache:: + generate:: 624 passed; mlxcel-xla --lib 370 passed.
  • Integration (cuda,test-utils): distributed_integration 20, pipeline_e2e 30, pipeline_remote_real_models 10, pipeline_server_remote_real_models 7, pipeline_ci_multi_stage_real_models 4 (--include-ignored --skip glm_moe_dsa, MLXCEL_REQUIRE_MODELS=1 MLXCEL_SDPA_DETERMINISTIC=1), disaggregated_serving_e2e 2, disaggregated_router_e2e 8: all pass.
  • cargo test --release --features cuda,xla-iree,test-utils --test xla_prepared_prefill -- --ignored: 4/4 on the default local-task device. MLXCEL_XLA_LOCAL_TASK_WORKERS=0 and abc fail the load naming the variable; 2 passes. Unit tests also reject 257 and 1000.
  • Item 4 gating: a root use mlxcel_xla::XlaPreparedPrefillLogits fails cargo check --features cuda,xla-iree with E0432 and passes with test-utils. --features cuda,xla-reference-diagnostics --lib --tests checks clean. (Both checks ran in the test-fast profile.)
  • Server smoke, --kv-cache-mode int8, release mlxcel-server: llama-4-scout-17b-16e-instruct-4bit logs applied_layers=12 total_layers=48 stateless_layers=0; gemma-3-1b-it-4bit logs applied_layers=4 total_layers=26.

Not changed: with MLXCEL_XLA_DEVICE=cuda, local_task_gemma3_vlm_prefill_matches_mlx_mask misses its 1e-3 tolerance (up to 5.4e-3) under the default f16 CUDA precision, identically on main; it passes with MLXCEL_XLA_PRECISION=f32.

Closes #2790

KV storage report: `kv_cache_storage_modes` returns `Option<Vec<Option<KVCacheMode>>>`, a `None` entry being a layer with no KV. Families describe layers with `LayerKv` from their cache builder's predicate: Llama 4 chunked layers are FP16 (`uses_chunked_cache` is shared with the builder), linear, conv and skipped layers of the hybrid families are stateless, and model-owned families without a mode table (DeepSeek V4, the recurrent and SSM families, their VLM wrappers) report real storage instead of `None`. The server log adds `kv_cache_mode_stateless_layers`; `logit_trace` prints it.

Sliding window: the nine `RotatingKVCache` families reject a 0 or over-`i32::MAX` window at load when a layer slides, and Gemma 3 rejects `sliding_window_pattern: 0`. Most store the validated `i32` for their builders.

IREE local-task: the C shim builds the device itself with 8 MiB worker stacks instead of the flag-driven factory, whose 128 KiB default cannot hold a CUDA-loaded process's static TLS. `MLXCEL_XLA_LOCAL_TASK_WORKERS` sets the worker count.

`XlaPreparedPrefillLogits` is test support (mlxcel-xla `test-support`, root `test-utils`), resets slots per prefill, and backs `Qwen25VlLanguageDiagnosticEngine`.

Pipeline gate: only a stage timeout or failed send opens it. A `RunEntry` timeout opens it unattributed until a probe names the stage, and a failed send is logged as "could not be reached".

Closes #2790
@inureyes inureyes added status:review Under review type:bug Bug fixes, error corrections, or issue resolutions priority:low Low priority area:models Model architectures, weights, loading, metadata area:core mlxcel-core: MLX FFI, primitives, KV cache, layers area:inference Generation, sampling, decoding (incl. speculative, DRY) labels Oct 31, 2026
Gemma4StageModel::from_filtered_weights builds RotatingKVCache from the same sliding_window cast as the single-process model, but only Gemma4TextModel::from_weights ran the #2790 load-time check, so a zero window on a pipeline stage still reached the cache constructor. The stage load now calls the same cache_window check.

Also restore the layer_types_list doc comment in gpt_oss.rs, which the new validated_sliding_window had captured. Clippy on the lib and tests is clean.

Refs #2790
MLXCEL_XLA_LOCAL_TASK_WORKERS above IREE's IREE_TASK_TOPOLOGY_MAX_GROUP_COUNT (256) was passed through and clamped silently by IREE. parse_local_task_workers now rejects values outside 1..=256 with a load error naming the variable, and docs/environment-variables.md states the range.

When a failed availability probe reopened the pipeline gate, the log line always said the stage did not answer within the teardown acknowledgement timeout, even when the probe could not be sent. probe_failure_cause reads the StageUnreachable cause from the error chain, so a failed send logs its reason and only a timeout keeps the timeout wording. The unit test is a pure error-chain check with no wall-clock bound.

Validation:
- cargo clippy --profile test-fast --features cuda -p mlxcel -p mlxcel-xla --lib --tests -- -D warnings: clean
- cargo test -p mlxcel-xla --lib local_task: 6 passed
- mlxcel lib distributed::pipeline:: under gpu-lock: 416 passed
- cargo fmt --all -- --check, make verify-env-var-docs: clean

Refs #2790
@inureyes inureyes added status:done Completed and removed status:review Under review labels Oct 31, 2026
Bilingual report (English and Korean) for the five LOW residuals of #2787, #2788 and #2789 closed by this PR.
@inureyes
inureyes marked this pull request as ready for review October 31, 2026 11:10
@inureyes
inureyes merged commit 4717d2a into main Oct 31, 2026
33 checks passed
@inureyes
inureyes deleted the fix/issue-2790-low-residuals branch October 31, 2026 11:53
@inureyes inureyes added this to the 0.8 milestone Nov 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers area:inference Generation, sampling, decoding (incl. speculative, DRY) area:models Model architectures, weights, loading, metadata priority:low Low 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: Close the LOW residuals left by #2787, #2788 and #2789

1 participant