GLM-4.7-Flash: model card
Browse files
README.md
ADDED
|
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
base_model: zai-org/GLM-4.7-Flash
|
| 4 |
+
tags:
|
| 5 |
+
- coreai
|
| 6 |
+
- aimodel
|
| 7 |
+
- apple-silicon
|
| 8 |
+
- on-device
|
| 9 |
+
- glm
|
| 10 |
+
- mixture-of-experts
|
| 11 |
+
- mla
|
| 12 |
+
pipeline_tag: text-generation
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# GLM-4.7-Flash — Apple Core AI (`.aimodel`)
|
| 16 |
+
|
| 17 |
+
**zai-org's GLM-4.7-Flash converted to Apple's Core AI** (the Core ML successor announced at
|
| 18 |
+
WWDC26), ready to run on macOS 27. This is the **first model on the zoo with Multi-head Latent
|
| 19 |
+
Attention (MLA)** — the DeepSeek-V3 attention family — riding Apple's **`coreai-pipelined` GPU
|
| 20 |
+
engine** with zero custom kernels.
|
| 21 |
+
|
| 22 |
+
> Requires the macOS 27 beta (Core AI ships with the OS). **Mac-only** (~30 GB int8 + a
|
| 23 |
+
> materialized full-MHA KV cache). Conversion code, parity ladder, and the Swift runner:
|
| 24 |
+
> **[coreai-model-zoo](https://github.com/john-rocky/coreai-model-zoo)** (see
|
| 25 |
+
> [`zoo/glm-4.7-flash.md`](https://github.com/john-rocky/coreai-model-zoo/blob/main/zoo/glm-4.7-flash.md)).
|
| 26 |
+
|
| 27 |
+
## Architecture
|
| 28 |
+
|
| 29 |
+
**~30B parameters, ~3B active per token** — **MLA attention on all 47 layers + a sparse MoE FFN**:
|
| 30 |
+
|
| 31 |
+
- **MLA** (heads 20, `q_lora_rank` 768, `kv_lora_rank` 512, `qk_nope` 192 + decoupled `qk_rope`
|
| 32 |
+
64 = head_dim 256, `v_head_dim` 256, RoPE θ=1e6 interleaved), authored in the **naive /
|
| 33 |
+
materialized** form: latent caches are projected up to per-head q/k/v, decoupled RoPE is
|
| 34 |
+
applied to the 64-dim rope slice, and the full per-head `[20, 256]` Q/K/V run through Apple's
|
| 35 |
+
standard SDPA composite. The KV cache stores the materialized per-head K/V.
|
| 36 |
+
- **MoE FFN** (layers 1–46; layer 0 dense, `first_k_dense_replace=1`): 64 routed experts, top-4,
|
| 37 |
+
plus one **non-gated shared expert**. `noaux_tc` routing reduces (n_group=1) to sigmoid scoring
|
| 38 |
+
+ selection-only bias correction; experts ride Apple's `SwitchGLU`/`GatherMM` composite.
|
| 39 |
+
|
| 40 |
+
## Measured (macOS 27 beta, M4 Max 128 GB, release `llm-benchmark`, `COREAI_CHUNK_THRESHOLD=1`)
|
| 41 |
+
|
| 42 |
+
| config | bundle | prefill tok/s | decode tok/s |
|
| 43 |
+
|---|---:|---:|---:|
|
| 44 |
+
| **int8 linear per-block-32 + untied absmax int8 head (`int8hu --head-sym`) = SHIP** | **30 GB** | **20.5** | **20.3** |
|
| 45 |
+
|
| 46 |
+
Decode is context-stable (set by the per-token weight read, not KV growth). **~20 tok/s for a
|
| 47 |
+
30B-class local coder on a Mac** — comfortably above reading speed.
|
| 48 |
+
|
| 49 |
+
## Numerics (gated)
|
| 50 |
+
|
| 51 |
+
- **Parity** (fp16 port vs fp32 HF oracle; 30B is too large for an fp32-resident oracle on
|
| 52 |
+
128 GB): RoPE / isolated MLA block / isolated MoE block all cosine **1.000000**; all 47 layers
|
| 53 |
+
≥0.9995; logits **top-1 16/16**; stateful decode + teacher-forced sweep all match. The
|
| 54 |
+
interleaved decoupled-RoPE convention is verified **bit-exact vs HF**.
|
| 55 |
+
- **int8 end-to-end**: the real `coreai-sequential` engine reproduces the eager-int8 CPU greedy
|
| 56 |
+
continuation **token-for-token** over 32 tokens — a coherent, on-topic continuation. Engine ≡
|
| 57 |
+
python at int8.
|
| 58 |
+
|
| 59 |
+
## Run
|
| 60 |
+
|
| 61 |
+
This is a **decode-only loop-free** bundle for the pipelined engine. Drive it token-by-token with
|
| 62 |
+
the `coreai-sequential` engine variant (the default / `coreai-pipelined` variants feed a prefill
|
| 63 |
+
chunk the static-`[1,1]` graph can't take):
|
| 64 |
+
|
| 65 |
+
```bash
|
| 66 |
+
# tok/s
|
| 67 |
+
COREAI_CHUNK_THRESHOLD=1 llm-benchmark \
|
| 68 |
+
--model gpu-pipelined/glm_4_7_flash_decode_int8hu_block32_sym -p 64 -g 128 -n 3
|
| 69 |
+
# greedy generation
|
| 70 |
+
COREAI_CHUNK_THRESHOLD=1 llm-runner \
|
| 71 |
+
--model gpu-pipelined/glm_4_7_flash_decode_int8hu_block32_sym \
|
| 72 |
+
--inference-engine-variant coreai-sequential --sampling-strategy greedy \
|
| 73 |
+
--prompt "Write a Python function to merge two sorted lists." --max-tokens 128
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
## License
|
| 77 |
+
|
| 78 |
+
GLM-4.7-Flash is released by zai-org under the **MIT License** (see `LICENSE`). The conversion
|
| 79 |
+
code (in [coreai-model-zoo](https://github.com/john-rocky/coreai-model-zoo)) derives from Apple's
|
| 80 |
+
BSD-3-clause `coreai_models`.
|