Repository navigation
feat(models): add Spark-X2.5 (spark2_5) sliding/full hybrid decoder - #3516
Merged
Merged
Conversation
Member
Author
Implementation Review SummaryIntent
Findings AddressedNone needed. No CRITICAL or HIGH findings. Remaining Items
Verification
Extra checks run during review: making the gate sigmoid run in bf16 fails the gate test ( |
Member
Author
Security and performance reviewNo CRITICAL, HIGH or MEDIUM findings, so no fixes were pushed. Checked:
LOW, not fixed:
|
Spark-X2.5 runs three sliding-window layers to one full-attention layer, and each layer type has its own RoPE (full layers rotate 64 of 256 dims at theta 5e6, sliding layers all 256 at 1e4). q/k/v come from one fused q_k_v_proj, a per-head sigmoid gate computed in f32 scales each head before out_proj, and the MLP uses exact erf GELU. Ported from mlx-lm's spark2_5 package. Sliding layers keep a RotatingKVCache(sliding_window) with window_size = sliding_window masks, full layers a KVCache, both in model-owned state through the shared SlidingHybridModel bodies, so the family gets native batched decode, last-row prefill logits and snapshot reuse. The loader normalizes the mlx-lm, mlx-vlm (language_model.) and model.embed_tokens layouts, drops rotary_emb.inv_freq, and applies upstream's config checks plus projection shape checks. Greedy 64-token output matches mlx_lm on GB10 for both validation checkpoints, including a 1111-token prompt that wraps the 512-token rotating cache. Closes #2372
The Spark-X2.5 entry in docs/supported-models.md opened its parenthesis before the colon and closed it at the end of the description. Neighbouring rows close the parenthesis after the identifiers and put the colon outside, so the row now reads the same way. Validation: cargo fmt --check, clippy --lib --tests --features cuda -D warnings, the four scripts/ci contract checks and 13 models::spark2_5 tests pass. Refs #2372
…er MLX tests Running the spark2_5 test selector with parallel threads on CUDA intermittently aborted the binary in cudaStreamEndCapture, because model_owned_batched_multistep ran without the shared MLX test guard. Take mlx_test_guard there like the other forward-pass tests in the module.
inureyes
force-pushed
the
feature/issue-2372-spark2-5
branch
from
November 28, 2026 16:02
75bab01 to
c745a00
Compare
inureyes
marked this pull request as ready for review
November 28, 2026 16:02
This was referenced Nov 28, 2026
inureyes
added a commit
that referenced
this pull request
Nov 29, 2026
Spark-X2.5 (#3516) gave `ModelType::Spark25` the new family "Spark", which `FAMILY_ORDER` in src/main.rs did not list, so `family_order_is_exhaustive` failed on main. The unit ran narrow test selectors and never built the `mlxcel` bin tests that hold this check; the post-run workspace gate caught it. Add "Spark" after "PLaMo", beside the other sliding/full hybrid text families. `cargo test --features cuda --bin mlxcel family_order` passes.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds Spark-X2.5 (
model_type: spark2_5,Spark2_5ForCausalLM), ported from mlx-lm'sspark2_5package (ml-explore/mlx-lm#1891). It is a dense decoder that runs three sliding-window layers to one full-attention layer, with per-layer-type RoPE, a fused q/k/v projection and a per-head sigmoid attention gate.rope_parametersentry: full layers rotate the first 64 of 256 dims at theta 5e6, sliding layers all 256 at theta 1e4 (non-traditional, absolute cache offset).q_k_v_projis split atq_sizeandq_size + kv_size. Theg_projgate runs its sigmoid in f32, casts back to the output dtype, and scales each head beforeout_proj. The MLP uses erf GELU in the input dtype, reusing Limite'sgelu_erf.RotatingKVCache(sliding_window, keep 0)withwindow_size = sliding_windowmasks (no+ 1, unlike PLaMo 3), and full layers useKVCache. Both live inModelOwnedSequenceStatethrough the sharedSlidingHybridModelbodies and AFMoE'shybrid_prefill_masks, which gives native batched decode, last-row prefill logits and snapshot reuse.model.*), mlx-vlm (language_model.model.*) andmodel.embed_tokenslayouts, dropsrotary_emb.inv_freqand uses a tied head. It applies upstream's config checks (iflayer_typesis absent it defaults to mlx-lm's 3+1 pattern) and refuses projections whose shape disagrees with the config.Verification (GB10,
--features cuda)mlx_lm0.32.2 with mlx-cuda-13 0.32.5, using a raw prompt,mlxcel generate --temp 0 --no-chat-template -n 64:abenzerps/Spark-X2.5-4B-MLX-4bit, 8-token prompt: all 64 tokens match.abenzerps/Spark-X2.5-4B-MLX-4bit, 1111-token prompt (wraps the 512-token window): all 64 tokens match.XHToken/Spark-X2.5-1.7B(bf16), 8-token prompt: all 64 tokens match.XHToken/Spark-X2.5-1.7B(bf16), 1111-token prompt: all 64 tokens match.usage.prompt_tokensfor the short prompt is also 8.mlxcel-serversmoke test on the 4B pack:/v1/completionsreturns the same continuation as the CLI, and/v1/chat/completionsanswers (reasoning output).mlxcel archlists the model andmlxcel arch --jsonincludesspark2_5.spark2_5unit tests pass, including the detection test. The four acceptance tests were checked by reverting the behavior each one covers:1 - sigmoid(12)rounds to 0), when the cast back to the output dtype is dropped, and aborts when the gate is broadcast over the wrong axis.nn.gelu_approx, mlxcelgelu_tanh) and with SiLU. mlxcel's owngelu_approxis erf despite its name, so the test targets the tanh form.cargo clippy --lib --tests --features cuda -- -D warnings,cargo fmt --check, the fourscripts/cicontract checks, and a release build all pass.Not run: Metal (no Apple host), the full workspace test suite (left to CI), and the OptiQ pack.
Closes #2372