mlboydaisuke commited on
Commit
2f8deff
Β·
verified Β·
1 Parent(s): 5d6abab

GLM-4.7-Flash: gather_qmm kernel card (2.6x, clean)

Browse files
Files changed (1) hide show
  1. README.md +32 -60
README.md CHANGED
@@ -1,80 +1,52 @@
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`.
 
1
  ---
2
  license: mit
3
  base_model: zai-org/GLM-4.7-Flash
 
 
 
 
 
 
 
 
4
  pipeline_tag: text-generation
5
+ library_name: core-ai
6
+ tags:
7
+ - core-ai
8
+ - coreml
9
+ - apple
10
+ - moe
11
+ - mla
12
+ - on-device
13
+ - metal
14
  ---
15
 
16
+ # GLM-4.7-Flash β€” Core AI (`gather_qmm` kernel, 2.6Γ— faster)
 
 
 
 
 
 
 
 
 
 
17
 
18
+ Apple **Core AI** (`.aimodel`) conversion of [zai-org/GLM-4.7-Flash](https://huggingface.co/zai-org/GLM-4.7-Flash)
19
+ (text decoder): MLA attention + a **64-expert top-4 sparse MoE** (+ non-gated shared expert).
20
+ ~30B total / **~3B active per token** β€” a strong local coder.
21
 
22
+ Part of the community Core AI model zoo: **https://github.com/john-rocky/coreai-model-zoo**
23
+ (full card: [`zoo/glm-4.7-flash.md`](https://github.com/john-rocky/coreai-model-zoo/blob/main/zoo/glm-4.7-flash.md)).
24
 
25
+ ## The `gather_qmm` kernel β€” 20.3 β†’ 52.4 tok/s (2.6Γ—)
 
 
 
 
 
 
 
26
 
27
+ Apple's `GatherMM` reads **all 64 experts' weights every token**; a custom
28
+ `coreai_torch.TorchMetalKernel` reads **only the 4 routed experts** (4/64) β†’ decode runs at
29
+ active-param bandwidth: **52.4 tok/s, 2.6Γ—** (the biggest relative gain of the zoo's three MoE
30
+ gather ports β€” a 16Γ— over-read removed).
31
 
32
+ **Quality is clean and unchanged.** The kernel reads the **`sym8`** scheme = the same
33
+ symmetric-linear int8 (per-K-block-32) recipe the standard int8 bundle uses, via a **bit-exact**
34
+ gather: **0 introduced flips / 18 vs fp16**. Pure speed win at the same quality.
35
 
36
+ | bundle | size | decode tok/s | quality |
37
+ |---|---:|---:|---|
38
+ | `gpu-pipelined/glm_4_7_flash_decode_sym8_gather/` | 30 GB | **52.4** | clean (0 flips/18 vs fp16) βœ… |
39
 
40
+ Mac-only (30 GB int8). Remaining speed lever = absorbed-MLA (GLM runs full MLA on all 47 layers).
 
 
 
 
 
 
 
 
41
 
42
  ## Run
43
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44
  ```
45
+ COREAI_CHUNK_THRESHOLD=1 llm-benchmark --model gpu-pipelined/glm_4_7_flash_decode_sym8_gather -p 128 -g 256 -n 3
46
+ ```
47
+
48
+ Convert your own with [`conversion/export_glm47_moe_metal_decode_pipelined.py`](https://github.com/john-rocky/coreai-model-zoo/blob/main/conversion/export_glm47_moe_metal_decode_pipelined.py).
49
 
50
  ## License
51
 
52
+ MIT (upstream GLM license). Conversion + `gather_qmm` kernel: community.