Repository navigation
Support PLaMo3 instruction-tuned models with YaRN - #1931
Merged
Merged
Conversation
mitmul
marked this pull request as ready for review
September 29, 2026 06:03
mitmul
force-pushed
the
codex/plamo3-610m-fin-speed
branch
from
September 29, 2026 06:26
cf6dc3b to
beceff8
Compare
Contributor
Author
|
Hi @zcbenz, thank you again for reviewing and merging the original PLaMo 3 support in #1234. |
zcbenz
force-pushed
the
codex/plamo3-610m-fin-speed
branch
from
October 18, 2026 23:21
beceff8 to
7b0242a
Compare
Closed
13 tasks
Merged
5 of 6 tasks
inureyes
pushed a commit
to lablup/mlxcel
that referenced
this pull request
Nov 27, 2026
…uncate (#3444) Gemma 4: a transformers 5.15+ config writes the full-attention shapes as `per_layer_config` instead of `global_head_dim` / `num_global_key_value_heads`. The new `mlxcel_core::gemma4_per_layer::gemma4_global_attention_from_per_layer_config` ports upstream's rules and error texts (Neywa-Labs/mlx-vlm#2719), and `TextConfig::apply_per_layer_config` folds the result into the two global fields at every parse site: `ModelArgs::text_args`, the fallible `ModelArgs::validate_text_config` the text, VLM, Unified, stage and tensor-parallel loaders call right after parsing, DiffusionGemma, the tensor-parallel batching probe and the MTP drafter config. A full-attention layer takes the global KV-head count under `attention_k_eq_v` or a `per_layer_config`. The memory preflight resolves the block through the same function and keeps its previous figure when the block does not resolve. The tensor-parallel runtime restates the block after dividing the KV heads per rank. Qwen 3.5: a `rope_parameters` block whose `type` or `rope_type` is `yarn` builds its table with `rope_utils::yarn_rope_setup` over the rotary dims, with `max_position_embeddings` as the default original context (Neywa-Labs/mlx-vlm#2649). The attention factor follows the transformers rules and multiplies only the rotary lanes of Q and K, on the standard, per-row verify, batched and MRoPE paths. An invalid YaRN block is a load error naming the field. Other users of the Qwen3-Next attention keep the plain rotation. `rope_utils`: `RopeScalingSpec` reads YaRN `truncate` (JSON bool only), and `truncate: false` keeps the correction band's fractional bounds as ml-explore/mlx-lm#1931 does. Without it the table is bit-identical to the previous integer ramp. The module's `Used by:` header now names every caller. Fixes #3215
inureyes
added a commit
to lablup/mlxcel
that referenced
this pull request
Nov 28, 2026
…3513) ## Summary - Adds PLaMo 3 (`plamo3`, `Plamo3ForCausalLM`): a dense sliding/full attention hybrid with packed `qkv_proj` and `gate_up_proj`, q/k offset norms before RoPE, and PLaMo 2's offset RMSNorms (helpers shared from `plamo2.rs`). Wired through detection, `ModelType`, `LoadedModel`, the config-backed loader, `mlxcel arch`, and model-owned state via `sliding_hybrid_lm` (native batched decode, snapshots, last-row logits). - Full-attention layers follow the checkpoint's `modeling_plamo.py`: YaRN (factor 256 over 4096 on the 610m instruct, `truncate: false`, concentration `0.1 ln(factor) + 1`) resolved through `RopeScalingKind::resolve`, so the server's `--rope-scaling none` reproduces mlx-lm's rotation. Sliding layers use plain `rope_local_theta`, a `window_size` ring and mlx-lm's `window_size + 1` prefill mask. - Tokenizer: every `CONTROL` row of `tokenizer.jsonl` becomes a special token (`<|plamo:msg|>` = 19, `<|plamo:tag|>` = 16), and for `Plamo3Tokenizer` only, its boundary splits around `<|plamo:...|>`, repeated-character and space runs are reproduced. PLaMo 2 encodings are unchanged. - `scale_embedding: true`, non-null image fields and non-`normal` `linear_type` are refused by name. `image_proj_type` is not rejected because the public 610m checkpoint ships `"linear"` with every other image field null. - Load-time hardening: every weight, including an untied `lm_head` (checked against `[vocab_size, hidden_size]`), is shape-validated against `config.json`, and the `break_around_*_threshold` values read from `tokenizer_config.json` are capped at 256 (shipped values are 4 and 2), since the repeated-character split pattern is quadratic for large thresholds. The YaRN `truncate` toggle the issue asks for already existed on main (ml-explore/mlx-lm#1931 port); this PR adds the factor 256 / 4096 pin (`yarn_truncate_toggle_on_the_plamo3_geometry`: default equals `truncate=true` bit for bit, `truncate=false` differs). ## Verification (spark-102, GB10, CUDA; Metal not run) - Unit tests (`plamo3`, `rope_utils`, `tokenizer::`, `detection`, coverage suites): pass. Covers pattern 8, the six offsets, q/k norm before RoPE, the YaRN table against the reference formula, the `window + 1` mask, ring wrap, all-full and all-sliding stacks, snapshot, batched decode, last-row logits. PLaMo 2 tokenizer tests pass against `models/plamo-2-1b`. - Revert check: reverting q/k order, one offset, `truncate`, the mask band, CONTROL registration and the pre-tokenizer fails 8 tests. - Tokenizer: 10 strings match `Plamo3Tokenizer` ids exactly, including `<|plamo:msg|>` -> `[19]`. - `mlxcel generate --temp 0`: Japanese (111 tokens) and English (47 tokens) answers are coherent and stop at the turn end. - `mlxcel-server` chat completion: `finish_reason: stop`, "Paris is the capital city of France." - HF reference (transformers 5.24.1, f32 CPU, YaRN on), 256-token teacher-forced stream: top-1 agreement 250/256. - mlx-lm 0.32.2 (CUDA), YaRN off: greedy ids match 59/64 (ja) and 38/64 (en); teacher-forced top-1 agrees 63/64 on both. Not a full 64-token match: each divergence is a one-ULP bf16 tie in mlx-lm's own logits (0.125 apart at ja step 59; at en step 38 mlx-lm's own decode and prefill pick different ids). - Rebuilt at the final head: `mlxcel generate` (Japanese, 111 tokens, stops at turn end) and `mlxcel-server` chat completion (`finish_reason: stop`) re-checked. - clippy (`--lib --tests --features cuda -D warnings`), fmt and the four contract checks pass. Workspace-wide tests not run here. ## Changes during review - Security review: untied `lm_head` shape validation (`a_misshapen_untied_lm_head_is_a_load_error`) and the 256 cap on PLaMo 3 pre-tokenizer thresholds (`oversized_break_thresholds_are_rejected`). ## Open points - Reasoning in `<|plamo:begin_think:plamo|>` markers stays in `content`; no PLaMo reasoning parser yet. - With `skip_special_tokens`, PLaMo 2 now also drops its CONTROL rows (for example `<|plamo:op|>`) on decode; its encodings are unchanged. - mlx-lm's convention (`window + 1` prefill band, `window` decode ring) makes a split prefill on a wrapped ring differ slightly from a one-shot prefill. The HF reference uses `window` throughout. Closes #2374
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.
Requirements
Model information
Supported checkpoints
Tested revision:
a000b59209f1688322c0804009dc9f3fd67e62c1.Verification
Test environment: Apple M1 Max, MLX 0.32.3, Python 3.13.15.
The CLI check used an 8-bit conversion with group size 64. To convert and run:
Output (final answer excerpt; reasoning text omitted):
Reference output (if you have access to CUDA hardware)
No CUDA run was performed. Reference comparisons used PyTorch 2.9.0 on MPS with FP32 weights.
2e-4.These comparisons used unquantized FP32 weights; the 8-bit CLI output above is a separate generation check.
Full-model inference at the maximum 262144-token context length has not been tested.