Skip to content

feat(models): add Arcee AFM-4.5B (arcee) dense support - #3270

Merged
inureyes merged 4 commits into
mainfrom
feature/1719-arcee-afm-4.5b
Nov 22, 2026
Merged

inureyes merged 4 commits into
mainfrom
feature/1719-arcee-afm-4.5b

Conversation

@inureyes

@inureyes inureyes commented Nov 22, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds the dense Arcee family (model_type: arcee, ArceeForCausalLM, arcee-ai/AFM-4.5B). Before this, mlxcel generate exited with Unsupported model type: arcee. This is not AFMoE (afmoe) and not Apple's AFM-7 (afm7).

  • src/models/arcee.rs: the decoder reuses the shared llama3::Attention (fused QKV, GQA, YaRN frequency table and magnitude, cache-owned attention dispatch, split-attention batched decode) and adds only the block and the gate-free MLP, down_proj(relu(up_proj(x))^2) through mlxcel_core::utils::relu_squared. The model implements last_row_logits, native batched decode, batched and maskless padded prefill, and the paged decode backend, as Llama3Model does.
  • ArceeConfig translates config.json (including a transformers 5 rope_parameters block, through the shared lift) into llama3::ModelArgs with a full struct literal. validate() refuses, naming the field: a hidden_act other than relu2, a RoPE type other than default / linear / llama3 / yarn (the shared path would otherwise fall back to the unscaled rotation with only a warning), a linear / llama3 / yarn block without a positive factor, a non-positive beta_fast / beta_slow / original_max_position_embeddings or beta_fast < beta_slow, YaRN truncate: false, a YaRN magnitude that differs from the one transformers' _compute_yarn_parameters derives (for example a declared attention_factor other than the derived one, or a non-unit mscale without mscale_all_dim, which transformers ignores; AFM-4.5B's own mscale: 1.0 gives the same 1.299573 on both sides), a partial_rotary_factor other than 1, a top-level original_max_position_embeddings that differs from the block's, a type / rope_type pair that disagree, and geometry beyond fixed ceilings or not fitting in i32. The RoPE keys outside RopeScaling are captured in ArceeConfig's own Deserialize (on top of the shared rope_parameters lift), so the adapter route screens them as the directory loader does. A gate_proj tensor in an MLP is refused at load.
  • Wired into detection, the config-backed loader (model_metadata.rs), LoadedModel, the registry and mlxcel arch (listed under the Arcee heading next to AFMoE), the memory estimator id, and the tensor-parallel dispatch table, where it is not shardable (the TP runtime would build a SwiGLU Llama MLP).
  • scripts/arcee_oracle_trace.py: the transformers reference arm for examples/logit_trace, reusing the chunk-plan transcription in laguna_oracle_trace.py. It has two negative arms, --arm relu (plain ReLU in every MLP) and --arm no-yarn (rope_parameters reset to the default rotation), plus --dtype bfloat16 and --report-range.
  • relu_squared gains a /// Used by: annotation (Arcee is its sixth caller file); the fused_add_rms_norm, forward_split_attention and RoPE-override rosters name Arcee. docs/supported-models.md, CHANGELOG.md, and an M3 Ultra benchmark row for afm-4.5b (benchmarks/metal_m3ultra_2026-11-23_afm-4.5b.csv).

Parity reference

Hugging Face transformers ArceeForCausalLM (src/transformers/models/arcee/modeling_arcee.py), PyPI transformers 5.24.0 with torch 2.15.0 and tokenizers 0.23.3, run on CPU in float32 (bf16 weights widened, which is exact) via uv run --python 3.12 --with torch --with transformers --with safetensors. The maintainer accepted this reference on 2026-11-23 because neither mlx-lm nor mlx-vlm has arcee. transformers resolves AFM-4.5B's YaRN block to attention scaling 1.299573 (0.1 * ln(20) + 1) and inv_freq[-1] = 5.77391e-06; the shared YaRN path applies the same values, which a unit test pins.

Validation

Real checkpoint models/afm-4.5b (bf16 on disk, run with mlxcel's usual bf16 to f16 load cast), M3 Ultra. The reference's peak squared-ReLU activation is 165 and its peak residual 363 on the short corpus (158 and 330 on the long one), far inside the f16 range. compare_logit_traces.py --decided 2:

Reference arm vs candidate Plan Positions Decided disagreement Logit delta on ref top-1 (p50 / max) Perplexity
transformers f32 vs mlxcel docs/architecture.md 256 8 8 2048 0 / 686 0.0047 / 0.19 39.808 vs 39.824 (+0.04%)
transformers f32 vs mlxcel, positions up to 8192 architecture.md + benchmarks.md 2048 4 8 6144 8192 0 / 2942 0.0044 / 0.17 17.855 vs 17.859 (+0.02%)
transformers f32 vs mlxcel MLXCEL_TRACE_BATCH_ROWS=1 (width-one decode) 256 8 8 2048 0 / 686 0.0044 / 0.25 +0.05%
transformers f32 vs mlxcel MLXCEL_TRACE_BATCH_ROWS=4 256 8 8 2048 0 / 686 0.0045 / 0.25 +0.07%
mlxcel B=1 vs B=4 256 8 8 2048 0 / 688
transformers f32 vs transformers bf16 (context) 256 8 8 2048 0 / 686
negative: transformers --arm relu vs mlxcel 256 8 8 2048 44 / 44 (100%) 3.43 / 12.7 16459 vs 39.8
negative: transformers --arm no-yarn vs mlxcel 256 8 8 2048 11 / 618 (1.8%) 0.58 / 7.3 42.2 vs 39.8
negative: transformers --arm no-yarn vs mlxcel, long 2048 4 8 6144 8192 126 / 1637 (7.7%) 0.84 / 18.8 140.1 vs 17.9

Every disagreement in the positive arms sits where the reference's top-two gap is below 0.5 and lands on the reference's rank 2. The YaRN negative arm also fails on the short plan, because YaRN changes the interpolated low frequencies and the attention magnitude at every position, not only past 4096.

cargo build --release --features metal,accelerate --bin mlxcel --bin mlxcel-server --example logit_trace
uv run --python 3.12 --with torch --with transformers --with safetensors python scripts/arcee_oracle_trace.py models/afm-4.5b docs/architecture.md 256 8 8 [--arm relu|no-yarn] > ref.tsv
./target/release/examples/logit_trace models/afm-4.5b docs/architecture.md 256 8 8 > mlxcel.tsv
python3 scripts/compare_logit_traces.py ref.tsv mlxcel.tsv --decided 2
  • mlxcel generate -m models/afm-4.5b -p "Hello" -n 50 --temp 0: "Hello! It's nice to meet you. How are you doing today?", stopping on <|im_end|> after 15 tokens. "What is the capital of France? Answer in one sentence." gives "The capital of France is Paris." A 200-token paragraph on the printing press is coherent at 60.4 tok/s.
  • Benchmark row (mlxcel generate -p "Hello, how are you today?" -n 128 --profile, the prompt text of the old FAIL:unsupported_arch_arcee_dense row, run by hand through the chat template rather than the sweep's pp512 shape, so prompt_target_len is empty): 195 prompt tokens, prefill 1557 tok/s, decode 63.0 tok/s, 51 tokens before EOS. The failing row in benchmarks/metal_m5max_2026-09-09.csv was measured on an M5 Max, which this host is not, so the new row is a separate M3 Ultra file.
  • mlxcel-server: two concurrent /v1/chat/completions requests (199 and 196 prompt tokens, batched decode at batch 2) finished with stop after 68 tokens ("The sky appears blue because of a phenomenon called Rayleigh scattering...") and length at 120 tokens (a worked 17 x 23 multiplication); a streaming request returned 60 chunks ending in length.
  • Unit tests (models::arcee, 16, plus models::detection_tests::arcee_dense_model_type_is_detected): config translation, the transformers attention-factor resolution and YaRN table, the rope_parameters lift, each refusal, the MLP against hand-computed squared-ReLU values (plain ReLU would give a different vector), the gate_proj refusal, the shared last-row harness and native batched decode against sequential decode. coverage_tests, clippy -D warnings on lib and tests, fmt, and the scripts/ci contract checks pass.

Changes during review

  • Review: the truncate screen moved from parse_config into ArceeConfig's Deserialize so the adapter (LoRA) route refuses it too, and the partial-rotary, top-level original context, type / rope_type conflict, inverted beta and factorless linear / llama3 refusals were added, each with a unit test. The benchmark row's mlxcel_commit now names this PR's first commit.
  • Security review (no CRITICAL or HIGH): the oracle now loads safetensors only (use_safetensors=True), and a top-level original_max_position_embeddings is compared with the context the shared YaRN path would really use, including its max_position_embeddings fallback when the RoPE block omits the key.
  • Bilingual technical report in TECHNICAL_REPORTS/3270-arcee-afm-dense-support-20261123.{en,ko}.md.

Not validated

  • Quantized Arcee exports (none is on this host); the path is the shared UnifiedLinear / FusedQKVLinear loading.
  • Tensor parallelism, which stays refused.
  • The bf16 reference arm was run only as a context check against the float32 reference, not against mlxcel.

Closes #1719

@inureyes inureyes added type:enhancement New features, capabilities, or significant additions priority:medium Medium priority area:models Model architectures, weights, loading, metadata modelsize:small 4-bit checkpoint <= 10GB; fast iteration, safe for smoke tests modeltype:text Text-only language model arch:dense Dense transformer decoder status:review Under review labels Nov 22, 2026
@inureyes

Copy link
Copy Markdown
Member Author

Implementation Review Summary

Intent

Load dense Arcee (arcee, AFM-4.5B) through the shared Llama attention with a gate-free squared-ReLU MLP, with transformers 5.24 parity, wired into CLI, server, mlxcel arch and docs.

Findings Addressed

None needed fixing at CRITICAL or HIGH. The YaRN screening matches transformers 5.24 _compute_yarn_parameters (declared attention_factor wins, the mscale and mscale_all_dim truthiness test, get_mscale returning 1 at factor <= 1, truncate defaulting to true, the original context defaulting to max_position_embeddings), and the shared table and ramp are algebraically the transformers ones. Registration covers every site K2-Horizon and AFMoE use.

Remaining Items

  • truncate: false is not refused on the adapter (LoRA) weight route: parse_model_config deserializes ArceeConfig with serde, so rope_truncate stays None and from_weights cannot see it. Reading truncate inside a custom Deserialize (after the lift) would close it. (MEDIUM)
  • fused_add_rms_norm in mlxcel-core layers.rs gains Arcee as a caller but its /// Used by: line does not name it; check_used_by.py --report lists it as unaccounted (advisory, not gating). (MEDIUM)
  • beta_fast < beta_slow is not refused; transformers' ramp then differs from the shared one. Edge config only. (LOW)
  • Config keys transformers honors that the port ignores without refusing: partial_rotary_factor, a top-level original_max_position_embeddings, and a type / rope_type pair that disagree (mlxcel reads type first, transformers rope_type). No published Arcee checkpoint sets them. (LOW)
  • linear / llama3 blocks with unusable parameters still fall back to the unscaled rotation with a warning instead of a refusal. (LOW)
  • The benchmark row records mlxcel_commit c0bcf575, which predates Arcee support, and has an empty prompt_target_len where the old failing row had 512, so it is not the same pp512 measurement shape. (LOW)

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 (arcee, coverage_tests, detection: 33 passed; clippy -D warnings, fmt and the scripts/ci contract checks clean)

inureyes added a commit that referenced this pull request Nov 22, 2026
Bilingual technical report for the Arcee AFM dense support PR.
@inureyes inureyes added status:done Completed and removed status:review Under review labels Nov 22, 2026
Adds the dense Arcee family (model_type arcee, ArceeForCausalLM). The decoder reuses the shared llama3 attention, including YaRN, and adds a gate-free squared-ReLU MLP. The config translation refuses activations, RoPE types and YaRN settings the shared path would decode differently from transformers.

Parity reference is Hugging Face transformers ArceeForCausalLM 5.24.0 (maintainer decision), scored by the new scripts/arcee_oracle_trace.py with relu and no-yarn negative arms. On AFM-4.5B the teacher-forced trace has no decided-position disagreement over 2048 and 8192 positions.

Closes #1719
Move the YaRN truncate screen into the ArceeConfig Deserialize impl so the adapter route refuses it too, and refuse partial_rotary_factor other than 1, a conflicting top-level original_max_position_embeddings, a type / rope_type conflict, an inverted beta pair and factorless linear or llama3 blocks. Name Arcee in the fused_add_rms_norm, forward_split_attention and RoPE-override rosters, and record the measured commit in the benchmark row.
A top-level original_max_position_embeddings is now compared with the context the shared YaRN path would actually use, including the max_position_embeddings fallback when the RoPE block omits it. The transformers oracle loads safetensors only.
Bilingual technical report for the Arcee AFM dense support PR.
@inureyes
inureyes force-pushed the feature/1719-arcee-afm-4.5b branch from 9fc870b to 156792e Compare November 22, 2026 21:41
@inureyes
inureyes marked this pull request as ready for review November 22, 2026 21:47
@inureyes
inureyes merged commit eeafdfa into main Nov 22, 2026
32 of 33 checks passed
@inureyes
inureyes deleted the feature/1719-arcee-afm-4.5b branch November 22, 2026 21:47
inureyes added a commit that referenced this pull request Nov 22, 2026
The branch was rebuilt on current main (f315dc2) to clear the CHANGELOG.md and docs/supported-models.md conflicts with #3270, #3275 and #3276. This merge records the previously pushed commit 2642118 as a parent so the update is a fast-forward of the remote branch; the tree is the rebuilt branch's, which already carries every change of that commit.

Refs #2354
inureyes added a commit that referenced this pull request Nov 23, 2026
…#3293)

The model library catalog tests used `arcee` as their example of an unsupported dense model. Arcee AFM became a supported family in #3270, so `server::webui::catalog::tests::incomplete_index_and_unsupported_dense_variant_stay_inspectable` fails on main: the entry now resolves an architecture. The embedding contract test in `catalog_contract_tests.rs` used the same model type and kept passing only because its config declares `BertModel`.

Both tests now use the synthetic model type `unported_dense_fixture`, which no detection arm will claim, so a future model port cannot silently change what they cover.

Test-only change. Found by the full serial lib suite on main after the auto-impl run (12583 passed, this one failed); `server::webui::catalog` now passes all 43 tests.
@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

arch:dense Dense transformer decoder area:models Model architectures, weights, loading, metadata modelsize:small 4-bit checkpoint <= 10GB; fast iteration, safe for smoke tests modeltype:text Text-only language model priority:medium Medium priority status:done Completed type:enhancement New features, capabilities, or significant additions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(models): add Arcee AFM-4.5B (arcee, dense ArceeForCausalLM) text model support

1 participant