Qwen2, Qwen2.5, and Qwen2.5-Coder¶
Overview and status¶
Registry type: qwen2. These families share the dense decoder path: GQA,
RoPE, RMSNorm, biased QKV projections, and gated feed-forward layers. Native
loading, completion, chat, sampling, and streaming are implemented. Qualification
is per checkpoint, precision, operation, and workload.
Checkpoints and evidence¶
Qwen/Qwen2.5-Coder-1.5B-Instruct
at 2e1fd397ee46e1388853d2af2c993145b0f1098a has recorded M4 LoRA-training
and adapter-reload evidence. Its tiny held-out quality gate scored 0.0 → 0.0
and failed; the result is not a quality qualification.
The selected Qwen/Qwen2.5-0.5B-Instruct Q8 profile is supported; see the
current inventory. Additional
1.5B/3B and Coder profiles retain their own evidence in the
catalog. The Coder variant uses the same
architecture, with its own weights and tokenizer/template assets.
Model Architecture¶
The diagram follows the native implementation. Layer counts, widths, head counts, and input sizes come from the checkpoint configuration; this is an architecture map, not an additional support or qualification claim.
Token IDs → token embeddings
↓
┌──────────────────── Decoder block × L ──────────────────────┐
│ RMSNorm → biased Q/K/V → GQA + RoPE + attention KV → add │
│ RMSNorm → gated feed-forward (SwiGLU) → add │
└─────────────────────────────────────────────────────────────┘
↓
Final RMSNorm → LM head → next-token logits
Papers and upstream references¶
Papers: Qwen2 Technical Report, Qwen2.5 Technical Report, and Qwen2.5-Coder Technical Report.
Qwen2.5 and Qwen2.5-Coder share this dense implementation; the diagram does not describe the separate MoE registry type.
Installation and assets¶
From the repository root, install python -m pip install -e . in a Python 3.10+
environment. Execution requires Apple Silicon and Metal. Preserve config.json,
complete safetensors weights/index, tokenizer.json, tokenizer metadata, and the
checkpoint chat template. Quantized checkpoints also need matching MLX
quantization metadata. Base and instruct checkpoints have different prompting needs.
CLI and Python examples¶
The CLI below requests raw completion; an instruct conversation should use the Python chat example. Both are usage examples, not new qualification results.
mlx-one inspect Qwen/Qwen2.5-Coder-1.5B-Instruct \
--revision 2e1fd397ee46e1388853d2af2c993145b0f1098a
mlx-one generate Qwen/Qwen2.5-Coder-1.5B-Instruct "def fibonacci(n):" \
--revision 2e1fd397ee46e1388853d2af2c993145b0f1098a \
--max-tokens 64 --temperature 0 --stream
from mlx_one import TextGenerationOptions, load_text_model, stream_chat
bundle = load_text_model(
"Qwen/Qwen2.5-Coder-1.5B-Instruct",
revision="2e1fd397ee46e1388853d2af2c993145b0f1098a",
)
for chunk in stream_chat(
bundle,
[{"role": "user", "content": "Write a Python function that adds two numbers."}],
options=TextGenerationOptions(max_tokens=64, temperature=0.0),
):
print(chunk.text, end="", flush=True)
The chat layer reads the checkpoint template; its fallback uses ChatML for this registry type. Prefer matching publisher assets over hand-written role markers.
Cache and memory limits¶
Dense KV is the default. Experimental block KV is limited to unquantized, text-only Qwen2/Qwen2.5, batch size one, and f16 KV. An HTTP 200 block smoke result does not prove token parity or shared-prefix execution.
The M4/32 GB report records approximately 28.2 GB peak MLX memory at 16K input for its unquantized Qwen baseline and a clean failure at approximately 32K. Its APC trial produced four misses and zero reused tokens because the published chat-prompt snapshot did not match the desired common prefix. Dense and block APC remain unqualified in that report. These measurements must not be transferred to the 1.5B Coder training run.
Use small initial contexts and consult the cache runtime matrix. Weight quantization does not automatically quantize KV storage. Resolve shape/tokenizer mismatches against the exact checkpoint; do not skip strict weight validation.
Implementation and validation¶
See configuration, model, weights, architecture tests, Metal tests, and Qwen training evidence.
pytest -q tests/test_native_qwen_architectures.py
MLX_ONE_RUN_MLX_TESTS=1 pytest -q tests/test_native_qwen_mlx.py