Repository navigation
feat(models): add Apertus (xIELU, QK-norm, llama3 RoPE scaling) - #260
Merged
Merged
Conversation
Apertus (Swiss AI, model_type `apertus`) is a Llama-style dense transformer with three deltas over the standard block: an xIELU activation MLP with no gate (up_proj/down_proj only), QK-norm on the per-head Q/K, and llama3 RoPE frequency scaling. Embeddings are untied (separate lm_head), with no logit multiplier. Mirrors https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/apertus.py. The xIELU activation carries per-layer learnable scalars alpha_p/alpha_n (stored pre-softplus) plus fixed beta/eps, read to f32 at load time and applied element-wise as where(x > 0, alpha_p*x^2 + beta*x, (expm1(min(x, eps)) - x)*alpha_n + beta*x) over square/expm1/minimum/where_cond ops. The llama3 scaled frequencies reuse the same band computation as exaone4 and feed fast_rope_with_freqs. QK-norm follows qwen3 (RMSNorm after reshape-to-heads, before transpose+RoPE), gated on the qk_norm flag. Per-layer norms are attention_layernorm/feedforward_layernorm with standard residuals; post_norm is parsed but unused. Loads through the standard config-backed route. Registered in detection, model metadata, the loaded-model dispatch, ALL_MODEL_TYPES, the metadata family table, the tensor-parallel architecture fallback, and supported-models docs. Checkpoint-free unit tests cover config parsing and the xIELU/softplus math; end-to-end generation is validated against mlx-community/Apertus-8B-Instruct-2509-4bit.
Two bf16 load bugs surfaced validating Apertus against mlx-community/Apertus-8B-Instruct-2509-4bit, each silently collapsing the forward toward zero rather than crashing. load_text_weights now promotes bf16 quantization scales/biases to f16 for quantized models. Newer mlx-community exports (Apertus-2509, Seed-OSS) ship bf16 quant scales, and mlxcel's dequant path needs f16: bf16 scales dequantize to near-zero and generation emits blank output. f16-scale checkpoints (granite and the rest) are a no-op, so no existing model regresses; the packed uint32 weights and every other tensor are untouched. Apertus read_scalar casts the bf16 act_fn scalars (xIELU alpha_p, alpha_n, beta, eps) to f32 before the item read. A raw item read on a bf16 array misreads the value, which zeroed the xIELU coefficients and vanished the MLP branch. Validated end to end against the real checkpoint: per-layer logit magnitudes match the mlx-lm reference to ~1% and greedy decode reproduces " Paris," exactly (tests/apertus_parity.rs).
This was referenced Jun 13, 2026
inureyes
added a commit
that referenced
this pull request
Jun 15, 2026
…ssion (#289) (#290) #260 added a blanket bf16->f16 promotion of quant scales/biases for all quantized models (convert_quant_scales_bf16_to_f16 in load_text_weights). Promoting only the scales while activations stay bf16 creates a bf16-activation x f16-scale dtype mismatch in quantized_matmul/gather_qmm that regressed decode 33-41% on M1 Ultra for every bf16-scale checkpoint: qwen3-30b-a3b 70->46, nemotron-h 91->53, plus qwen3-0.6b, gpt-oss-120b, solar-100b, minimax, hunyuan-large, jamba, dots. f16-scale checkpoints (mixtral, llama-3.1, qwen2.5, phi-4) were unaffected. Bisected to d80f787 (#260); not the fused-MoE kernel and not the MLX pin. The promotion was unnecessary for correctness. Apertus-2509 and Seed-OSS decode correctly with bf16 scales; the blank output once attributed to their bf16 scales was the separate xIELU read_scalar bf16 bug, fixed in the apertus loader. Promoting every tensor to f16 instead corrupts Apertus (xIELU x^2 overflows f16, like BitNet's relu^2). Leave quantized models fully bf16 (the pre-#260 fast path). On M1 Ultra this restores qwen3-30b-a3b to ~84 and nemotron-h to ~92 tok/s; the apertus_parity real-model test still passes and Seed-OSS / dots.llm1 / granite hybrid / lfm2 decode correctly. Also reflow a doc comment in granitemoehybrid_tests.rs so a wrapped '+' is not at a line start (pre-existing clippy::doc_lazy_continuation under --all-targets; unrelated to the fix, needed for a green lint gate).
sjswerdloff
pushed a commit
to sjswerdloff/mlxcel
that referenced
this pull request
Jul 30, 2026
I read 'get rid of versioning of the cold storage' as the durable byte format's magic/version identifier, and built a priority argument on it: the integrity digest first because a freeze was coming. Alden disagreed, I escalated rather than adjudicated, and Stuart says Alden is right. He meant HOUSEKEEPING - versioning directories, environment variables, and dead v2/v3 code and files - once things stabilise. Never the byte format. The format is not freezing. Magic and version bytes stay, because without an identifier stale bytes parse plausibly instead of failing closed. The digest was still right to do first - it is Alden's P1 and the authority files decide what may be deleted - but that is a DIFFERENT reason than the one I gave, and the one I gave was false. Same shape Cora named on kindled-skills lablup#260 hours earlier: a true statement of effect with a wrong statement of cause. Heading retracted in place rather than deleted; a design doc that silently changes its premise is worse than one that shows the change. Real cleanup targets recorded so the actual direction is not lost behind my misreading. Co-Authored-By: clement-7074f29f <[email protected]>
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
…up#260) * feat(models): add Apertus (xIELU, QK-norm, llama3 RoPE scaling) Apertus (Swiss AI, model_type `apertus`) is a Llama-style dense transformer with three deltas over the standard block: an xIELU activation MLP with no gate (up_proj/down_proj only), QK-norm on the per-head Q/K, and llama3 RoPE frequency scaling. Embeddings are untied (separate lm_head), with no logit multiplier. Mirrors https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/apertus.py. The xIELU activation carries per-layer learnable scalars alpha_p/alpha_n (stored pre-softplus) plus fixed beta/eps, read to f32 at load time and applied element-wise as where(x > 0, alpha_p*x^2 + beta*x, (expm1(min(x, eps)) - x)*alpha_n + beta*x) over square/expm1/minimum/where_cond ops. The llama3 scaled frequencies reuse the same band computation as exaone4 and feed fast_rope_with_freqs. QK-norm follows qwen3 (RMSNorm after reshape-to-heads, before transpose+RoPE), gated on the qk_norm flag. Per-layer norms are attention_layernorm/feedforward_layernorm with standard residuals; post_norm is parsed but unused. Loads through the standard config-backed route. Registered in detection, model metadata, the loaded-model dispatch, ALL_MODEL_TYPES, the metadata family table, the tensor-parallel architecture fallback, and supported-models docs. Checkpoint-free unit tests cover config parsing and the xIELU/softplus math; end-to-end generation is validated against mlx-community/Apertus-8B-Instruct-2509-4bit. * fix(models): correct Apertus loading for bf16-scale checkpoints Two bf16 load bugs surfaced validating Apertus against mlx-community/Apertus-8B-Instruct-2509-4bit, each silently collapsing the forward toward zero rather than crashing. load_text_weights now promotes bf16 quantization scales/biases to f16 for quantized models. Newer mlx-community exports (Apertus-2509, Seed-OSS) ship bf16 quant scales, and mlxcel's dequant path needs f16: bf16 scales dequantize to near-zero and generation emits blank output. f16-scale checkpoints (granite and the rest) are a no-op, so no existing model regresses; the packed uint32 weights and every other tensor are untouched. Apertus read_scalar casts the bf16 act_fn scalars (xIELU alpha_p, alpha_n, beta, eps) to f32 before the item read. A raw item read on a bf16 array misreads the value, which zeroed the xIELU coefficients and vanished the MLP branch. Validated end to end against the real checkpoint: per-layer logit magnitudes match the mlx-lm reference to ~1% and greedy decode reproduces " Paris," exactly (tests/apertus_parity.rs).
be-free-snowboy
pushed a commit
to freestylejs/snowbrain-mlxcel
that referenced
this pull request
Oct 27, 2026
…ssion (lablup#289) (lablup#290) lablup#260 added a blanket bf16->f16 promotion of quant scales/biases for all quantized models (convert_quant_scales_bf16_to_f16 in load_text_weights). Promoting only the scales while activations stay bf16 creates a bf16-activation x f16-scale dtype mismatch in quantized_matmul/gather_qmm that regressed decode 33-41% on M1 Ultra for every bf16-scale checkpoint: qwen3-30b-a3b 70->46, nemotron-h 91->53, plus qwen3-0.6b, gpt-oss-120b, solar-100b, minimax, hunyuan-large, jamba, dots. f16-scale checkpoints (mixtral, llama-3.1, qwen2.5, phi-4) were unaffected. Bisected to d80f787 (lablup#260); not the fused-MoE kernel and not the MLX pin. The promotion was unnecessary for correctness. Apertus-2509 and Seed-OSS decode correctly with bf16 scales; the blank output once attributed to their bf16 scales was the separate xIELU read_scalar bf16 bug, fixed in the apertus loader. Promoting every tensor to f16 instead corrupts Apertus (xIELU x^2 overflows f16, like BitNet's relu^2). Leave quantized models fully bf16 (the pre-lablup#260 fast path). On M1 Ultra this restores qwen3-30b-a3b to ~84 and nemotron-h to ~92 tok/s; the apertus_parity real-model test still passes and Seed-OSS / dots.llm1 / granite hybrid / lfm2 decode correctly. Also reflow a doc comment in granitemoehybrid_tests.rs so a wrapped '+' is not at a line start (pre-existing clippy::doc_lazy_continuation under --all-targets; unrelated to the fix, needed for a green lint gate).
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
Port Apertus (Swiss AI,
apertus), a Llama-style dense transformer, through the standard config-backed loader. Apertus differs from a plain Llama block in three ways: an xIELU activation MLP with no gate, QK-norm on the per-head Q/K, and llama3 RoPE frequency scaling. Embeddings are untied (separatelm_head), with no logit multiplier. Mirrors the upstream reference at https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/apertus.py and the XieLU activation at https://github.com/ml-explore/mlx-lm/blob/main/mlx_lm/models/activations.py.What changed
src/models/apertus.rs(new):ApertusModelwith the config-backedload+from_weights+LanguageModelsurface. xIELU activation built from square/expm1/minimum/where_cond; per-layeralpha_p/alpha_nare read to f32 at load (softplus applied,alpha_noffset bybeta), andbeta/epsdefault to 0.5 / -1e-6 when absent. QK-norm gated onqk_norm(RMSNorm after reshape-to-heads, before transpose + RoPE). llama3 scaled frequencies viafast_rope_with_freqs, computed once and shared per layer (same band formula as exaone4). Norms areattention_layernorm/feedforward_layernormwith standard residuals;post_normis parsed but unused. Untiedlm_head(tied would fall back toembed_tokens.as_linear).src/models/apertus_tests.rs(new): checkpoint-free config-parse tests plus pure-scalar xIELU/softplus math checks.detection.rs("apertus"),model_metadata.rs(config-backed entry),loaded_model.rs(enum variant + dispatch arm),mod.rs(pub mod/pub use,ModelType::Apertus,ALL_MODEL_TYPES, metadata("Apertus (dense)", "Specialized"), test module),distributed/tensor_parallel/inference.rs(architecture fallback), anddocs/supported-models.md.Test plan
cargo check --release --features metal,accelerate --libcargo clippy --release --features metal,accelerate --lib -- -D warningscargo fmt --checkmlx-community/Apertus-8B-Instruct-2509-4bit(real-model gate, run by the maintainer; the implementation environment has no Metal device)Closes #248