tacos4me commited on
Commit
513fb85
·
verified ·
1 Parent(s): 4002592

model card (WIP banner), serving patches + SM120 tuned config, conversion/acceptance scripts, LICENSE

Browse files
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Z.AI Co., Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,427 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: mit
3
+ base_model: LibertAIDAI/GLM-5.3-Flash-NVFP4
4
+ base_model_relation: quantized
5
+ quantized_by: tacos4me
6
+ tags:
7
+ - nvfp4
8
+ - fp8
9
+ - blackwell
10
+ - vllm
11
+ - glm
12
+ - glm5_next
13
+ - moe
14
+ - long-context
15
+ - modelopt
16
+ language:
17
+ - en
18
+ - zh
19
+ pipeline_tag: text-generation
20
+ library_name: vllm
21
+ ---
22
+
23
+ > [!WARNING]
24
+ > **⚠️ WIP / preview — weights uploading and final pre-publish checks in flight (2026-08-30).**
25
+ > The serve recipe and patches below are measured-working, the shipped checkpoint carries the
26
+ > parent repo's recalibrated input scales (gated directly — see the provenance note), and
27
+ > independent re-verification (quality re-validation, clean-room patch repro, claims-vs-logs
28
+ > audit) has been folded in. Expect final edits over the next hours.
29
+
30
+ # GLM-5.3-Flash · NVFP4 experts + block-FP8 attention* · 524,288 ctx in VRAM on 2× RTX PRO 6000
31
+
32
+ **524,288-token max-model-len, entirely in VRAM (zero CPU offload) on 2× RTX PRO 6000
33
+ Blackwell Workstation (96 GB each, TP2, PCIe only — no NVLink).** Measured: three consecutive
34
+ real prompts of **503,374 / 503,441 / 503,461 tokens** all completed (prefill 75–87 s;
35
+ re-confirmed on the shipped recalibrated-scales build: 503,374 tokens in 80.4 s), with a
36
+ published teacher-forced quality gate (≥95% top-1 vs the BF16-attention baseline, n=271):
37
+ **95.57%** on the shipped build, 96.68% on the pre-recalibration build. Single-stream decode
38
+ **101.7 tok/s** at short context, no speculative decoding.
39
+
40
+ To our knowledge this is the **first 192 GB setup to reach 512k-class context (524,288) with
41
+ 8-bit (FP8-e4m3) KV cache and a published quality gate**. It is *not* the first zero-offload
42
+ GLM-5.3-Flash on this hardware: [brandonmusic/GLM-5.3-Flash-tr3-4bpw](https://huggingface.co/brandonmusic/GLM-5.3-Flash-tr3-4bpw)
43
+ (2026-08-27) served measured ~498k-token needle retrievals at a 499,968-token ceiling on the
44
+ same 2-GPU setup — using **4-bit NVFP4 KV** in that mode (a mode whose own card reports a
45
+ failed quality gate, 3/10), while its FP8-KV mode caps at 262,144. See
46
+ [Related work](#related-work) for the full field.
47
+
48
+ The trades, up front: the 512k lane is **text-only** (vision tower not loaded), **MTP
49
+ speculative decoding off**, and **single-sequence** (`--max-num-seqs 1`, batched 1024) —
50
+ those three buy the memory that 512k needs; concurrent requests queue. Same checkpoint,
51
+ alternative operating point: **129–146 tok/s** single-stream (content-dependent — MTP
52
+ acceptance varies with content) at **262,144** context with MTP k=1 (clearly a different
53
+ lane — do not mix its numbers with the 512k lane's).
54
+
55
+ \* "FP8 attention" precisely: all attention *projections* are block-FP8 **except**
56
+ `kv_b_proj`, `f_b/g_b`, and the sparse indexer, which stay BF16 — full map below.
57
+
58
+ - **Base:** [zai-org/GLM-5.3-Flash](https://huggingface.co/zai-org/GLM-5.3-Flash) (MIT) — 320B
59
+ total / 18B active MoE, 34 KDA linear-attention layers + 11 DeepSeek-sparse-attention (MLA)
60
+ layers + 1 MTP draft layer, natively multimodal, 1M-token trained context.
61
+ - **Parent:** [LibertAIDAI/GLM-5.3-Flash-NVFP4](https://huggingface.co/LibertAIDAI/GLM-5.3-Flash-NVFP4)
62
+ @ revision `caca4e6a` (head, with the **recalibrated** expert input scales) — the NVFP4
63
+ routed-expert quantization (~97% of parameters) is **their work**, inherited unchanged
64
+ here; everything else BF16; 181.3 GiB.
65
+ - **This checkpoint (173.85 GiB):** the parent, further quantized — attention projections,
66
+ shared/dense MLP, and `lm_head` converted from BF16 to block-FP8 (E4M3 + FP32
67
+ `weight_scale_inv` dequant scales). That is what lets the whole model + 512k-class FP8 KV
68
+ fit in 2×96 GB with zero CPU offload: the BF16-attention parent cannot even *load*
69
+ offload-free on this hardware (OOM during weight loading at any context).
70
+
71
+ Not affiliated with Z.ai / Zhipu or LibertAI.
72
+
73
+ > [!IMPORTANT]
74
+ > **🔒 This checkpoint does NOT load on stock vLLM — and not on the stock GLM-5.3-Flash vendor
75
+ > images either.** `glm5_next` support currently ships in per-model images
76
+ > ([vllm#53906](https://github.com/vllm-project/vllm/pull/53906) is still open), and those
77
+ > images deliberately construct all attention layers *unquantized* (they strip `quant_config`
78
+ > because the official checkpoints keep attention BF16) and cannot load an FP8 `lm_head`.
79
+ > Serving this checkpoint requires the four files in [`serving/`](./serving) — applied on top
80
+ > of the public `cstechdev/vllm:glm53-flash-nope-sm120-cu130-20260826-r1` image (Dockerfile
81
+ > included). Checkpoint and image are a **matched pair**. Without the patches you will get
82
+ > `KeyError` on attention `weight_scale_inv` tensors or a vocab-embedding shape assert.
83
+
84
+ > [!NOTE]
85
+ > **Input-scales provenance (2026-08-30).** The parent's expert `input_scale` tensors went
86
+ > through three upstream revisions in one day: an `input_scale=1.0` placeholder
87
+ > (`357b45cc`), its retraction
88
+ > ([discussion #7](https://huggingface.co/LibertAIDAI/GLM-5.3-Flash-NVFP4/discussions/7) —
89
+ > at 1.0, activation blocks with amax < ~0.1 underflow their fp8 block scale to zero,
90
+ > causing input-dependent intermittent repetition), and a same-day recalibration
91
+ > (`caca4e6a`, calibrated per-projection scales). **This repo pins `caca4e6a` — the
92
+ > recalibrated scales — and gates them directly:** teacher-forced top-1 **95.57%** vs the
93
+ > BF16-attention baseline (gate ≥95), long-generation repetition probes clean at 225k and
94
+ > 259,632-token contexts (2,712-token greedy generations; worst 4-gram repeat 3 and 2 vs
95
+ > fail threshold ≥12), and a 503,374-token round completed in **80.4 s** with **~122.7
96
+ > tok/s** marginal decode. Raw gate dumps: `scripts/results-recal.json`,
97
+ > `scripts/results-longrep-recal.json`, `scripts/results-longrep-prod-topup.json`.
98
+
99
+ ---
100
+
101
+ ## What exactly is quantized
102
+
103
+ Rebuilt from the pristine parent checkpoint by `scripts/convert_fp8attn.py` followed by
104
+ `scripts/convert_lmhead.py` (together they reproduce this checkpoint bit-for-bit —
105
+ determinism experimentally verified), 425 tensors converted BF16 → `F8_E4M3` weight +
106
+ `weight_scale_inv` FP32 block scales, dispatched per-layer through a `MIXED_PRECISION`
107
+ ModelOpt-style manifest in `config.json`:
108
+
109
+ | family | tensors | FP8 block | size before → after | round-trip err vs BF16 |
110
+ |---|---:|---|---|---:|
111
+ | routed experts (incl. MTP draft) | — | **NVFP4** (unchanged — LibertAIDAI's work) | 163.3 GiB | — |
112
+ | KDA q/k/v_proj (34 layers) | 102 | [32,32] | 6.38 → 3.19 GiB | ~2.4% |
113
+ | KDA b/f_a/g_a_proj (34 layers) | 102 | [32,32] | 0.08 → 0.04 GiB | ~2.3% |
114
+ | o_proj, all 46 layers (KDA + MLA + MTP) | 46 | [128,128] | 3.63 → 1.81 GiB | ~2.3% |
115
+ | MLA q_a/kv_a/q_b (12 layers incl. MTP) | 36 | [128,128] | 0.75 → 0.38 GiB | **0.12–0.16%** |
116
+ | shared experts + dense MLP (L0–2) | 138 | [128,128] | 2.86 → 1.43 GiB | **0.16%** |
117
+ | lm_head | 1 | [128,128] | 1.18 → 0.59 GiB | 2.64% |
118
+
119
+ Kept **BF16** on purpose: `kv_b_proj` (absorbed to BF16 by the MLA runtime anyway; FP8 would
120
+ leak error into the decode path for ~0.09 GiB/rank), KDA `f_b/g_b` gate projections (the
121
+ upstream authors are most explicit about delta-rule precision there), the sparse-attention
122
+ indexer, `embed_tokens`, the **entire vision tower** (present and unquantized), norms,
123
+ routers, convs.
124
+
125
+ The MLA q-LoRA family and the MLP family measure at 0.12–0.16% round-trip because the base
126
+ GLM-5.3 model is natively block-FP8 — those BF16 tensors are dequantized copies, and block-128
127
+ re-quantization is a near-bit-level re-derivation. The KDA projections and `o_proj` sit at the
128
+ ~2.3% E4M3 floor: that is a real numerics change on the precision-sensitive KDA delta-rule
129
+ path, which is why the quality gate below was run. We do not call the attention conversion
130
+ lossless or near-lossless — it passes our ≥95% teacher-forced gate; the protocol and n are
131
+ published below and the raw dumps ship in `scripts/`.
132
+
133
+ Why block [32,32] for the KDA in_proj: vLLM fuses q,k,v,b,f_a,g_a into one
134
+ `in_proj_qkvbfg_a` module with a 32-row `b` shard at a non-128-aligned offset, and the
135
+ activation group derives from the block's first dim — the block must be square and divide 32.
136
+
137
+ Integrity: full index↔safetensors-header cross-check over all 121 shards — 150,651 tensors,
138
+ zero mismatches; `total_size` exact (186,674,168,184 bytes = 173.85 GiB of tensors).
139
+
140
+ ## Measured results
141
+
142
+ All numbers below are **measured** on this box (2× RTX PRO 6000 Blackwell Workstation
143
+ Edition, 96 GB each, TP2, PCIe, no NVLink; vLLM `0.1.dev20051+g487ecf187` in the patched
144
+ image). Anything inferred is labeled. Full raw quality dumps: `scripts/results-512k.json`
145
+ (this build), `scripts/results-base.json` (BF16-attention baseline),
146
+ `scripts/results-fp8attn-r2.json` (pre-lm-head/pre-tune intermediate).
147
+
148
+ ### Operating points
149
+
150
+ | | previous prod lane¹ | **512k lane (this card's headline)** | **262k MTP lane** |
151
+ |---|---:|---:|---:|
152
+ | max-model-len | 262,144 | **524,288** | 262,144 |
153
+ | largest measured prompt | — | **503,374 / 503,441 / 503,461 tok (3/3 completed)** | 34k (16.3 s prefill) |
154
+ | CPU offload | 6 GiB/rank experts | **none** | **none** |
155
+ | MTP speculative decode | k=1 | off | k=1 |
156
+ | single-stream decode (short ctx) | 87 tok/s | **101.7 tok/s** | **129–146 tok/s** (content-dependent) |
157
+ | marginal decode @503k ctx | — | ~120–130 tok/s² (~122.7 on the shipped build's gate) | — |
158
+ | ~503k-token prefill | — | 75–87 s (~6.3k tok/s, batched 1024); 80.4 s on the shipped build | — |
159
+ | multimodal | yes | text-only (tower not loaded) | text-only (tower not loaded) |
160
+ | teacher-forced top-1 vs BF16-attn baseline | reference | **95.57%** shipped scales (96.68% pre-recal) | **95.57%** shipped scales (96.68% pre-recal) |
161
+
162
+ ¹ Our previous production configuration: BF16-attention parent checkpoint, CPU-offloaded
163
+ experts, multimodal, MTP k=1 — a **different feature set**, quoted for context, not as an
164
+ apples-to-apples baseline.
165
+ ² Prefix-cached differential (61 tokens over a 1.6 s window on top of a cached 503k
166
+ context) — an estimate of marginal decode rate, not a sustained-throughput measurement.
167
+
168
+ For reference, the BF16-attention parent checkpoint **cannot** operate offload-free on this
169
+ hardware at all: it OOMs during weight loading even at `--max-model-len 32768`
170
+ (~92 GiB/rank of weights alone). Block-FP8 attention is what unlocks offload-free operation.
171
+
172
+ ### Memory (per rank, from vLLM's own ledger)
173
+
174
+ At identical flags to the old offloaded prod config, FP8 attention+MLP moved the KV pool from
175
+ **340,163 → 645,997 tokens (+89.9%)** and max *loadable* context from **315,392 → 524,288**.
176
+ Offload-free at 524,288: weights+non-torch **84.77 GiB/rank** (vs 87.7 baseline — MTP-off
177
+ −2.01, vision-skip −0.53, FP8 lm_head −0.29, each landing to the decimal), KV pool pinned
178
+ 3.95 GiB = **526,825 tokens** at fp8 KV (~7.84 KiB/token/rank).
179
+
180
+ ### The 512k fit ladder (how the final flags were found)
181
+
182
+ | # | attempt | result |
183
+ |---|---|---|
184
+ | A | 524,288, util 0.985, seqs 2, batched 2048, MTP off, mm off, FP8 lm_head | FAIL — avail 3.08 vs 3.92 GiB needed; profile peak grows ~O(max-model-len) (sparse-MLA prefill workspace) |
185
+ | B | util 0.99, warmups off, graphs [1,2] | FAIL — **on this GPU the init free-memory reading is always ~93.89/94.97 GiB (the worker's own CUDA context ≈ 1.05 GiB), so `--gpu-memory-utilization` ≥ 0.989 can never boot.** Use `--kv-cache-memory` instead |
186
+ | B3 | **`--kv-cache-memory` 4.15 GiB pin** (skips profiling + the util gate), util 0.95 as formality | BOOTS + SERVES, pool 552,543 tok |
187
+ | C1 | + tuned kernels image, seqs 2, batched 2048 | quality gate PASSED, 101.7 tok/s — but FAIL at a real 503k prefill: torch OOM from an O(context) sparse-MLA indexer transient (~4+ GiB at 500k) |
188
+ | C2 | **seqs 1, batched 1024, kv pin 3.95 GiB, graphs [1], JIT warmups off** | **ACCEPTANCE PASSED** — 3× consecutive 503,374 / 503,441 / 503,461-token prompts all completed (`finish_reason: stop`, coherent), min-free watermark 290 MiB, 64 recoverable allocator retries, zero hard OOMs, zero request failures |
189
+
190
+ ### Quality gates
191
+
192
+ Protocol: teacher-forced comparison (identical context both sides, `prompt_logprobs`, n=271
193
+ scored positions) plus 10 greedy 50-token generations, against the **unmodified NVFP4 parent
194
+ under the unpatched vendor image** (BF16 attention everywhere). Raw dumps and the scorer
195
+ (`compare.py`) ship in `scripts/` — every number below is reproducible from them.
196
+
197
+ | metric | MLP-only FP8 (r1) | + attention FP8 (r2) | pre-recal build³ | **shipped build (recal scales)⁵** |
198
+ |---|---:|---:|---:|---:|
199
+ | teacher-forced top-1 agreement | 97.4% | 97.05% | 96.68% | **95.57%** (gate: ≥95) |
200
+ | teacher-forced mean \|Δlogprob\| | 0.146 | 0.148 | 0.142 | — (0.142 / 95.94% vs the pre-recal dump) |
201
+ | greedy agreement until first divergence | 94.7% | 90.5% | 60.0% (n=25)⁴ | 90.82% (89/98) |
202
+ | long-generation degeneracy | none (2400 tok) | none (2400 tok) | none (2400 tok) | none — incl. 2,712-tok gens at 225k & 259,632-tok contexts |
203
+
204
+ ³ `scripts/results-512k.json` vs `scripts/results-base.json` under the shipped `compare.py` —
205
+ run it yourself. (An intermediate tuned-kernel lane measured 0.159 / 91.7% at a different
206
+ operating point; the dump's numbers are the ones printed here.)
207
+ ⁴ Greedy chains on a reasoning model diverge at the first flipped token, so
208
+ until-divergence agreement is noisy at small n (25 agreeing positions across 10 prompts at
209
+ this operating point); the teacher-forced row is the signal.
210
+ ⁵ `scripts/results-recal.json` vs `scripts/results-base.json`; repetition probes in
211
+ `scripts/results-longrep-recal.json` (2× ~225k ctx) and
212
+ `scripts/results-longrep-prod-topup.json` (259,632 ctx). The recalibrated input scales cost
213
+ ~1.1 pt of teacher-forced agreement vs the pre-recal build on this metric while fixing the
214
+ upstream-documented fp8-underflow repetition mechanism — see the provenance note up top.
215
+
216
+ The patched image itself is **bitwise neutral** for BF16-attention checkpoints (measured:
217
+ 100.00% teacher-forced agreement, |Δlogprob| = 0.00000 vs the vendor image on the parent
218
+ checkpoint). MTP draft acceptance stays healthy (81% mixed suite / 98.5% on a counting
219
+ bench, r2 measurement). Sanity: `17*23 → 391` correct on every configuration, including
220
+ served at the 524,288 ceiling.
221
+
222
+ ### The honest detour: MLP-only FP8 was a net LOSS
223
+
224
+ The first conversion round (shared+dense MLP only, −0.71 GiB/rank of weights) measured
225
+ **negative**: KV pool 330,800 vs 340,163 baseline (−2.8%), max context 301,056 vs 315,392
226
+ (−4.5%). vLLM permanently reserves the profiled activation peak, and activating the FP8
227
+ block-GEMM path costs a fixed **+0.80 GiB/rank** in that profile — independent of how many
228
+ layers are FP8. It outspent the saving. Only when attention (+2.81 GiB/rank) joined did the
229
+ fixed cost amortize 4:1. If you are building a partial-FP8 derivative: go all-in or don't
230
+ bother.
231
+
232
+ ### The kernel story (why the tuned config JSON ships in `serving/`)
233
+
234
+ vLLM has **zero** tuned `w8a8` block-FP8 triton configs for SM120 in-tree (219 configs, none
235
+ for this device name). The KDA fused in_proj (N=12576, K=4096, block [32,32]) therefore ran a
236
+ default config at **313 µs/call — 43.8% of all decode GPU time** (torch-profiler measured).
237
+ One autotuned JSON (`serving/configs/…block_shape=[32,32].json`, benched at 22.3 µs at M=1)
238
+ plus dropping CPU offload took the same checkpoint from 66 → 142 tok/s at 114k ctx (and
239
+ 66 → 91.5 tok/s with offload kept). The tuned tiles keep the default's `BLOCK_SIZE_K=32`
240
+ k-split, so the reduction order — and the numerics — are unchanged. The block-128 GEMMs run
241
+ vendored DeepGEMM SM120 kernels at ~1.35 TB/s effective and were left alone.
242
+
243
+ ## Serving
244
+
245
+ ### 1. Build the patched image
246
+
247
+ ```bash
248
+ docker build -t local/vllm-glm53:fp8attn-512k serving/
249
+ ```
250
+
251
+ `serving/` = the public `cstechdev/vllm:glm53-flash-nope-sm120-cu130-20260826-r1` image
252
+ (the [chriswritescode-dev/glm-5.3-flash-sm120](https://github.com/chriswritescode-dev/glm-5.3-flash-sm120)
253
+ overlay of the official per-model vLLM image — our image lineage) plus exactly four files
254
+ (see [`serving/README.md`](./serving/README.md) for the per-file breakdown):
255
+
256
+ 1. `kda.py` — remove the `quant_config` save/None/restore strip around KDA layer construction;
257
+ 2. `model.py` — `Glm5NextDecoderLayer`: pass the real `quant_config` instead of `None` to MLA
258
+ attention (covers the 11 MLA layers + the MTP draft layer);
259
+ 3. `modelopt.py` — `ModelOptMixedPrecisionConfig`: `FP8_BLOCK128/64/32` dispatch, fused-module
260
+ name resolution, MTP draft-prefix aliases, and a `ParallelLMHead` method whose
261
+ `weight_scale_inv` loader shards scale rows by vocab shard (the FP8 lm_head loader);
262
+ 4. `configs/*.json` — the SM120-tuned triton config above.
263
+
264
+ These files are Apache-2.0 vLLM-tree files (SPDX headers retained), credit to the vLLM
265
+ project and the per-model image authors; the base image is pulled from Docker Hub, not
266
+ redistributed here. **Parallel-work credit:**
267
+ [local-inference-lab](https://github.com/local-inference-lab/vllm) independently landed the
268
+ equivalent MLA quant-config passthrough in their public vLLM fork
269
+ ([`dev/jovian-judgement@8590bf9c`](https://github.com/local-inference-lab/vllm/commit/8590bf9c),
270
+ 2026-08-29 — about half a day before our acceptance run), paired with MXFP8 attention via
271
+ the b12x SM120 kernels; our patch does the same for the official per-model-image code path
272
+ and adds the block-[32,32] FP8 dispatch for the fused KDA in_proj plus the FP8 lm_head
273
+ loader.
274
+
275
+ ### 2. Run — 512k operating point (as measured in acceptance)
276
+
277
+ ```bash
278
+ docker run --init --rm --gpus all --runtime nvidia --ipc=host --network host \
279
+ --shm-size=32g --ulimit memlock=-1 --ulimit stack=67108864 \
280
+ -e VLLM_ENGINE_READY_TIMEOUT_S=3600 \
281
+ -v /path/to/GLM-5.3-Flash-NVFP4-FP8ATTN-512K:/model:ro \
282
+ local/vllm-glm53:fp8attn-512k /model \
283
+ --served-model-name glm-5.3-flash \
284
+ --host 0.0.0.0 --port 8000 \
285
+ --tensor-parallel-size 2 \
286
+ --max-model-len 524288 \
287
+ --gpu-memory-utilization 0.95 \
288
+ --kv-cache-memory 4241026048 \
289
+ --kv-cache-dtype fp8 \
290
+ --max-num-seqs 1 \
291
+ --max-num-batched-tokens 1024 \
292
+ --limit-mm-per-prompt '{"image":0,"video":0}' \
293
+ --kernel-config '{"enable_jit_warmup":false,"enable_cutedsl_warmup":false}' \
294
+ --compilation-config '{"cudagraph_capture_sizes":[1]}' \
295
+ --enable-prefix-caching \
296
+ --no-enable-flashinfer-autotune \
297
+ --enable-auto-tool-choice --tool-call-parser glm47 --reasoning-parser glm45 \
298
+ --trust-remote-code
299
+ ```
300
+
301
+ Every flag is load-bearing:
302
+
303
+ - **`--kv-cache-memory 4241026048` (3.95 GiB/rank, pinned)** — the load-bearing trick, and a
304
+ disclosed trade: the pin **bypasses vLLM's memory-profiling gate**. Background: on this
305
+ GPU the boot-time free-memory reading is always ~93.89 of 94.97 GiB (the worker's own CUDA
306
+ context ≈ 1.05 GiB is counted as used), so `--gpu-memory-utilization` ≥ 0.989 can **never
307
+ boot** — the util gate compares against a number that includes your own overhead. The
308
+ explicit pin skips profiling *and* the util gate; `0.95` remains only as a formality.
309
+ Pool at this pin: 526,825 tokens. The headroom was then proven by the 3×503k soak, not by
310
+ a profiler.
311
+ - **`--max-num-seqs 1 --max-num-batched-tokens 1024`** — the sparse-MLA prefill carries an
312
+ O(context) transient (~4+ GiB at 500k context, growing 306→517 MiB allocations in the
313
+ indexer scoring path). seqs 2 / batched 2048 boots and passes short-context quality but
314
+ **dies with a torch OOM at a real 503k prefill** (ladder row C1). Single-sequence is the
315
+ 512k use case; concurrent requests queue.
316
+ - **`--limit-mm-per-prompt '{"image":0,"video":0}'`** — builds the vision tower as a missing
317
+ stage (never allocated, weights skipped): −0.53 GiB/rank. This lane is **text-only**.
318
+ - **No `--speculative-config`** — MTP off frees ~2.0 GiB/rank (draft layer); required to fit 512k.
319
+ - **JIT warmups off, cudagraph sizes [1]** — trims the profile/graph reservations that the
320
+ 512k fit needs back.
321
+
322
+ Margin disclosure: the min-free VRAM watermark during a 503k prefill is **~290 MiB**, with
323
+ recoverable PyTorch allocator retries by design (64 across the 3-prompt soak, zero request
324
+ failures). **Do not co-locate other GPU tenants while a long prefill is in flight** — under
325
+ external VRAM perturbation this configuration will OOM.
326
+
327
+ ### 2b. Run — 262k MTP speed lane (129–146 tok/s)
328
+
329
+ Same command, changed flags: `--max-model-len 262144 --kv-cache-memory 3113851289
330
+ --max-num-seqs 2` (drop `--compilation-config`), add
331
+ `--speculative-config '{"method":"mtp","num_speculative_tokens":1}'`.
332
+ Measured: pool 327,680 tokens (1.25× at 262k), single-stream decode **129–146 tok/s**
333
+ depending on content (MTP acceptance varies with the text being generated; 146.4 was our
334
+ original bench, independent re-measurement across mixed prompts spans the range), 34k-token
335
+ prompt prefill in 16.3 s.
336
+
337
+ ## Related work
338
+
339
+ The 192 GB long-context field is moving fast; credit where due, and plain statements about
340
+ what is and is not first here. (Corrections welcome — open a discussion.)
341
+
342
+ - **[brandonmusic/GLM-5.3-Flash-tr3-4bpw](https://huggingface.co/brandonmusic/GLM-5.3-Flash-tr3-4bpw)**
343
+ (2026-08-27) — EXL3-K4 experts on the same 2× RTX PRO 6000, TP2, **zero offload, before
344
+ us**, with MTP3 active and strong short-ctx decode (145–151 tok/s at 0–64k). Its
345
+ `long500k` profile reaches a 499,968-token ceiling with measured needle retrievals from
346
+ ~498k-token prompts (17/18 through 499K) — using **4-bit NVFP4 KV** in that mode, which
347
+ its own card reports failing its quality gate (LAVD 3/10); its 8-bit FP8-KV mode is
348
+ capped at 262,144. Respect: they were first to zero-offload long context on this
349
+ hardware. The delta this repo adds is 524,288 **with FP8 KV** and a passing published
350
+ quality gate. (Their repo is `license: other` — cited, nothing reused.)
351
+ - **[local-inference-lab/GLM-5.3-Flash-NVFP4-4p67](https://huggingface.co/local-inference-lab/GLM-5.3-Flash-NVFP4-4p67)**
352
+ (2026-08-27) — calibrated NVFP4 experts (better-calibrated input scales than our parent's
353
+ revision) + **MXFP8 attention & shared experts**, KLD ~0.04 published, explicitly targeted
354
+ at 2× RTX 6000. Their public vLLM fork has had a TP2 offload-free launcher since
355
+ 2026-08-29 (`8590bf9c`), including the same MLA quant-config passthrough we ship (see
356
+ Serving §1 credit). MXFP8-on-SM120 is code-complete and kernel-proven in their stack; no
357
+ published end-to-end TP2 context/throughput/eval measurements yet ("Evals to follow").
358
+ - **[local-inference-lab/vllm PR #522](https://github.com/local-inference-lab/vllm/pull/522)**
359
+ (2026-08-30) — **4× RTX PRO 6000 (384 GB, not 192 GB)**: 1,048,576-token qualified,
360
+ benchmark rows at 512k (66.0/122.7 tok/s), ~200k-token retrieval passed. Bigger iron,
361
+ bigger numbers, already public.
362
+ - **[3× DGX Spark, TP=3](https://forums.developer.nvidia.com/t/glm-5-3-flash-nvfp4-on-3x-dgx-spark-tp-3-512k-context-35-tok-s/381534)** —
363
+ 512K context at 35 tok/s on 384 GB unified memory (SM121; not 192 GB, different hardware
364
+ class).
365
+ - **[Infatoshi/GLM-5.3-Flash-NVFP4-FP8](https://huggingface.co/Infatoshi/GLM-5.3-Flash-NVFP4-FP8)**
366
+ (2026-08-29) — NVFP4+FP8 variant calibrated on 4× B200; vLLM explicitly not validated by
367
+ its card; 1k-context diagnostic only.
368
+
369
+ **What this repo claims, precisely:** the first published 192 GB (2×96 GB) configuration
370
+ reaching 524,288 max-model-len with 8-bit (FP8) KV cache *and* a published quality gate,
371
+ with measured ≥503k-token prompts served and the exact recipe + raw evidence included.
372
+ Nothing more. If you know of prior art that contests this, open a discussion and this
373
+ section will be corrected.
374
+
375
+ ## Repo layout
376
+
377
+ ```
378
+ ├─ model-000{01..120}-of-00120.safetensors # 173.9 GiB total: NVFP4 + block-FP8 + BF16
379
+ ├─ model.safetensors.index.json
380
+ ├─ model-input-scales.safetensors # recalibrated scales from parent @caca4e6a — see provenance note
381
+ ├─ config.json # MIXED_PRECISION manifest (38k+ per-layer entries)
382
+ ├─ tokenizer.json / tokenizer_config.json / chat_template.jinja / generation_config.json
383
+ ├─ serving/ # the matched-pair runtime (Apache-2.0, vLLM-derived)
384
+ │ ├─ Dockerfile ├─ kda.py ├─ model.py ├─ modelopt.py └─ configs/*.json
385
+ └─ scripts/ # provenance + evidence (documents our exact env)
386
+ ├─ convert_fp8attn.py # parent → attention/MLP FP8 (CPU-only, deterministic)
387
+ ├─ convert_lmhead.py # + lm_head FP8, in place (reversible, --revert)
388
+ ├─ accept-512k.sh / longctx.py # the 512k acceptance harness (3× ~503k prompts)
389
+ ├─ boot-512k-fit.sh / validate.py / bench_decode.py # harness deps (boot, quality dump, decode bench)
390
+ ├─ compare.py # teacher-forced / greedy A/B scorer
391
+ └─ results-512k.json / results-base.json / results-fp8attn-r2.json # raw dumps behind every quality number
392
+ ```
393
+
394
+ ## Provenance, license, attribution
395
+
396
+ - Weights: **MIT**, © 2026 Z.AI Co., Ltd (LICENSE carried verbatim). Chain:
397
+ [zai-org/GLM-5.3-Flash](https://huggingface.co/zai-org/GLM-5.3-Flash) →
398
+ [LibertAIDAI/GLM-5.3-Flash-NVFP4](https://huggingface.co/LibertAIDAI/GLM-5.3-Flash-NVFP4)
399
+ (revision `caca4e6a`, the recalibrated-input-scales head — NVFP4 expert quantization and
400
+ input scales are LibertAI's work) →
401
+ this repo (block-FP8 attention/MLP/lm_head conversion). Not affiliated with Z.ai / Zhipu
402
+ or LibertAI.
403
+ - `serving/*.py`: Apache-2.0, derived from the vLLM project (SPDX headers retained), via the
404
+ official per-model image as packaged by
405
+ [chriswritescode-dev/glm-5.3-flash-sm120](https://github.com/chriswritescode-dev/glm-5.3-flash-sm120);
406
+ parallel-work credit to local-inference-lab per Serving §1.
407
+ - Conversion was CPU-only, deterministic, calibration-free (block-wise amax/448 scaling);
408
+ `scripts/convert_fp8attn.py` **+ `scripts/convert_lmhead.py`** reproduce this checkpoint
409
+ bit-for-bit from the parent (determinism experimentally verified during audit).
410
+
411
+ ## Known limitations
412
+
413
+ - **Matched pair:** loads only under the `serving/` patched image. Stock vLLM has no
414
+ `glm5_next`; vendor images assert/KeyError on this checkpoint.
415
+ - **Input-scales history:** the parent's scales were revised twice on release week (see the
416
+ provenance note up top); this repo ships the recalibrated `caca4e6a` scales, gated directly.
417
+ - **Text-only as served:** both measured operating points skip the vision tower. The tower
418
+ weights are present and byte-identical to the parent, and the patched image leaves the
419
+ tower unquantized, but multimodal serving of this checkpoint is **untested**
420
+ (inferred-safe, not measured).
421
+ - Single-stream orientation at 512k (`--max-num-seqs 1`); throughput under concurrency was
422
+ not the target and is unmeasured beyond a 4-way probe at smaller contexts.
423
+ - ~290 MiB VRAM margin during a full 512k prefill — no other GPU tenants.
424
+ - SM120 (RTX PRO 6000 Blackwell) is the only measured platform. The quant format itself is
425
+ hardware-agnostic block-FP8/NVFP4, but the kernel selection and the tuned config are
426
+ SM120.
427
+ - Scripts in `scripts/` document our exact environment; paths and flags may need adaptation.
scripts/accept-512k.sh ADDED
@@ -0,0 +1,68 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Full acceptance under one gpu-lock window. Boots the candidate config,
3
+ # runs: 391 check, validate.py (quality dump), compare vs r2 + base,
4
+ # short-ctx decode bench, 3x >=500k-token rounds (longctx.py), teardown.
5
+ # Usage: accept-512k.sh [MAXLEN] [IMAGE] [EXTRA vllm args...] (env: SEQS BATCHED UTIL MM)
6
+ set -u
7
+ D="$(cd "$(dirname "$0")" && pwd)"
8
+ LOG=/tmp/glm-512k-accept.log
9
+ MODEL=glm-5.3-flash-fp8attn
10
+ PORT=18996
11
+
12
+ docker rm -f glm-512k-fit >/dev/null 2>&1
13
+ # teardown race guard: another worker's dying container may still hold VRAM
14
+ # for a few seconds after the lock frees; wait for both cards to drain.
15
+ for i in $(seq 1 60); do
16
+ MAXUSED=$(nvidia-smi --query-gpu=memory.used --format=csv,noheader,nounits | sort -n | tail -1)
17
+ [ "$MAXUSED" -lt 200 ] && break
18
+ sleep 3
19
+ done
20
+ echo "GPU drain: max used ${MAXUSED} MiB before boot"
21
+ setsid "$D/boot-512k-fit.sh" "$@" >"$LOG" 2>&1 &
22
+ BOOT=$!
23
+ READY=0
24
+ for i in $(seq 1 240); do
25
+ sleep 5
26
+ if curl -sf -m 2 http://127.0.0.1:$PORT/health >/dev/null 2>&1; then READY=1; break; fi
27
+ kill -0 "$BOOT" 2>/dev/null || break
28
+ done
29
+ echo "=== LEDGER ==="
30
+ grep -aiE "consumed|non-torch|activation|KV cache size|kv cache memory|Maximum concurrency|graph|needs|available|ERROR|OOM" "$LOG" | tail -25
31
+ if [ "$READY" != "1" ]; then echo "BOOT FAILED"; docker stop glm-512k-fit >/dev/null 2>&1; exit 2; fi
32
+
33
+ # VRAM watermark sampler (min free MiB seen during the run)
34
+ ( MINFREE=999999; while docker ps --format '{{.Names}}' | grep -q glm-512k-fit; do
35
+ F=$(nvidia-smi --query-gpu=memory.free --format=csv,noheader,nounits | sort -n | head -1)
36
+ [ -n "$F" ] && [ "$F" -lt "$MINFREE" ] && MINFREE=$F && echo "$MINFREE" > /tmp/glm-512k-minfree
37
+ sleep 4
38
+ done ) &
39
+ WATCH=$!
40
+
41
+ echo "=== 391 ==="
42
+ curl -s -m 300 http://127.0.0.1:$PORT/v1/chat/completions -H 'Content-Type: application/json' \
43
+ -d "{\"model\":\"$MODEL\",\"messages\":[{\"role\":\"user\",\"content\":\"What is 17*23? Reply with just the number.\"}],\"max_tokens\":200,\"temperature\":0}" \
44
+ | python3 -c 'import json,sys; r=json.load(sys.stdin); m=r["choices"][0]["message"]; print((m.get("content") or "")[:100], "| reasoning:", (m.get("reasoning_content") or "")[-80:])'
45
+
46
+ echo "=== validate.py ==="
47
+ python3 "$D/validate.py" $PORT $MODEL "$D/results-512k.json" || echo "validate FAILED"
48
+
49
+ echo "=== compare vs r2 ==="
50
+ python3 "$D/compare.py" "$D/results-fp8attn-r2.json" "$D/results-512k.json" || true
51
+ echo "=== compare vs base ==="
52
+ python3 "$D/compare.py" "$D/results-base.json" "$D/results-512k.json" || true
53
+
54
+ echo "=== decode short-ctx ==="
55
+ python3 "$D/bench_decode.py" $PORT $MODEL 512 || true
56
+
57
+ echo "=== longctx 3 rounds ==="
58
+ python3 "$D/longctx.py" $PORT $MODEL 3 505000
59
+ LC=$?
60
+
61
+ echo "=== post-run VRAM ==="
62
+ nvidia-smi --query-gpu=index,memory.used --format=csv,noheader
63
+ kill "$WATCH" 2>/dev/null
64
+ echo "=== min free watermark (MiB): $(cat /tmp/glm-512k-minfree 2>/dev/null || echo n/a) ==="
65
+
66
+ if [ "${KEEP:-0}" != "1" ]; then docker stop glm-512k-fit >/dev/null 2>&1; wait "$BOOT" 2>/dev/null; fi
67
+ echo "=== ACCEPT EXIT: longctx=$LC ==="
68
+ exit $LC
scripts/bench_decode.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Single-stream decode throughput. Usage: bench_decode.py <port> <model> [n_tokens]"""
2
+ import json
3
+ import sys
4
+ import time
5
+ import urllib.request
6
+
7
+ PORT, MODEL = int(sys.argv[1]), sys.argv[2]
8
+ N = int(sys.argv[3]) if len(sys.argv) > 3 else 512
9
+
10
+ payload = {
11
+ "model": MODEL,
12
+ "messages": [
13
+ {
14
+ "role": "user",
15
+ "content": "Count from 1 to 300 in words, one number per line (one, two, three, ...).",
16
+ }
17
+ ],
18
+ "temperature": 0,
19
+ "max_tokens": N,
20
+ "ignore_eos": True,
21
+ }
22
+ req = urllib.request.Request(
23
+ f"http://127.0.0.1:{PORT}/v1/chat/completions",
24
+ data=json.dumps(payload).encode(),
25
+ headers={"Content-Type": "application/json"},
26
+ )
27
+ # warmup (also primes prefix cache off: different prompt)
28
+ warm = dict(payload, max_tokens=32)
29
+ urllib.request.urlopen(
30
+ urllib.request.Request(req.full_url, data=json.dumps(warm).encode(), headers=req.headers),
31
+ timeout=600,
32
+ ).read()
33
+ t0 = time.time()
34
+ r = json.loads(urllib.request.urlopen(req, timeout=600).read())
35
+ dt = time.time() - t0
36
+ ct = r["usage"]["completion_tokens"]
37
+ print(f"{ct} completion tokens in {dt:.2f}s = {ct / dt:.1f} tok/s (single stream, MTP on)")
scripts/boot-512k-fit.sh ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Offload-free 512k lane boot. Container glm-512k-fit, port 18996.
3
+ # Usage: boot-512k-fit.sh [MAXLEN] [IMAGE] [EXTRA vllm args...]
4
+ # Env knobs: MODEL_DIR (checkpoint path), CACHE_DIR (vllm cache),
5
+ # SEQS (2), BATCHED (2048), UTIL (0.98), MM ("0" -> tower skipped)
6
+ MODEL_DIR="${MODEL_DIR:-$PWD/GLM-5.3-Flash-NVFP4-FP8ATTN-512K}"
7
+ CACHE_DIR="${CACHE_DIR:-$HOME/.cache/vllm-glm53}"
8
+ set -e
9
+ MAXLEN="${1:-524288}"
10
+ IMAGE="${2:-local/vllm-glm53:fp8attn-r4}"
11
+ shift 2 2>/dev/null || shift $# 2>/dev/null || true
12
+ MM_ARGS=()
13
+ if [ "${MM:-0}" = "0" ]; then
14
+ MM_ARGS=(--limit-mm-per-prompt '{"image":0,"video":0}')
15
+ fi
16
+ SPEC_ARGS=(--speculative-config '{"method":"mtp","num_speculative_tokens":1}')
17
+ if [ "${SPEC:-1}" = "0" ]; then
18
+ SPEC_ARGS=()
19
+ fi
20
+ exec docker run --name glm-512k-fit --init --rm \
21
+ --gpus all \
22
+ --runtime nvidia \
23
+ --ipc=host \
24
+ --network host \
25
+ --shm-size=32g \
26
+ --ulimit memlock=-1 \
27
+ --ulimit stack=67108864 \
28
+ -e VLLM_ENGINE_READY_TIMEOUT_S=3600 \
29
+ -e HF_HUB_OFFLINE=1 \
30
+ -e VLLM_MEMORY_PROFILER_ESTIMATE_CUDAGRAPHS="${ESTG:-1}" \
31
+ -v "$MODEL_DIR":/model:ro \
32
+ -v "$CACHE_DIR":/root/.cache \
33
+ "$IMAGE" \
34
+ /model \
35
+ --served-model-name glm-5.3-flash-fp8attn \
36
+ --host 0.0.0.0 \
37
+ --port 18996 \
38
+ --tensor-parallel-size 2 \
39
+ --max-model-len "$MAXLEN" \
40
+ --gpu-memory-utilization "${UTIL:-0.98}" \
41
+ --kv-cache-dtype fp8 \
42
+ --max-num-seqs "${SEQS:-2}" \
43
+ --max-num-batched-tokens "${BATCHED:-2048}" \
44
+ --enable-prefix-caching \
45
+ --no-enable-flashinfer-autotune \
46
+ --enable-auto-tool-choice \
47
+ --tool-call-parser glm47 \
48
+ --reasoning-parser glm45 \
49
+ --trust-remote-code \
50
+ "${SPEC_ARGS[@]}" \
51
+ "${MM_ARGS[@]}" \
52
+ "$@"
scripts/compare.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Compare two validate.py result dumps (baseline vs converted).
2
+
3
+ Usage: python3 compare.py baseline.json converted.json
4
+ """
5
+
6
+ import json
7
+ import sys
8
+
9
+ a = json.load(open(sys.argv[1]))
10
+ b = json.load(open(sys.argv[2]))
11
+
12
+ print(f"baseline={a['model']} converted={b['model']}")
13
+ print(f"arith 17*23: base={a['arith_correct']} conv={b['arith_correct']}")
14
+ print(
15
+ f"long gen: base {a['long_gen_tokens']} tok degenerate={a['long_gen_degenerate']} | "
16
+ f"conv {b['long_gen_tokens']} tok degenerate={b['long_gen_degenerate']}"
17
+ )
18
+
19
+ # greedy 50-token comparison: positionwise top-1 agreement until first
20
+ # divergence (after divergence contexts differ), plus |dlogprob| on agreeing
21
+ # positions.
22
+ tot_pos = agree = 0
23
+ dl = []
24
+ full_match = 0
25
+ for ga, gb in zip(a["greedy"], b["greedy"]):
26
+ ta, tb = ga["tokens"], gb["tokens"]
27
+ la, lb = ga["token_logprobs"], gb["token_logprobs"]
28
+ n = min(len(ta), len(tb))
29
+ diverged = False
30
+ prompt_match = 0
31
+ for i in range(n):
32
+ if diverged:
33
+ break
34
+ tot_pos += 1
35
+ if ta[i] == tb[i]:
36
+ agree += 1
37
+ prompt_match += 1
38
+ if la[i] is not None and lb[i] is not None:
39
+ dl.append(abs(la[i] - lb[i]))
40
+ else:
41
+ diverged = True
42
+ if not diverged and len(ta) == len(tb):
43
+ full_match += 1
44
+ print(
45
+ f"greedy: {full_match}/{len(a['greedy'])} prompts identical for all 50 tok; "
46
+ f"agreement until divergence {agree}/{tot_pos} = {100 * agree / max(tot_pos, 1):.2f}%"
47
+ )
48
+ if dl:
49
+ print(
50
+ f"greedy |dlogprob| on agreeing tokens: mean {sum(dl) / len(dl):.5f} "
51
+ f"max {max(dl):.5f} (n={len(dl)})"
52
+ )
53
+
54
+ # teacher-forced prompt logprobs: identical context by construction.
55
+ tf_dl = []
56
+ tf_pos = tf_agree = 0
57
+ for sa, sb in zip(a["scored"], b["scored"]):
58
+ for pa, pb in zip(sa["prompt_logprobs"], sb["prompt_logprobs"]):
59
+ if pa is None or pb is None:
60
+ continue
61
+ # chosen prompt token = the key with rank field that matches; both dicts
62
+ # contain the actual token (rank r) and the top-1. Find common token id
63
+ # present in both (the prompt token id is the same on both sides).
64
+ common = set(pa) & set(pb)
65
+ if not common:
66
+ continue
67
+ # the prompt token appears in both dicts (it is always included)
68
+ for tid in common:
69
+ ra, rb = pa[tid].get("rank"), pb[tid].get("rank")
70
+ tf_dl.append(abs(pa[tid]["logprob"] - pb[tid]["logprob"]))
71
+ tf_pos += 1
72
+ if (ra == 1) == (rb == 1):
73
+ tf_agree += 1
74
+ break
75
+ print(
76
+ f"teacher-forced: n={tf_pos} mean |dlogprob| {sum(tf_dl) / max(len(tf_dl), 1):.5f} "
77
+ f"max {max(tf_dl) if tf_dl else 0:.5f}; top-1-status agreement "
78
+ f"{100 * tf_agree / max(tf_pos, 1):.2f}%"
79
+ )
scripts/convert_fp8attn.py ADDED
@@ -0,0 +1,345 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Derive GLM-5.3-Flash-NVFP4-FP8ATTN (r2: MLP + ATTENTION FP8) from
2
+ GLM-5.3-Flash-NVFP4 (rev caca4e6a; expert weight shards are byte-identical to
3
+ 357b45cc — only the input scales and card differ between those revisions).
4
+
5
+ Targets the patched serving image that passes the real quant_config into the
6
+ KDA/MLA attention constructors (kda.py strip removed, model.py:329
7
+ None -> real). See the model card and serving/README.md.
8
+
9
+ Run convert_lmhead.py afterward to reproduce the published checkpoint
10
+ (block-FP8 lm_head) bit-for-bit.
11
+
12
+ Converted surfaces and block sizes (weight F8_E4M3 + weight_scale_inv F32,
13
+ dequant multiplier amax/448):
14
+
15
+ FP8_BLOCK128 ([128,128], the proven MLP path):
16
+ - *.mlp.shared_experts.{gate,up,down}_proj layers 3..45 (incl. MTP 45)
17
+ - *.mlp.{gate,up,down}_proj dense layers 0..2
18
+ - *.self_attn.o_proj ALL 46 layers (KDA + MLA)
19
+ - *.self_attn.{q_a_proj,kv_a_proj_with_mqa,q_b_proj} MLA layers
20
+ (q_a + kv_a fuse into fused_qkv_a_proj at runtime: offsets 0/1536 and
21
+ sizes 1536/512 all divide 128 because qk_rope_head_dim=0)
22
+
23
+ FP8_BLOCK32 ([32,32], new dispatch in the r2 image's modelopt.py):
24
+ - *.self_attn.{q,k,v,b,f_a,g_a}_proj KDA layers
25
+ (they fuse into in_proj_qkvbfg_a whose per-rank TP2 layout is
26
+ q|k|v 4096 each | b 32 | f_a 128 | g_a 128 — block_n must divide 32;
27
+ square because Fp8LinearMethod's activation group = block_n)
28
+
29
+ Kept BF16 (deliberate):
30
+ - kv_b_proj — MLA absorption stores BF16 W_UK/W_UV copies regardless
31
+ (mla_attention.py:1022); net saving ~0.09 GiB/rank and
32
+ _get_kv_b_proj_input_dtype has an untested fp8 branch.
33
+ - f_b_proj/g_b_proj — delta-rule gate projections, not in the tasking.
34
+ - indexer.*, convs, norms, embed_tokens, lm_head, visual.* — as before.
35
+
36
+ Untouched shards are HARDLINKED to the source. Manifest carries both the
37
+ main-model spelling (model.language_model.layers.N.*) and the MTP draft
38
+ runtime spelling (model.layers.45.*), for MLP AND attention.
39
+ """
40
+
41
+ import json
42
+ import os
43
+ import re
44
+ import struct
45
+ import time
46
+
47
+ import ml_dtypes
48
+ import numpy as np
49
+
50
+ SRC = None # set from --input in __main__
51
+ DST = None # set from --output in __main__
52
+ FIRST_K_DENSE = 3
53
+ NUM_LAYERS = 46 # 45 decoder + MTP layer 45
54
+ NUM_EXPERTS = 288
55
+
56
+ MLP_RE = re.compile(
57
+ r"^model\.language_model\.layers\.(\d+)\.mlp\."
58
+ r"(shared_experts\.)?(gate|up|down)_proj\.weight$"
59
+ )
60
+ ATTN128_RE = re.compile(
61
+ r"^model\.language_model\.layers\.(\d+)\.self_attn\."
62
+ r"(o_proj|q_a_proj|kv_a_proj_with_mqa|q_b_proj)\.weight$"
63
+ )
64
+ ATTN32_RE = re.compile(
65
+ r"^model\.language_model\.layers\.(\d+)\.self_attn\."
66
+ r"(q|k|v|b|f_a|g_a)_proj\.weight$"
67
+ )
68
+
69
+ # ignore-list patterns whose modules are now FP8-quantized
70
+ UNIGNORE = {
71
+ # MLP family (as in convert_fp8mlp.py)
72
+ "*.mlp.shared_experts.gate_up_proj",
73
+ "*.mlp.shared_experts.down_proj",
74
+ "*.mlp.shared_experts.gate_proj",
75
+ "*.mlp.shared_experts.up_proj",
76
+ "*.mlp.gate_up_proj",
77
+ "*.mlp.down_proj",
78
+ "*.mlp.gate_proj",
79
+ "*.mlp.up_proj",
80
+ # attention: KDA fused in_proj shards + fused spellings
81
+ "*.self_attn.q_proj",
82
+ "*.self_attn.k_proj",
83
+ "*.self_attn.v_proj",
84
+ "*.self_attn.b_proj",
85
+ "*.self_attn.f_a_proj",
86
+ "*.self_attn.g_a_proj",
87
+ "*.self_attn.in_proj_qkvbfg_a",
88
+ "*.self_attn.fused_qkvbfg_a_proj",
89
+ # attention: o_proj (KDA + MLA) and the MLA q/lora side
90
+ "*.self_attn.o_proj",
91
+ "*.self_attn.q_a_proj",
92
+ "*.self_attn.kv_a_proj_with_mqa",
93
+ "*.self_attn.fused_qkv_a_proj",
94
+ "*.self_attn.fused_qkv_a_proj_with_mqa",
95
+ "*.self_attn.q_b_proj",
96
+ }
97
+ # NOTE deliberately NOT unignored: *.self_attn.kv_b_proj, *.self_attn.f_b_proj,
98
+ # *.self_attn.g_b_proj, *.self_attn.fused_fg_b_proj, indexer/conv/norm entries.
99
+
100
+
101
+ def read_header(path):
102
+ with open(path, "rb") as f:
103
+ n = struct.unpack("<Q", f.read(8))[0]
104
+ return json.loads(f.read(n)), 8 + n
105
+
106
+
107
+ def block_for(name):
108
+ """Return the quant block size for a target tensor name, else None."""
109
+ m = MLP_RE.match(name)
110
+ if m:
111
+ layer, shared = int(m.group(1)), bool(m.group(2))
112
+ return 128 if (shared or layer < FIRST_K_DENSE) else None
113
+ if ATTN128_RE.match(name):
114
+ return 128
115
+ if ATTN32_RE.match(name):
116
+ return 32
117
+ return None
118
+
119
+
120
+ def quant_block(w32, b):
121
+ n, k = w32.shape
122
+ assert n % b == 0 and k % b == 0, (n, k, b)
123
+ B = w32.reshape(n // b, b, k // b, b)
124
+ amax = np.abs(B).max(axis=(1, 3), keepdims=True)
125
+ s = np.where(amax == 0, np.float32(1), amax / np.float32(448)).astype(np.float32)
126
+ q = np.clip(B / s, -448, 448).astype(ml_dtypes.float8_e4m3fn)
127
+ return (
128
+ np.ascontiguousarray(q.reshape(n, k)),
129
+ np.ascontiguousarray(s.reshape(B.shape[0], B.shape[2])),
130
+ )
131
+
132
+
133
+ def build_quantized_layers(mla_layers):
134
+ ql = {}
135
+ nvfp4 = {"quant_algo": "NVFP4", "group_size": 16}
136
+ fp8_128 = {"quant_algo": "FP8_BLOCK128"}
137
+ fp8_32 = {"quant_algo": "FP8_BLOCK32"}
138
+
139
+ def attn_entries(base, layer):
140
+ # base ends in ".self_attn"
141
+ ql[f"{base}.o_proj"] = fp8_128
142
+ if layer in mla_layers:
143
+ for p in ("q_a_proj", "kv_a_proj_with_mqa", "q_b_proj"):
144
+ ql[f"{base}.{p}"] = fp8_128
145
+ else:
146
+ for p in ("q_proj", "k_proj", "v_proj", "b_proj", "f_a_proj", "g_a_proj"):
147
+ ql[f"{base}.{p}"] = fp8_32
148
+
149
+ for layer in range(NUM_LAYERS):
150
+ base = f"model.language_model.layers.{layer}"
151
+ attn_entries(f"{base}.self_attn", layer)
152
+ if layer >= FIRST_K_DENSE:
153
+ for e in range(NUM_EXPERTS):
154
+ for p in ("gate", "up", "down"):
155
+ ql[f"{base}.mlp.experts.{e}.{p}_proj"] = nvfp4
156
+ for p in ("gate", "up", "down"):
157
+ ql[f"{base}.mlp.shared_experts.{p}_proj"] = fp8_128
158
+ else:
159
+ for p in ("gate", "up", "down"):
160
+ ql[f"{base}.mlp.{p}_proj"] = fp8_128
161
+
162
+ # MTP draft-model runtime spelling: mtp.py builds the layer-45 decoder
163
+ # block with prefix "model.layers.45" (no ".mtp_block" in the quant-lookup
164
+ # prefix), so the manifest must carry these keys verbatim. Mirrors the MLP
165
+ # aliases that fixed the FP8MIX-v2 KeyError; extended here to attention.
166
+ mtp = "model.layers.45"
167
+ attn_entries(f"{mtp}.self_attn", 45)
168
+ for e in range(NUM_EXPERTS):
169
+ for p in ("gate", "up", "down"):
170
+ ql[f"{mtp}.mlp.experts.{e}.{p}_proj"] = nvfp4
171
+ ql[f"{mtp}.mlp.experts.routed_experts.0.up_proj"] = nvfp4
172
+ for p in ("gate", "up", "down"):
173
+ ql[f"{mtp}.mlp.shared_experts.{p}_proj"] = fp8_128
174
+ return ql
175
+
176
+
177
+ def main():
178
+ os.makedirs(DST, exist_ok=True)
179
+ idx = json.load(open(f"{SRC}/model.safetensors.index.json"))
180
+ wmap = dict(idx["weight_map"])
181
+ shards = sorted(set(wmap.values()))
182
+
183
+ mla_layers = sorted(
184
+ {
185
+ int(re.match(r"model\.language_model\.layers\.(\d+)\.", n).group(1))
186
+ for n in wmap
187
+ if ".self_attn.q_a_proj." in n
188
+ }
189
+ )
190
+ assert mla_layers == [3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 45], mla_layers
191
+
192
+ todo = {}
193
+ n32 = n128 = 0
194
+ for name, sh in wmap.items():
195
+ b = block_for(name)
196
+ if b is not None:
197
+ todo.setdefault(sh, {})[name] = b
198
+ if b == 32:
199
+ n32 += 1
200
+ else:
201
+ n128 += 1
202
+ n_targets = n32 + n128
203
+ print(f"{n_targets} targets ({n32} block32 + {n128} block128) in {len(todo)}/{len(shards)} shards")
204
+ assert n32 == 204, n32 # 34 KDA layers x 6
205
+ assert n128 == 138 + 82, n128 # MLP 138 + attn (46 o + 12x3 MLA)
206
+
207
+ t0 = time.time()
208
+ linked = rewritten = 0
209
+ size_delta = 0
210
+ for si, sh in enumerate(shards, 1):
211
+ src, dst = f"{SRC}/{sh}", f"{DST}/{sh}"
212
+ if os.path.exists(dst):
213
+ os.unlink(dst)
214
+ if sh not in todo:
215
+ os.link(src, dst)
216
+ linked += 1
217
+ continue
218
+ hdr, base = read_header(src)
219
+ meta = hdr.get("__metadata__")
220
+ conv = todo[sh]
221
+ order = [k for k in hdr if k != "__metadata__"]
222
+ new_hdr, blobs, off = {}, [], 0
223
+ with open(src, "rb") as f:
224
+ for k in order:
225
+ m = hdr[k]
226
+ s, e = m["data_offsets"]
227
+ f.seek(base + s)
228
+ raw = f.read(e - s)
229
+ if k in conv:
230
+ assert m["dtype"] == "BF16", (k, m["dtype"])
231
+ w = (
232
+ np.frombuffer(raw, dtype=ml_dtypes.bfloat16)
233
+ .reshape(m["shape"])
234
+ .astype(np.float32)
235
+ )
236
+ qw, sc = quant_block(w, conv[k])
237
+ for nm, arr, dt in (
238
+ (k, qw, "F8_E4M3"),
239
+ (k[: -len(".weight")] + ".weight_scale_inv", sc, "F32"),
240
+ ):
241
+ b = arr.tobytes()
242
+ new_hdr[nm] = {
243
+ "dtype": dt,
244
+ "shape": list(arr.shape),
245
+ "data_offsets": [off, off + len(b)],
246
+ }
247
+ blobs.append(b)
248
+ off += len(b)
249
+ size_delta += len(b)
250
+ size_delta -= len(raw)
251
+ else:
252
+ new_hdr[k] = {
253
+ "dtype": m["dtype"],
254
+ "shape": m["shape"],
255
+ "data_offsets": [off, off + len(raw)],
256
+ }
257
+ blobs.append(raw)
258
+ off += len(raw)
259
+ if meta is not None:
260
+ new_hdr["__metadata__"] = meta
261
+ hb = json.dumps(new_hdr, separators=(",", ":")).encode()
262
+ pad = (-(8 + len(hb))) % 8
263
+ hb += b" " * pad
264
+ tmp = dst + ".tmp"
265
+ with open(tmp, "wb") as f:
266
+ f.write(struct.pack("<Q", len(hb)))
267
+ f.write(hb)
268
+ for b in blobs:
269
+ f.write(b)
270
+ os.replace(tmp, dst)
271
+ rewritten += 1
272
+ print(
273
+ f"[{si}/{len(shards)}] {sh} rewrote {len(conv)} tensors "
274
+ f"({time.time() - t0:.0f}s)",
275
+ flush=True,
276
+ )
277
+
278
+ for sh, names in todo.items():
279
+ for name in names:
280
+ wmap[name[: -len(".weight")] + ".weight_scale_inv"] = sh
281
+ idx["weight_map"] = wmap
282
+ if "metadata" in idx and "total_size" in idx["metadata"]:
283
+ idx["metadata"]["total_size"] += size_delta
284
+ json.dump(idx, open(f"{DST}/model.safetensors.index.json", "w"))
285
+
286
+ cfg = json.load(open(f"{SRC}/config.json"))
287
+ src_q = cfg["quantization_config"]
288
+ ignore = [p for p in src_q["ignore"] if p not in UNIGNORE]
289
+ cfg["quantization_config"] = {
290
+ "producer": src_q.get("producer", {"name": "modelopt", "version": "0.45.0"}),
291
+ "quant_method": "modelopt",
292
+ "quant_algo": "MIXED_PRECISION",
293
+ "kv_cache_scheme": src_q.get("kv_cache_scheme"),
294
+ "group_size": 16,
295
+ "ignore": ignore,
296
+ "quantized_layers": build_quantized_layers(set(mla_layers)),
297
+ }
298
+ json.dump(cfg, open(f"{DST}/config.json", "w"), indent=1)
299
+
300
+ for fn in os.listdir(SRC):
301
+ if fn.endswith(".safetensors") or fn in (
302
+ "config.json",
303
+ "model.safetensors.index.json",
304
+ ):
305
+ continue
306
+ s, d = f"{SRC}/{fn}", f"{DST}/{fn}"
307
+ if os.path.isfile(s) and not os.path.exists(d):
308
+ os.link(s, d)
309
+ print(
310
+ f"DONE linked={linked} rewritten={rewritten} "
311
+ f"size_delta={size_delta / 2**30:.3f} GiB in {time.time() - t0:.0f}s"
312
+ )
313
+
314
+
315
+ if __name__ == "__main__":
316
+ import argparse
317
+
318
+ ap = argparse.ArgumentParser(
319
+ description="Derive the NVFP4 + block-FP8 (MLP + attention) checkpoint from a "
320
+ "pristine GLM-5.3-Flash-NVFP4 checkpoint (rev caca4e6a). Unchanged shards are "
321
+ "hardlinked (same filesystem required). Run convert_lmhead.py afterward to "
322
+ "reproduce the published checkpoint exactly."
323
+ )
324
+ ap.add_argument(
325
+ "--input",
326
+ required=True,
327
+ help="pristine GLM-5.3-Flash-NVFP4 checkpoint dir (only read)",
328
+ )
329
+ ap.add_argument(
330
+ "--output",
331
+ required=True,
332
+ help="output checkpoint dir (created if missing; EXISTING FILES IN IT ARE REPLACED)",
333
+ )
334
+ ap.add_argument("--yes", action="store_true", help="skip the confirmation prompt")
335
+ args = ap.parse_args()
336
+ SRC, DST = os.path.abspath(args.input), os.path.abspath(args.output)
337
+ if SRC == DST:
338
+ raise SystemExit("--input and --output must differ (conversion is not in-place)")
339
+ if not os.path.isfile(os.path.join(SRC, "model.safetensors.index.json")):
340
+ raise SystemExit(f"{SRC} has no model.safetensors.index.json — not a checkpoint dir")
341
+ if not args.yes:
342
+ reply = input(f"(Re)write shards in {DST} from {SRC}? [y/N] ")
343
+ if reply.strip().lower() not in ("y", "yes"):
344
+ raise SystemExit("aborted")
345
+ main()
scripts/convert_lmhead.py ADDED
@@ -0,0 +1,197 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Post-step on GLM-5.3-Flash-NVFP4-FP8ATTN: quantize lm_head to block-FP8.
2
+
3
+ Composable AFTER convert_fp8attn.py (r2 content). Targets the fp8attn-r4
4
+ image, whose modelopt.py dispatches ParallelLMHead + FP8_BLOCK128 to
5
+ _Fp8BlockLMHeadMethod (vocab-block-sharded scale loader).
6
+
7
+ lm_head.weight BF16 [154880, 4096] -> F8_E4M3 + weight_scale_inv F32
8
+ [1210, 32], block [128,128], dequant multiplier amax/448 — identical
9
+ scheme/derivation to convert_fp8attn.py's quant_block.
10
+
11
+ Geometry: 154880 % 128 == 0 and the TP2 vocab shard 77440 % 128 == 0, so
12
+ weight and scale shard exactly on block boundaries.
13
+
14
+ config.json: remove "lm_head" from quantization_config.ignore (its substring
15
+ match would keep the head excluded) and add
16
+ quantized_layers["lm_head"] = {"quant_algo": "FP8_BLOCK128"}.
17
+
18
+ Reversible: the touched shard, config.json and the index are snapshotted as
19
+ *.pre-lmhead first (shard via hardlink — zero cost). `--revert` puts all
20
+ three back and removes the snapshots. embed_tokens stays BF16 (gather
21
+ semantics: VocabParallelEmbedding never receives a quant method).
22
+
23
+ Source NVFP4 dir untouched (all writes are new-file + os.replace).
24
+ """
25
+
26
+ import json
27
+ import os
28
+ import struct
29
+ import sys
30
+ import time
31
+
32
+ import ml_dtypes
33
+ import numpy as np
34
+
35
+ DST = None # set from --dir in __main__
36
+ TENSOR = "lm_head.weight"
37
+ BLOCK = 128
38
+ SUFFIX = ".pre-lmhead"
39
+
40
+
41
+ def read_header(path):
42
+ with open(path, "rb") as f:
43
+ n = struct.unpack("<Q", f.read(8))[0]
44
+ return json.loads(f.read(n)), 8 + n
45
+
46
+
47
+ def quant_block(w32, b):
48
+ n, k = w32.shape
49
+ assert n % b == 0 and k % b == 0, (n, k, b)
50
+ B = w32.reshape(n // b, b, k // b, b)
51
+ amax = np.abs(B).max(axis=(1, 3), keepdims=True)
52
+ s = np.where(amax == 0, np.float32(1), amax / np.float32(448)).astype(np.float32)
53
+ q = np.clip(B / s, -448, 448).astype(ml_dtypes.float8_e4m3fn)
54
+ return (
55
+ np.ascontiguousarray(q.reshape(n, k)),
56
+ np.ascontiguousarray(s.reshape(B.shape[0], B.shape[2])),
57
+ )
58
+
59
+
60
+ def revert():
61
+ idx_path = f"{DST}/model.safetensors.index.json"
62
+ cfg_path = f"{DST}/config.json"
63
+ idx_bak, cfg_bak = idx_path + SUFFIX, cfg_path + SUFFIX
64
+ if not os.path.exists(idx_bak):
65
+ sys.exit("no .pre-lmhead snapshots found; nothing to revert")
66
+ shard = json.load(open(idx_bak))["weight_map"][TENSOR]
67
+ shard_path = f"{DST}/{shard}"
68
+ for bak, live in ((shard_path + SUFFIX, shard_path), (idx_bak, idx_path), (cfg_bak, cfg_path)):
69
+ os.replace(bak, live)
70
+ print(f"reverted: {shard}, index, config restored")
71
+
72
+
73
+ def main():
74
+ idx_path = f"{DST}/model.safetensors.index.json"
75
+ cfg_path = f"{DST}/config.json"
76
+ idx = json.load(open(idx_path))
77
+ if TENSOR + "_scale_inv" in idx["weight_map"] or (
78
+ TENSOR[: -len(".weight")] + ".weight_scale_inv"
79
+ ) in idx["weight_map"]:
80
+ sys.exit("lm_head already converted (scale in index); use --revert first")
81
+ shard = idx["weight_map"][TENSOR]
82
+ src = f"{DST}/{shard}"
83
+
84
+ # snapshots (shard as hardlink: pre-conversion inode preserved for free)
85
+ os.link(src, src + SUFFIX)
86
+ for p in (idx_path, cfg_path):
87
+ with open(p) as f, open(p + SUFFIX, "w") as g:
88
+ g.write(f.read())
89
+
90
+ t0 = time.time()
91
+ hdr, base = read_header(src)
92
+ meta = hdr.get("__metadata__")
93
+ order = [k for k in hdr if k != "__metadata__"]
94
+ new_hdr, blobs, off, size_delta = {}, [], 0, 0
95
+ with open(src, "rb") as f:
96
+ for k in order:
97
+ m = hdr[k]
98
+ s, e = m["data_offsets"]
99
+ f.seek(base + s)
100
+ raw = f.read(e - s)
101
+ if k == TENSOR:
102
+ assert m["dtype"] == "BF16", m["dtype"]
103
+ w = (
104
+ np.frombuffer(raw, dtype=ml_dtypes.bfloat16)
105
+ .reshape(m["shape"])
106
+ .astype(np.float32)
107
+ )
108
+ qw, sc = quant_block(w, BLOCK)
109
+ # round-trip check
110
+ deq = qw.astype(np.float32) * np.repeat(
111
+ np.repeat(sc, BLOCK, 0), BLOCK, 1
112
+ )
113
+ err = np.linalg.norm(deq - w) / np.linalg.norm(w)
114
+ print(f"lm_head shape {m['shape']} round-trip rel err {err:.4%}")
115
+ for nm, arr, dt in (
116
+ (k, qw, "F8_E4M3"),
117
+ (k[: -len(".weight")] + ".weight_scale_inv", sc, "F32"),
118
+ ):
119
+ b = arr.tobytes()
120
+ new_hdr[nm] = {
121
+ "dtype": dt,
122
+ "shape": list(arr.shape),
123
+ "data_offsets": [off, off + len(b)],
124
+ }
125
+ blobs.append(b)
126
+ off += len(b)
127
+ size_delta += len(b)
128
+ size_delta -= len(raw)
129
+ else:
130
+ new_hdr[k] = {
131
+ "dtype": m["dtype"],
132
+ "shape": m["shape"],
133
+ "data_offsets": [off, off + len(raw)],
134
+ }
135
+ blobs.append(raw)
136
+ off += len(raw)
137
+ if meta is not None:
138
+ new_hdr["__metadata__"] = meta
139
+ hb = json.dumps(new_hdr, separators=(",", ":")).encode()
140
+ hb += b" " * ((-(8 + len(hb))) % 8)
141
+ tmp = src + ".tmp"
142
+ with open(tmp, "wb") as f:
143
+ f.write(struct.pack("<Q", len(hb)))
144
+ f.write(hb)
145
+ for b in blobs:
146
+ f.write(b)
147
+ os.replace(tmp, src)
148
+
149
+ wmap = dict(idx["weight_map"])
150
+ wmap[TENSOR[: -len(".weight")] + ".weight_scale_inv"] = shard
151
+ idx["weight_map"] = wmap
152
+ if "metadata" in idx and "total_size" in idx["metadata"]:
153
+ idx["metadata"]["total_size"] += size_delta
154
+ json.dump(idx, open(idx_path, "w"))
155
+
156
+ cfg = json.load(open(cfg_path))
157
+ q = cfg["quantization_config"]
158
+ q["ignore"] = [p for p in q["ignore"] if p != "lm_head"]
159
+ q["quantized_layers"]["lm_head"] = {"quant_algo": "FP8_BLOCK128"}
160
+ json.dump(cfg, open(cfg_path, "w"), indent=1)
161
+
162
+ print(
163
+ f"DONE {shard} rewritten, size_delta={size_delta / 2**30:+.3f} GiB, "
164
+ f"{time.time() - t0:.0f}s. Revert: python3 convert_lmhead.py --dir {DST} --revert"
165
+ )
166
+
167
+
168
+ if __name__ == "__main__":
169
+ import argparse
170
+
171
+ ap = argparse.ArgumentParser(
172
+ description="Quantize lm_head to block-FP8 IN PLACE in a converted "
173
+ "GLM-5.3-Flash-NVFP4-FP8ATTN checkpoint dir. The touched shard, config.json and "
174
+ "index are snapshotted as *.pre-lmhead first; --revert restores them."
175
+ )
176
+ ap.add_argument(
177
+ "--dir", required=True, help="checkpoint dir to modify IN PLACE"
178
+ )
179
+ ap.add_argument(
180
+ "--revert", action="store_true", help="restore the *.pre-lmhead snapshots"
181
+ )
182
+ ap.add_argument("--yes", action="store_true", help="skip the confirmation prompt")
183
+ args = ap.parse_args()
184
+ DST = os.path.abspath(args.dir)
185
+ if not os.path.isfile(os.path.join(DST, "model.safetensors.index.json")):
186
+ raise SystemExit(f"{DST} has no model.safetensors.index.json — not a checkpoint dir")
187
+ if args.revert:
188
+ revert()
189
+ else:
190
+ if not args.yes:
191
+ reply = input(
192
+ f"Rewrite the lm_head shard in {DST} IN PLACE "
193
+ "(with .pre-lmhead snapshots)? [y/N] "
194
+ )
195
+ if reply.strip().lower() not in ("y", "yes"):
196
+ raise SystemExit("aborted")
197
+ main()
scripts/longctx.py ADDED
@@ -0,0 +1,140 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """512k acceptance: N consecutive >=500k-token prompts through a live server.
2
+
3
+ Usage: python3 longctx.py <port> <model> [n_rounds=3] [target_tokens=505000]
4
+
5
+ Each round builds a DIFFERENT ~target-token prompt (defeats prefix caching so
6
+ every round is a fresh full-length prefill — the fragmentation test), asks for
7
+ a short completion, and reports usage.prompt_tokens, prefill time, and decode
8
+ tok/s. Round 1 additionally re-sends its own prompt (prefix-cache hit) with a
9
+ longer completion to measure steady decode tok/s at full context.
10
+ """
11
+
12
+ import json
13
+ import random
14
+ import sys
15
+ import time
16
+ import urllib.request
17
+
18
+ PORT, MODEL = sys.argv[1], sys.argv[2]
19
+ ROUNDS = int(sys.argv[3]) if len(sys.argv) > 3 else 3
20
+ TARGET = int(sys.argv[4]) if len(sys.argv) > 4 else 505000
21
+
22
+ WORDS = (
23
+ "the quick brown fox jumps over a lazy dog while seventeen green wizards "
24
+ "quietly brew potent elixirs behind twelve ancient marble columns near "
25
+ "the harbor as autumn rain drums softly on copper rooftops and distant "
26
+ "bells mark the passing hours for patient scholars reading dusty scrolls"
27
+ ).split()
28
+
29
+
30
+ def build_prompt(seed, n_tokens):
31
+ rng = random.Random(seed)
32
+ # ~1.3 tokens/word for this vocab; overshoot handled by the caller loop.
33
+ words = []
34
+ target_words = int(n_tokens / 1.35)
35
+ while len(words) < target_words:
36
+ chunk = WORDS[:]
37
+ rng.shuffle(chunk)
38
+ words.extend(chunk)
39
+ words.append(f"marker{rng.randint(1000, 9999)}.")
40
+ return " ".join(words)
41
+
42
+
43
+ def post(path, payload, timeout=3600):
44
+ req = urllib.request.Request(
45
+ f"http://127.0.0.1:{PORT}{path}",
46
+ data=json.dumps(payload).encode(),
47
+ headers={"Content-Type": "application/json"},
48
+ )
49
+ with urllib.request.urlopen(req, timeout=timeout) as r:
50
+ return json.loads(r.read())
51
+
52
+
53
+ def count_tokens(text):
54
+ r = post("/tokenize", {"model": MODEL, "prompt": text})
55
+ return r["count"]
56
+
57
+
58
+ def chat(prompt_text, max_tokens):
59
+ t0 = time.time()
60
+ r = post(
61
+ "/v1/chat/completions",
62
+ {
63
+ "model": MODEL,
64
+ "messages": [
65
+ {
66
+ "role": "user",
67
+ "content": prompt_text
68
+ + "\n\nThe text above is filler. Reply with the single "
69
+ "word ACKNOWLEDGED followed by one short sentence.",
70
+ }
71
+ ],
72
+ "max_tokens": max_tokens,
73
+ "temperature": 0,
74
+ },
75
+ )
76
+ dt = time.time() - t0
77
+ return r, dt
78
+
79
+
80
+ # calibrate tokens/char on a small sample
81
+ sample = build_prompt(0, 2000)
82
+ spt = count_tokens(sample) / len(sample)
83
+ print(f"calibration: {spt:.5f} tok/char on {len(sample)} chars")
84
+
85
+ results = []
86
+ for rnd in range(1, ROUNDS + 1):
87
+ # build to target using measured ratio, then trim/verify via /tokenize
88
+ text = build_prompt(rnd, int(TARGET * 1.02))
89
+ need_chars = int(TARGET / spt)
90
+ text = text[:need_chars]
91
+ n_tok = count_tokens(text)
92
+ print(f"[round {rnd}] built prompt: {n_tok} tokens ({len(text)} chars)")
93
+ if n_tok < 500000:
94
+ # extend deterministically until over 500k
95
+ while n_tok < 500500:
96
+ text = text + " " + build_prompt(100 + rnd, 6000)
97
+ n_tok = count_tokens(text)
98
+ print(f"[round {rnd}] extended to {n_tok} tokens")
99
+
100
+ r, dt = chat(text, 64)
101
+ u = r["usage"]
102
+ reply = r["choices"][0]["message"].get("content") or r["choices"][0][
103
+ "message"
104
+ ].get("reasoning_content", "")
105
+ ok = u["prompt_tokens"] >= 500000 and r["choices"][0].get("finish_reason") in (
106
+ "stop",
107
+ "length",
108
+ )
109
+ print(
110
+ f"[round {rnd}] prompt_tokens={u['prompt_tokens']} "
111
+ f"completion={u['completion_tokens']} wall={dt:.1f}s "
112
+ f"finish={r['choices'][0].get('finish_reason')} ok={ok}"
113
+ )
114
+ print(f"[round {rnd}] reply: {reply[:200]!r}")
115
+ entry = {
116
+ "round": rnd,
117
+ "prompt_tokens": u["prompt_tokens"],
118
+ "wall_s": dt,
119
+ "ok": ok,
120
+ "reply_head": reply[:200],
121
+ }
122
+
123
+ if rnd == 1:
124
+ # decode-rate at full context: resend (prefix cached) with more tokens
125
+ r1, dt1 = chat(text, 1)
126
+ r2, dt2 = chat(text, 257)
127
+ gen = r2["usage"]["completion_tokens"]
128
+ # crude: dt2 includes cached-prefill overhead ~= dt1
129
+ rate = (gen - 1) / max(dt2 - dt1, 1e-6)
130
+ print(
131
+ f"[round 1] decode at {u['prompt_tokens']} ctx: {gen} tok in "
132
+ f"{dt2:.1f}s (1-tok call {dt1:.1f}s) -> ~{rate:.1f} tok/s"
133
+ )
134
+ entry["decode_tok_s_at_ctx"] = round(rate, 1)
135
+ results.append(entry)
136
+
137
+ json.dump(results, open("/tmp/longctx-results.json", "w"), indent=1)
138
+ n_ok = sum(1 for e in results if e["ok"])
139
+ print(f"PASS {n_ok}/{ROUNDS}" if n_ok == ROUNDS else f"FAIL {n_ok}/{ROUNDS}")
140
+ sys.exit(0 if n_ok == ROUNDS else 1)
scripts/results-512k.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"port": 18996, "model": "glm-5.3-flash-fp8attn", "arith_correct": true, "arith_raw": "391", "long_gen_tokens": 2400, "long_gen_degenerate": false, "long_gen_tail": "", "greedy": [{"prompt": "What is 17*23? Answer with just the number.", "tokens": [" No", " explanation", ".\n\n", "Asked", " on", " ", "10", "/", "13", "/", "202", "3", ",", " ", "2", " page", "views", "\n\n", "Re", "plies", "\n\n", "39", "1", ".", " No", ",", " wait", ".", " ", "17", "*", "23", " is", " ", "39", "1", ".", " No", ",", " that", "'s", " not", " right", " either", ".", " Let", " me", " calculate", " it", " properly"], "token_logprobs": [-0.05366511642932892, -0.9350380301475525, -0.380475789308548, -2.2214250564575195, -0.20399169623851776, -0.01683633029460907, -1.594815731048584, -8.022463589441031e-05, -2.632683515548706, -4.0531076592742465e-06, -2.6702524337451905e-05, -0.5865628719329834, -0.00019572250312194228, -1.3351351299206726e-05, -0.5414031147956848, -8.034383063204587e-05, -5.23315102327615e-05, -0.0007976687629707158, -0.8636804223060608, -0.004327575676143169, -0.002378137083724141, -0.2068578451871872, -0.0010551605373620987, -0.4351445436477661, -2.109701633453369, -0.7401304841041565, -0.6942418813705444, -0.5244114398956299, -1.0793718099594116, -0.5912761688232422, -0.31640252470970154, -0.0005953923100605607, -0.3274829685688019, -0.5549824833869934, -0.0022199528757482767, -0.000662703241687268, -0.25928738713264465, -0.927765429019928, -0.09151877462863922, -1.0703998804092407, -0.04463984817266464, -0.22456113994121552, -0.04124918580055237, -0.3160233199596405, -0.0028626436833292246, -0.7268477082252502, -0.0005360596696846187, -0.792045533657074, -0.8923566937446594, -1.213303804397583]}, {"prompt": "Write a Python function that returns the nth Fibonacci number iteratively.", "tokens": [" The", " function", " should", " take", " an", " integer", " n", " as", " input", " and", " return", " the", " nth", " Fibonacci", " number", ".", " The", " Fibonacci", " sequence", " is", " defined", " as", " F", "(", "0", ")", " =", " ", "0", ",", " F", "(", "1", ")", " =", " ", "1", ",", " and", " F", "(n", ")", " =", " F", "(n", "-", "1", ")", " +", " F"], "token_logprobs": [-1.6943055391311646, -0.5823361873626709, -0.112541064620018, -1.3006826639175415, -0.2677465081214905, -0.026433274149894714, -0.23271720111370087, -0.3905608654022217, -0.13937094807624817, -0.041517630219459534, -0.052468955516815186, -0.010499831289052963, -0.21235646307468414, -0.11370497941970825, -0.0008087463211268187, -1.0704808235168457, -0.9860906600952148, -0.3667610287666321, -0.012264197692275047, -0.6368409395217896, -0.4017713963985443, -0.1622999757528305, -0.941962718963623, -0.01426851749420166, -0.048608336597681046, -0.12718714773654938, -0.0001722425949992612, -0.0004450284468475729, -0.0006429274217225611, -0.006943738553673029, -8.487341256113723e-05, -7.295342220459133e-05, -1.680836794548668e-05, -4.386805812828243e-05, -1.5616295058862306e-05, -9.619726915843785e-05, -3.814624506048858e-05, -0.0010099078062921762, -0.05528891086578369, -0.034970786422491074, -0.0009255892946384847, -0.00012742661056108773, -3.886147169396281e-05, -0.00019012074335478246, -3.45700973412022e-05, -0.0014965059235692024, -0.00030071981018409133, -0.0002733095607254654, -0.0003432638186495751, -6.19869097135961e-05]}, {"prompt": "Explain the difference between TCP and UDP in two sentences.", "tokens": [" Then", ",", " explain", " why", " a", " video", " streaming", " service", " might", " use", " UDP", " instead", " of", " TCP", ".\n\n", "Ex", "plain", " the", " difference", " between", " TCP", " and", " UDP", " in", " two", " sentences", ".", " Then", ",", " explain", " why", " a", " video", " streaming", " service", " might", " use", " UDP", " instead", " of", " TCP", ".\n\n", "What", "'s", " a", " course", " level", " question", "?\n\n", "This"], "token_logprobs": [-2.143164873123169, -0.7151578664779663, -2.00456166267395, -1.4926910400390625, -1.517710566520691, -0.6309954524040222, -0.4701595902442932, -0.9748557209968567, -0.5520204305648804, -0.5754847526550293, -0.10024659335613251, -1.093806266784668, -0.0013913960428908467, -0.005019207019358873, -0.6733178496360779, -0.6214088797569275, -0.002333657816052437, -0.010152720846235752, -0.0029850706923753023, -0.0005583396414294839, -0.001408419106155634, -0.0009964506607502699, -6.41325386823155e-05, -0.00990535132586956, -0.010408640839159489, -0.00017951308109331876, -0.0485992506146431, -0.006944685708731413, -0.0008186326595023274, -0.001734420657157898, -0.0004839917819481343, -0.0006947487709112465, -0.0011188682401552796, -0.00014029949670657516, -0.0015955348499119282, -0.00039867559098638594, -0.0012436520773917437, -0.0005052005290053785, -0.00016485285595990717, -4.815939246327616e-05, -0.000291662581730634, -0.5456695556640625, -1.3766045570373535, -0.32731661200523376, -0.18958568572998047, -2.384284496307373, -2.220212936401367, -1.6876273155212402, -0.19231566786766052, -1.8455116748809814]}, {"prompt": "Translate to French: 'The quick brown fox jumps over the lazy dog.'", "tokens": [" The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".\n", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".\n", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".\n", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".\n", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".\n"], "token_logprobs": [-2.2402284145355225, -0.19012491405010223, -0.007193143479526043, -0.009139369241893291, -0.01923772506415844, -0.001384134404361248, -0.002724746707826853, -0.0011538759572431445, -0.0006387577159330249, -0.9065314531326294, -1.1879884004592896, -0.11312580108642578, -0.006771829444915056, -0.10594210773706436, -0.006137571297585964, -0.002190216211602092, -0.006136149168014526, -0.001061352901160717, -0.0010850501712411642, -0.3114866018295288, -0.36771097779273987, -0.03323061391711235, -0.006126670632511377, -0.019557030871510506, -0.0031175841577351093, -0.0018236687174066901, -0.002058888552710414, -0.0006785474251955748, -0.0009180859779007733, -0.11084146797657013, -0.1182633638381958, -0.011283867992460728, -0.0006501944735646248, -0.007268532644957304, -0.0025309454649686813, -0.00710449181497097, -0.0006897454150021076, -0.0017848765710368752, -0.00034600470098666847, -0.36827409267425537, -0.34182628989219666, -0.0200320016592741, -0.0009926398051902652, -0.0031632171012461185, -0.002413457492366433, -0.0006563892820850015, -0.0005508335889317095, -0.0013192531187087297, -0.0024672087747603655, -0.3734191358089447]}, {"prompt": "List the first 8 prime numbers separated by commas.", "tokens": [" The", " first", " ", "8", " prime", " numbers", " are", ":", " ", "2", ",", " ", "3", ",", " ", "5", ",", " ", "7", ",", " ", "11", ",", " ", "13", ",", " ", "17", ",", " ", "19", ".\n\n", "F", "ilo", " tutor", " solution", "\n\n", "Students", " who", " ask", " this", " question", " also", " asked", "\n\n", "Question", " Text", " ", " List", " the"], "token_logprobs": [-1.9596421718597412, -0.4394250810146332, -0.6387233734130859, -0.13414281606674194, -0.1679842323064804, -0.03987943381071091, -0.10874909907579422, -0.7848167419433594, -0.08312206715345383, -0.020730141550302505, -0.020677711814641953, -0.023003509268164635, -0.0036820252425968647, -0.004723936785012484, -0.004315943457186222, -0.0018197420286014676, -0.005848201457411051, -0.006533689331263304, -0.003494230331853032, -0.008086915127933025, -0.005233516450971365, -0.0025749404449015856, -0.0027939353603869677, -0.003230474190786481, -0.0006223172531463206, -0.011298484168946743, -0.005090490449219942, -0.0020828000269830227, -0.012244884856045246, -0.032125189900398254, -0.0012993711279705167, -0.6935392022132874, -0.6844730377197266, -0.0011449456214904785, -0.08876242488622665, -0.0008736607851460576, -0.003432812402024865, -0.03839205950498581, -5.9126061387360096e-05, -0.013770694844424725, -3.814689989667386e-06, -6.6756979322235566e-06, -5.245195097813848e-06, -0.006541624199599028, -0.000504723924677819, -0.015013555064797401, -0.0007649118197150528, -3.58813522325363e-05, -0.029479607939720154, -0.00017426878912374377]}, {"prompt": "What year did the Apollo 11 mission land on the moon? One word answer.", "tokens": [" No", " explanation", ".", " No", " links", ".", " No", " unnecessary", " answers", ".", " No", " spam", ".", " :", ")\n\n\n", "Question", " Text", " ", " Question", ":", " What", " year", " did", " the", " Apollo", " ", "11", " mission", " land", " on", " the", " moon", "?", " One", " word", " answer", ".", " No", " explanation", ".", " No", " links", ".", " No", " unnecessary", " answers", ".", " No", " spam", "."], "token_logprobs": [-2.731863260269165, -1.2752913236618042, -0.9330357909202576, -1.662278652191162, -1.8924283981323242, -0.15317098796367645, -0.27358484268188477, -0.08787223696708679, -0.13311609625816345, -0.04959043115377426, -0.5360126495361328, -0.7952455878257751, -0.08824098110198975, -1.050515055656433, -0.15692096948623657, -0.0840870812535286, -0.008074498735368252, -9.536738616588991e-07, -0.06402893364429474, -0.20874162018299103, -0.2755618095397949, -0.00016115797916427255, -2.7418097943154862e-06, -0.0001289761275984347, -4.2676016164477915e-05, -2.2291887944447808e-05, -1.764281842042692e-05, -5.6622808187967166e-05, -3.755022044060752e-05, -3.2186455882765586e-06, -1.9192511899746023e-05, -6.318072337307967e-06, -0.0010883843060582876, -0.031238215044140816, -2.1219027985353023e-05, -0.0003673355677165091, -0.0005220004240982234, -0.00042763148667290807, -0.00039939055568538606, -5.686121585313231e-05, -3.8265450712060556e-05, -6.174850568640977e-05, -3.4927710657939315e-05, -6.103329360485077e-05, -0.0001262346631847322, -6.592056161025539e-05, -4.637133679352701e-05, -5.578839045483619e-05, -0.00265733664855361, -0.005875222384929657]}, {"prompt": "Summarize the plot of Romeo and Juliet in one sentence.", "tokens": [" a", ")", " Two", " fe", "uding", " families", " reconcile", " after", " their", " children", ",", " Romeo", " and", " Juliet", ",", " die", " in", " a", " tragic", " misunderstanding", ".", " b", ")", " Romeo", " and", " Juliet", " fall", " in", " love", ",", " marry", " secretly", ",", " and", " their", " deaths", " ultimately", " end", " their", " families", "'", " feud", ".", " c", ")", " Romeo", " and", " Juliet", "'s", " love"], "token_logprobs": [-2.1703412532806396, -0.15103945136070251, -1.1161473989486694, -0.5909921526908875, -0.0003094194398727268, -0.10608192533254623, -1.5099761486053467, -0.09141913056373596, -0.023786770179867744, -0.007523535750806332, -0.741470456123352, -0.02876473404467106, -0.0016337393317371607, -0.0005801424849778414, -0.0024628089740872383, -0.5147541761398315, -0.866106390953064, -0.01595539227128029, -0.07065749168395996, -0.2379065901041031, -0.011185086332261562, -0.0022080582566559315, -0.00023123928986024112, -0.03406801447272301, -0.05845574662089348, -0.018109573051333427, -1.2329301834106445, -0.0005461869877763093, -0.001280679483897984, -0.6086601614952087, -0.6257649660110474, -0.6946520209312439, -0.00028975578607060015, -0.023415477946400642, -1.0414952039718628, -0.5640149116516113, -0.15413634479045868, -0.40352529287338257, -0.2264421135187149, -0.0017034795600920916, -0.0004885195521637797, -0.019189778715372086, -0.0017847575945779681, -0.00020037073409184813, -0.00015198028995655477, -0.47579729557037354, -0.5047392845153809, -0.00013124081306159496, -0.46045899391174316, -0.4059118926525116]}, {"prompt": "Write a SQL query selecting the top 5 customers by total order value from tables customers(id,name) and orders(id,customer_id,value).", "tokens": [" Show", " name", " and", " total", "_value", ".\n\n", "Key", " Concept", "\n\n", "SQL", " query", "\n\n", "Write", " a", " SQL", " query", " to", " retrieve", " data", " from", " multiple", " tables", ".\n\n", "Basic", " Answer", "\n\n", "Problem", " Analysis", ":\n\n", "Problem", " Type", ":", " SQL", " Query", " Construction", "\n\n", "Input", "/", "Output", " Specifications", ":", " Input", " consists", " of", " two", " tables", ":", " `", "customers", "(id"], "token_logprobs": [-1.7412843704223633, -0.7169070839881897, -0.019785895943641663, -0.019124170765280724, -0.5549339652061462, -0.8705314993858337, -2.021120548248291, -0.5813575387001038, -0.00045408427831716835, -0.02357267402112484, -0.6645888090133667, -0.05320630967617035, -1.0110276937484741, -0.05475207790732384, -0.005284981802105904, -0.0024142900947481394, -0.23290647566318512, -0.35716134309768677, -0.312810480594635, -0.6364868879318237, -0.46962887048721313, -3.755022044060752e-05, -0.3974932134151459, -0.17063754796981812, -0.00011538793478393927, -0.0003864018653985113, -0.708624005317688, -0.0015023384476080537, -0.010401562787592411, -0.5868915915489197, -0.0006353028584271669, -0.0053011090494692326, -0.011467376723885536, -0.2073754370212555, -0.7498971223831177, -0.14878760278224945, -0.0005765683017671108, -0.18576151132583618, -0.0002821285743266344, -0.014558868482708931, -0.16984885931015015, -0.13761208951473236, -0.6304841041564941, -2.95634672511369e-05, -0.027029382064938545, -0.010522598400712013, -0.18062888085842133, -0.16078151762485504, -0.00024768622824922204, -0.45264387130737305]}, {"prompt": "What is the derivative of x^3 + 2x with respect to x?", "tokens": [" A", ")", " ", "3", "x", "^", "2", " +", " ", "2", " B", ")", " ", "3", "x", "^", "2", " +", " ", "2", "x", " C", ")", " ", "3", "x", "^", "2", " D", ")", " ", "3", "x", " +", " ", "2", "\n\n", "The", " derivative", " of", " x", "^", "3", " +", " ", "2", "x", " with", " respect", " to"], "token_logprobs": [-1.5944575071334839, -0.05725596100091934, -0.07979963719844818, -0.007053356617689133, -0.013282505795359612, -0.023178357630968094, -0.004207212012261152, -0.46354299783706665, -0.06884685158729553, -0.03887399286031723, -0.6159241199493408, -0.023583386093378067, -0.1507594883441925, -0.05638807639479637, -0.008161172270774841, -0.195260152220726, -0.025988280773162842, -0.5220953226089478, -0.0061931367963552475, -0.02445274591445923, -0.012877283617854118, -0.0049278708174824715, -0.0012722263345494866, -0.25282856822013855, -0.08099863678216934, -0.0036814315244555473, -0.1732884645462036, -0.018786007538437843, -0.32611575722694397, -0.0019019624451175332, -0.2527478337287903, -0.4061877429485321, -0.008816837333142757, -0.8998973369598389, -0.0008470999309793115, -0.0007996936910785735, -0.05400592088699341, -1.659879446029663, -0.17039790749549866, -0.009593102149665356, -0.4219285845756531, -0.013264271430671215, -0.0038353470154106617, -0.10990472137928009, -6.389413465512916e-05, -0.0001429217227268964, -0.0005138983833603561, -0.20696669816970825, -2.5748875486897305e-05, -1.9788545614574105e-05]}, {"prompt": "Name the chemical symbol for gold and the element with atomic number 6.", "tokens": [" Also", ",", " what", " is", " the", " chemical", " symbol", " for", " potassium", "?\n\n", "Under", "stand", " the", " Problem", "\n\n", "The", " question", " is", " asking", " for", " the", " chemical", " symbols", " of", " specific", " elements", ":", " gold", ",", " the", " element", " with", " atomic", " number", " ", "6", ",", " and", " potassium", ".", " It", " requires", " knowledge", " of", " the", " periodic", " table", ".\n\n", "Answer", "\n\n"], "token_logprobs": [-2.0155763626098633, -0.10166452080011368, -1.6660900115966797, -0.39350152015686035, -0.15042315423488617, -1.8658961057662964, -0.21612761914730072, -0.041894037276506424, -1.416043758392334, -0.5321013331413269, -1.3154377937316895, -0.0019223083509132266, -0.00013982271775603294, -0.0022652698680758476, -4.3748852476710454e-05, -0.003725613234564662, -0.031966909766197205, -0.14286720752716064, -0.006652470678091049, -0.14620928466320038, -0.4131415784358978, -0.010491691529750824, -0.5784404277801514, -0.24753810465335846, -0.9235640168190002, -0.0029743739869445562, -0.2060442417860031, -0.00978908035904169, -0.06436231732368469, -0.6872923374176025, -0.002315698890015483, -0.0018553201807662845, -0.004170055501163006, -3.814624506048858e-05, -7.509902934543788e-05, -7.998623186722398e-05, -0.5767382979393005, -0.008434033952653408, -0.003410596400499344, -0.19361397624015808, -1.1016932725906372, -0.5897455811500549, -0.7072017788887024, -0.009304258041083813, -0.16426433622837067, -0.0014730566181242466, -4.410734163684538e-06, -0.642660915851593, -0.00014518637908622622, -1.156323378381785e-05]}], "scored": [{"text": "The mitochondrion is the powerhouse of the cell, converting ", "prompt_logprobs": [null, {"53582": {"logprob": -11.922040939331055, "rank": 19527}, "154822": {"logprob": -4.711103439331055, "rank": 1}}, {"81": {"logprob": -0.8295952081680298, "rank": 2}, "4204": {"logprob": -0.5795952081680298, "rank": 1}}, {"290": {"logprob": -9.179073458653875e-06, "rank": 1}}, {"374": {"logprob": -0.6459322571754456, "rank": 1}}, {"279": {"logprob": -1.1027772426605225, "rank": 2}, "264": {"logprob": -1.1027772426605225, "rank": 1}}, {"73538": {"logprob": -3.106271982192993, "rank": 3}, "1240": {"logprob": -0.35627201199531555, "rank": 1}}, {"315": {"logprob": -0.06489021331071854, "rank": 1}}, {"279": {"logprob": -0.040618229657411575, "rank": 1}}, {"2779": {"logprob": -0.01888088323175907, "rank": 1}}, {"11": {"logprob": -1.3736138343811035, "rank": 2}, "13": {"logprob": -0.8736138343811035, "rank": 1}}, {"33277": {"logprob": -2.927035331726074, "rank": 6}, "323": {"logprob": -1.4270352125167847, "rank": 1}}, {"36209": {"logprob": -0.9653592109680176, "rank": 1}}, {"1119": {"logprob": -0.1414087563753128, "rank": 1}}, {"993": {"logprob": -2.644946813583374, "rank": 3}, "66072": {"logprob": -0.519946813583374, "rank": 1}}, {"70338": {"logprob": -7.64102369430475e-05, "rank": 1}}, {"482": {"logprob": -4.60137271147687e-05, "rank": 1}}, {"2406": {"logprob": -0.006253319326788187, "rank": 1}}, {"759": {"logprob": -0.0017754758009687066, "rank": 1}}, {"91597": {"logprob": -8.427741704508662e-05, "rank": 1}}, {"1526": {"logprob": -4.395354747772217, "rank": 2}, "320": {"logprob": -0.020354675129055977, "rank": 1}}, {"77673": {"logprob": -0.9773801565170288, "rank": 2}, "34423": {"logprob": -0.8523801565170288, "rank": 1}}, {"93199": {"logprob": -0.007886935956776142, "rank": 1}}, {"2302": {"logprob": -8.368142152903602e-05, "rank": 1}}, {"13": {"logprob": -0.6074341535568237, "rank": 1}}, {"1096": {"logprob": -2.2608704566955566, "rank": 3}, "21714": {"logprob": -1.3233704566955566, "rank": 1}}, {"1882": {"logprob": -0.4683040678501129, "rank": 1}}, {"13657": {"logprob": -3.583826780319214, "rank": 6}, "33482": {"logprob": -1.0838267803192139, "rank": 1}}, {"3941": {"logprob": -1.5542473793029785, "rank": 1}}, {"279": {"logprob": -0.12049098312854767, "rank": 1}}, {"9176": {"logprob": -0.15709643065929413, "rank": 1}}, {"70428": {"logprob": -0.2582826316356659, "rank": 1}}, {"38346": {"logprob": -0.13131451606750488, "rank": 1}}, {"11": {"logprob": -0.6781489849090576, "rank": 1}}, {"1380": {"logprob": -2.1387040615081787, "rank": 3}, "892": {"logprob": -0.6387040615081787, "rank": 1}}, {"279": {"logprob": -0.5551042556762695, "rank": 1}}, {"16698": {"logprob": -0.3808964192867279, "rank": 1}}, {"7557": {"logprob": -0.0027291453443467617, "rank": 1}}, {"8780": {"logprob": -0.0008891443139873445, "rank": 1}}, {"63111": {"logprob": -2.470587730407715, "rank": 5}, "323": {"logprob": -1.5955877304077148, "rank": 1}}, {"264": {"logprob": -0.1412690430879593, "rank": 1}}, {"80822": {"logprob": -0.009124485775828362, "rank": 1}}, {"20129": {"logprob": -0.0744018703699112, "rank": 1}}, {"13": {"logprob": -1.691678524017334, "rank": 2}, "429": {"logprob": -0.816678524017334, "rank": 1}}]}, {"text": "def quicksort(arr):\n if len(arr) <= 1:\n return arr", "prompt_logprobs": [null, {"3974": {"logprob": -4.449723720550537, "rank": 16}, "1760": {"logprob": -3.262223720550537, "rank": 1}}, {"6860": {"logprob": -0.4935719966888428, "rank": 1}}, {"10934": {"logprob": -0.37234917283058167, "rank": 1}}, {"982": {"logprob": -0.5229650735855103, "rank": 1}}, {"262": {"logprob": -0.1639808714389801, "rank": 1}}, {"421": {"logprob": -0.1277536302804947, "rank": 1}}, {"2422": {"logprob": -0.1302429437637329, "rank": 1}}, {"10934": {"logprob": -0.0006017066189087927, "rank": 1}}, {"8": {"logprob": -0.015007800422608852, "rank": 1}}, {"2651": {"logprob": -0.036407049745321274, "rank": 1}}, {"220": {"logprob": -0.007719329092651606, "rank": 1}}, {"16": {"logprob": -0.0002826052950695157, "rank": 1}}, {"510": {"logprob": -0.00797066930681467, "rank": 1}}, {"286": {"logprob": -0.00042167355422861874, "rank": 1}}, {"470": {"logprob": -0.00019202772818971425, "rank": 1}}, {"2890": {"logprob": -0.0007681279676035047, "rank": 1}}, {"198": {"logprob": -0.10040564090013504, "rank": 1}}, {"262": {"logprob": -0.0007936188485473394, "rank": 1}}, {"25964": {"logprob": -0.1372290998697281, "rank": 1}}, {"284": {"logprob": -0.006115652155131102, "rank": 1}}, {"2890": {"logprob": -0.000734178873244673, "rank": 1}}, {"24617": {"logprob": -0.15358063578605652, "rank": 1}}, {"10934": {"logprob": -5.8053239627042785e-05, "rank": 1}}, {"8": {"logprob": -0.09064149111509323, "rank": 1}}, {"442": {"logprob": -0.024767601862549782, "rank": 1}}, {"220": {"logprob": -0.0007381098694168031, "rank": 1}}, {"17": {"logprob": -7.557583012385294e-05, "rank": 1}}, {"921": {"logprob": -0.02795916609466076, "rank": 1}}, {"262": {"logprob": -0.0008369756978936493, "rank": 1}}, {"2115": {"logprob": -0.02689431421458721, "rank": 1}}, {"284": {"logprob": -0.002852777484804392, "rank": 1}}, {"508": {"logprob": -0.0035253537353128195, "rank": 1}}, {"87": {"logprob": -0.0005697772721759975, "rank": 1}}, {"369": {"logprob": -0.0008541273418813944, "rank": 1}}, {"856": {"logprob": -2.3007127310847864e-05, "rank": 1}}, {"304": {"logprob": -4.5298504119273275e-05, "rank": 1}}, {"2890": {"logprob": -6.83045873302035e-05, "rank": 1}}, {"421": {"logprob": -0.0002954761730507016, "rank": 1}}, {"856": {"logprob": -0.00012766500003635883, "rank": 1}}, {"366": {"logprob": -0.00023755589791107923, "rank": 1}}, {"25964": {"logprob": -0.00010918975021922961, "rank": 1}}, {"921": {"logprob": -0.012729343958199024, "rank": 1}}, {"262": {"logprob": -4.0649541915627196e-05, "rank": 1}}, {"6149": {"logprob": -0.024306857958436012, "rank": 1}}, {"284": {"logprob": -0.00043501926120370626, "rank": 1}}, {"508": {"logprob": -7.784063927829266e-05, "rank": 1}}, {"87": {"logprob": -9.238292841473594e-05, "rank": 1}}, {"369": {"logprob": -3.4689302992774174e-05, "rank": 1}}, {"856": {"logprob": -5.006777428206988e-06, "rank": 1}}, {"304": {"logprob": -3.659658250398934e-05, "rank": 1}}, {"2890": {"logprob": -1.490105023549404e-05, "rank": 1}}, {"421": {"logprob": -0.000358159770257771, "rank": 1}}, {"856": {"logprob": -1.645074735279195e-05, "rank": 1}}, {"621": {"logprob": -0.00024279984063468874, "rank": 1}}, {"25964": {"logprob": -7.557583012385294e-05, "rank": 1}}, {"921": {"logprob": -0.002313201315701008, "rank": 1}}, {"262": {"logprob": -0.00011848701251437888, "rank": 1}}, {"1290": {"logprob": -0.0009632238652557135, "rank": 1}}, {"284": {"logprob": -0.00021336186910048127, "rank": 1}}, {"508": {"logprob": -0.0003196682082489133, "rank": 1}}, {"87": {"logprob": -0.000426439888542518, "rank": 1}}, {"369": {"logprob": -5.4834770708112046e-05, "rank": 1}}, {"856": {"logprob": -1.7404405298293568e-05, "rank": 1}}, {"304": {"logprob": -1.1444026313256472e-05, "rank": 1}}, {"2890": {"logprob": -0.0002302858338225633, "rank": 1}}, {"421": {"logprob": -0.0001629458274692297, "rank": 1}}, {"856": {"logprob": -2.396077979938127e-05, "rank": 1}}, {"861": {"logprob": -5.900685573578812e-05, "rank": 1}}, {"25964": {"logprob": -0.00010239553375868127, "rank": 1}}, {"921": {"logprob": -0.007368648424744606, "rank": 1}}, {"262": {"logprob": -0.0007203606073744595, "rank": 1}}, {"470": {"logprob": -0.004490411374717951, "rank": 1}}, {"3974": {"logprob": -0.005435924045741558, "rank": 1}}, {"6860": {"logprob": -4.2676016164477915e-05, "rank": 1}}, {"17646": {"logprob": -0.003262556390836835, "rank": 1}}, {"8": {"logprob": -0.00028725311858579516, "rank": 1}}, {"488": {"logprob": -2.7179348762729205e-05, "rank": 1}}, {"6149": {"logprob": -0.1005512997508049, "rank": 1}}, {"488": {"logprob": -5.638440416078083e-05, "rank": 1}}, {"3974": {"logprob": -0.0038856971077620983, "rank": 1}}, {"6860": {"logprob": -1.4424220353248529e-05, "rank": 1}}, {"27611": {"logprob": -0.0005211663665249944, "rank": 1}}, {"8": {"logprob": -3.7821779251098633, "rank": 4}, "692": {"logprob": -0.2821778357028961, "rank": 1}}]}, {"text": "In 1969, the Apollo 11 mission successfully landed the first", "prompt_logprobs": [null, {"220": {"logprob": -6.208653926849365, "rank": 14}, "314": {"logprob": -5.021153926849365, "rank": 1}}, {"121818": {"logprob": -9.52942943572998, "rank": 440}, "220": {"logprob": -1.0919296741485596, "rank": 1}}, {"24": {"logprob": -2.050053358078003, "rank": 2}, "17": {"logprob": -1.800053358078003, "rank": 1}}, {"11": {"logprob": -0.3165985941886902, "rank": 1}}, {"279": {"logprob": -1.9090681076049805, "rank": 1}}, {"34976": {"logprob": -2.702807903289795, "rank": 2}, "356": {"logprob": -1.890307903289795, "rank": 1}}, {"220": {"logprob": -0.23287898302078247, "rank": 1}}, {"98965": {"logprob": -0.2566189169883728, "rank": 1}}, {"8951": {"logprob": -0.9037951827049255, "rank": 1}}, {"7790": {"logprob": -2.8613624572753906, "rank": 5}, "26039": {"logprob": -1.1113625764846802, "rank": 1}}, {"26039": {"logprob": -0.1891137659549713, "rank": 1}}, {"279": {"logprob": -1.592130184173584, "rank": 2}, "12671": {"logprob": -0.717130184173584, "rank": 1}}, {"1156": {"logprob": -0.013842063024640083, "rank": 1}}, {"12671": {"logprob": -0.1554824858903885, "rank": 1}}, {"389": {"logprob": -0.015862351283431053, "rank": 1}}, {"279": {"logprob": -0.0019161213422194123, "rank": 1}}, {"17309": {"logprob": -0.4793456792831421, "rank": 1}}, {"13": {"logprob": -0.43903154134750366, "rank": 1}}, {"32962": {"logprob": -2.1498584747314453, "rank": 3}, "1096": {"logprob": -1.2123583555221558, "rank": 1}}, {"44605": {"logprob": -0.0063511673361063, "rank": 1}}, {"323": {"logprob": -0.28968068957328796, "rank": 1}}, {"37754": {"logprob": -0.14665082097053528, "rank": 1}}, {"30230": {"logprob": -0.00028606137493625283, "rank": 1}}, {"25210": {"logprob": -0.00013004888023715466, "rank": 1}}, {"7391": {"logprob": -1.4673173427581787, "rank": 2}, "6116": {"logprob": -1.2173173427581787, "rank": 1}}, {"13179": {"logprob": -2.1032395362854004, "rank": 4}, "220": {"logprob": -1.2282394170761108, "rank": 1}}, {"1378": {"logprob": -3.178372383117676, "rank": 2}, "220": {"logprob": -0.0533723421394825, "rank": 1}}, {"323": {"logprob": -0.3623727858066559, "rank": 1}}, {"264": {"logprob": -0.006554414983838797, "rank": 1}}, {"8337": {"logprob": -8.064005851745605, "rank": 3}, "4279": {"logprob": -0.001505433232523501, "rank": 1}}, {"4115": {"logprob": -0.005899872165173292, "rank": 1}}, {"4889": {"logprob": -2.83845853805542, "rank": 3}, "389": {"logprob": -0.46345847845077515, "rank": 1}}, {"279": {"logprob": -0.11783696711063385, "rank": 1}}, {"41305": {"logprob": -0.2105509638786316, "rank": 1}}, {"11": {"logprob": -0.5777708292007446, "rank": 1}}, {"25814": {"logprob": -2.6614980697631836, "rank": 3}, "1393": {"logprob": -0.411498099565506, "rank": 1}}, {"56329": {"logprob": -1.016498327255249, "rank": 2}, "10464": {"logprob": -0.891498327255249, "rank": 1}}, {"3684": {"logprob": -3.3936514854431152, "rank": 4}, "10464": {"logprob": -0.14365145564079285, "rank": 1}}, {"311": {"logprob": -3.583463430404663, "rank": 4}, "323": {"logprob": -0.3334634602069855, "rank": 1}}, {"4446": {"logprob": -0.008997136726975441, "rank": 1}}, {"1182": {"logprob": -0.003895434318110347, "rank": 1}}, {"311": {"logprob": -0.14708548784255981, "rank": 1}}, {"9234": {"logprob": -0.0021491781808435917, "rank": 1}}, {"13": {"logprob": -0.38070181012153625, "rank": 1}}]}, {"text": "Le petit prince demanda au renard ce que signifiait le mot a", "prompt_logprobs": [null, {"44744": {"logprob": -12.63610553741455, "rank": 44769}, "154822": {"logprob": -2.86657452583313, "rank": 1}}, {"41490": {"logprob": -0.9462587833404541, "rank": 1}}, {"137474": {"logprob": -13.022157669067383, "rank": 7574}, "320": {"logprob": -2.7096574306488037, "rank": 1}}, {"7906": {"logprob": -6.202425479888916, "rank": 17}, "549": {"logprob": -1.3899253606796265, "rank": 1}}, {"5672": {"logprob": -6.6236042976379395, "rank": 38}, "12955": {"logprob": -1.5611042976379395, "rank": 1}}, {"567": {"logprob": -0.003742002882063389, "rank": 1}}, {"3761": {"logprob": -4.859536170959473, "rank": 18}, "25": {"logprob": -1.6720362901687622, "rank": 1}}, {"1709": {"logprob": -0.410189151763916, "rank": 1}}, {"1841": {"logprob": -0.668915331363678, "rank": 1}}, {"333": {"logprob": -0.021018855273723602, "rank": 1}}, {"685": {"logprob": -0.006669404450803995, "rank": 1}}, {"275": {"logprob": -0.016423985362052917, "rank": 1}}, {"512": {"logprob": -1.1903163194656372, "rank": 1}}, {"3852": {"logprob": -0.01635456085205078, "rank": 1}}, {"131231": {"logprob": -1.8878552913665771, "rank": 3}, "12480": {"logprob": -1.0753552913665771, "rank": 1}}, {"6496": {"logprob": -4.0649541915627196e-05, "rank": 1}}, {"12053": {"logprob": -0.09761586785316467, "rank": 1}}, {"13": {"logprob": -1.3712267875671387, "rank": 1}}, {"1967": {"logprob": -1.791018009185791, "rank": 1}}, {"5672": {"logprob": -0.035116855055093765, "rank": 1}}, {"567": {"logprob": -4.7444173105759546e-05, "rank": 1}}, {"3247": {"logprob": -4.059698104858398, "rank": 4}, "24324": {"logprob": -0.30969831347465515, "rank": 1}}, {"5011": {"logprob": -0.0001250427303602919, "rank": 1}}, {"64": {"logprob": -0.0004391897819004953, "rank": 1}}, {"1709": {"logprob": -0.651698887348175, "rank": 1}}, {"44244": {"logprob": -0.7026461958885193, "rank": 1}}, {"1841": {"logprob": -0.4766460657119751, "rank": 1}}, {"333": {"logprob": -0.00014447122521232814, "rank": 1}}, {"685": {"logprob": -0.0014467497821897268, "rank": 1}}, {"275": {"logprob": -0.00021741411183029413, "rank": 1}}, {"1884": {"logprob": -9.278042793273926, "rank": 46}, "74145": {"logprob": -0.27804288268089294, "rank": 1}}, {"261": {"logprob": -0.009656503796577454, "rank": 1}}, {"939": {"logprob": -0.0011544713051989675, "rank": 1}}, {"151101": {"logprob": -0.0026007420383393764, "rank": 1}}, {"11": {"logprob": -1.8432267904281616, "rank": 2}, "13": {"logprob": -0.5932267904281616, "rank": 1}}, {"1842": {"logprob": -1.5929813385009766, "rank": 1}}, {"1709": {"logprob": -0.8842247724533081, "rank": 1}}, {"4403": {"logprob": -3.830415725708008, "rank": 11}, "3541": {"logprob": -1.7679158449172974, "rank": 1}}, {"512": {"logprob": -1.878219485282898, "rank": 4}, "389": {"logprob": -1.315719485282898, "rank": 1}}, {"41490": {"logprob": -3.2642438411712646, "rank": 2}, "44744": {"logprob": -0.07674393802881241, "rank": 1}}, {"326": {"logprob": -1.5530779361724854, "rank": 2}, "11203": {"logprob": -0.6780778765678406, "rank": 1}}, {"6": {"logprob": -0.030124684795737267, "rank": 1}}, {"138865": {"logprob": -0.0473979189991951, "rank": 1}}, {"6496": {"logprob": -0.02706070989370346, "rank": 1}}, {"285": {"logprob": -0.0003430254873819649, "rank": 1}}, {"1315": {"logprob": -0.0008181562297977507, "rank": 1}}, {"11": {"logprob": -0.03445449098944664, "rank": 1}}, {"44786": {"logprob": -0.41375118494033813, "rank": 1}}, {"38832": {"logprob": -1.035122275352478, "rank": 1}}, {"1167": {"logprob": -0.00020549570035655051, "rank": 1}}, {"62129": {"logprob": -0.21618129312992096, "rank": 1}}, {"326": {"logprob": -0.007741567678749561, "rank": 1}}, {"21997": {"logprob": -0.014529849402606487, "rank": 1}}, {"409": {"logprob": -0.054837729781866074, "rank": 1}}, {"326": {"logprob": -0.0026894372422248125, "rank": 1}}, {"48052": {"logprob": -0.0012055517872795463, "rank": 1}}, {"265": {"logprob": -0.0002557904226705432, "rank": 1}}, {"13": {"logprob": -2.6397721767425537, "rank": 2}, "1842": {"logprob": -0.13977208733558655, "rank": 1}}]}, {"text": "The gradient of the loss function with respect to the weight", "prompt_logprobs": [null, {"20129": {"logprob": -8.929853439331055, "rank": 975}, "154822": {"logprob": -4.711103439331055, "rank": 1}}, {"315": {"logprob": -0.8434014320373535, "rank": 1}}, {"279": {"logprob": -0.8529768586158752, "rank": 2}, "264": {"logprob": -0.8529768586158752, "rank": 1}}, {"4709": {"logprob": -5.461456298828125, "rank": 13}, "729": {"logprob": -0.773956298828125, "rank": 1}}, {"729": {"logprob": -0.34525054693222046, "rank": 1}}, {"448": {"logprob": -1.2351714372634888, "rank": 1}}, {"5091": {"logprob": -0.007803904823958874, "rank": 1}}, {"311": {"logprob": -0.0007889734115451574, "rank": 1}}, {"279": {"logprob": -0.39285874366760254, "rank": 1}}, {"14314": {"logprob": -1.0512843132019043, "rank": 1}}, {"374": {"logprob": -1.0378243923187256, "rank": 1}}, {"24113": {"logprob": -2.437234401702881, "rank": 3}, "264": {"logprob": -1.3122344017028809, "rank": 1}}, {"4566": {"logprob": -3.0449869632720947, "rank": 5}, "1667": {"logprob": -0.79498690366745, "rank": 1}}, {"1182": {"logprob": -0.36877167224884033, "rank": 1}}, {"2674": {"logprob": -0.02516896463930607, "rank": 1}}, {"27048": {"logprob": -0.007283680606633425, "rank": 1}}, {"11": {"logprob": -1.1153569221496582, "rank": 1}}, {"18915": {"logprob": -4.563106536865234, "rank": 10}, "892": {"logprob": -0.8131066560745239, "rank": 1}}, {"279": {"logprob": -0.005665080156177282, "rank": 1}}, {"8780": {"logprob": -0.0062430123798549175, "rank": 1}}, {"5912": {"logprob": -0.0008057684754021466, "rank": 1}}, {"6193": {"logprob": -0.9492177963256836, "rank": 1}}, {"553": {"logprob": -0.015497731044888496, "rank": 1}}, {"6193": {"logprob": -0.0004687402688432485, "rank": 1}}, {"504": {"logprob": -1.3893572092056274, "rank": 2}, "13": {"logprob": -0.7643572092056274, "rank": 1}}, {"279": {"logprob": -0.08988732099533081, "rank": 1}}, {"2550": {"logprob": -0.01756012998521328, "rank": 1}}, {"1182": {"logprob": -0.18666112422943115, "rank": 1}}, {"311": {"logprob": -0.03809535130858421, "rank": 1}}, {"279": {"logprob": -0.009112554602324963, "rank": 1}}, {"1946": {"logprob": -0.020355259999632835, "rank": 1}}, {"13": {"logprob": -0.45089805126190186, "rank": 1}}, {"794": {"logprob": -7.581850051879883, "rank": 73}, "1096": {"logprob": -1.1443498134613037, "rank": 1}}, {"65474": {"logprob": -0.01450047641992569, "rank": 1}}, {"20129": {"logprob": -1.4351179599761963, "rank": 2}, "52755": {"logprob": -0.3101179599761963, "rank": 1}}, {"36760": {"logprob": -0.002448301063850522, "rank": 1}}, {"1221": {"logprob": -2.9529736042022705, "rank": 5}, "320": {"logprob": -0.45297354459762573, "rank": 1}}, {"8836": {"logprob": -0.10355337709188461, "rank": 1}}, {"1817": {"logprob": -1.4208792448043823, "rank": 2}, "279": {"logprob": -0.29587921500205994, "rank": 1}}, {"4680": {"logprob": -0.10474679619073868, "rank": 1}}, {"21070": {"logprob": -5.917784690856934, "rank": 24}, "553": {"logprob": -1.1677848100662231, "rank": 1}}, {"745": {"logprob": -0.004588313400745392, "rank": 1}}, {"13": {"logprob": -7.754643440246582, "rank": 6}, "311": {"logprob": -0.004643371794372797, "rank": 1}}]}]}
scripts/results-base.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"port": 18998, "model": "glm-fp8attn-base", "arith_correct": true, "arith_raw": "391", "long_gen_tokens": 2400, "long_gen_degenerate": false, "long_gen_tail": "", "greedy": [{"prompt": "What is 17*23? Answer with just the number.", "tokens": [" No", " steps", ".\n\n", "17", "*", "23", " =", " ", "39", "1", "\n\n", "What", " is", " ", "17", "*", "23", "?", " Answer", " with", " just", " the", " number", ".", " No", " steps", ".\n\n", "17", "*", "23", " =", " ", "39", "1", "\n\n", "What", " is", " ", "17", "*", "23", "?", " Answer", " with", " just", " the", " number", ".", " No", " steps"], "token_logprobs": [-0.7954843044281006, -1.3792524337768555, -0.8923012018203735, -1.519234538078308, -0.3318193852901459, -0.0009023646707646549, -0.2268953174352646, -0.03562337905168533, -0.0500919446349144, -0.001936228945851326, -0.6661547422409058, -1.3289430141448975, -0.10404541343450546, -0.17208032310009003, -0.7173145413398743, -0.18108612298965454, -0.051913853734731674, -0.17457455396652222, -0.06793863326311111, -0.009760631248354912, -0.007896278984844685, -0.0013723488664254546, -0.0036529258359223604, -0.015474255196750164, -0.013663692399859428, -0.0049583567306399345, -0.12601077556610107, -0.6352027654647827, -0.1328856647014618, -0.000809818331617862, -0.03420545905828476, -0.01041701715439558, -0.006588877644389868, -0.0009128456003963947, -0.04143974557518959, -0.5812287330627441, -0.08164242655038834, -0.10177209228277206, -0.19336189329624176, -0.04851158335804939, -0.003962167073041201, -0.03563936799764633, -0.0347386933863163, -0.004366625566035509, -0.007574410177767277, -0.0009559590835124254, -0.0007364421617239714, -0.007781194057315588, -0.008378238417208195, -0.0009616755996830761]}, {"prompt": "Write a Python function that returns the nth Fibonacci number iteratively.", "tokens": [" Then", ",", " write", " another", " function", " that", " returns", " the", " nth", " Fibonacci", " number", " recursively", ".", " Finally", ",", " write", " a", " third", " function", " that", " returns", " the", " nth", " Fibonacci", " number", " using", " memo", "ization", ".\n\n", "```", "python", "\n", "#", " Iter", "ative", " Fibonacci", " function", "\n", "def", " fibonacci", "_iter", "ative", "(n", "):\n", " ", " a", ",", " b", " =", " "], "token_logprobs": [-1.6434892416000366, -0.9371449947357178, -0.6478077173233032, -0.6087609529495239, -0.028878703713417053, -0.6090443730354309, -0.7285573482513428, -0.400341659784317, -0.26828649640083313, -0.07403828203678131, -0.0056958990171551704, -0.06270158290863037, -0.3978736400604248, -1.638857126235962, -0.0037520977202802896, -0.44121015071868896, -0.1505894958972931, -0.8687252998352051, -0.007234448567032814, -0.021169191226363182, -1.2010337114334106, -0.06959781050682068, -0.037812214344739914, -0.013777866959571838, -0.0009217780898325145, -0.34697413444519043, -0.4509808123111725, -0.0003815161471720785, -0.7622365951538086, -2.0443100929260254, -0.010528850369155407, -0.008007921278476715, -0.605451762676239, -0.19750574231147766, -0.11380360275506973, -1.2685909271240234, -0.8510158658027649, -0.2427232414484024, -0.010517762042582035, -0.8140695691108704, -0.010436954908072948, -0.004059052560478449, -0.00037305548903532326, -0.008768389001488686, -0.0135618532076478, -0.9471744298934937, -0.08977857232093811, -5.483612312673358e-06, -0.0001110968878492713, -1.2159273865108844e-05]}, {"prompt": "Explain the difference between TCP and UDP in two sentences.", "tokens": [" TCP", " is", " a", " connection", "-oriented", " protocol", " that", " guarantees", " reliable", " delivery", " of", " data", ",", " while", " UDP", " is", " a", " connection", "less", " protocol", " that", " does", " not", " guarantee", " delivery", " but", " is", " faster", ".", " TCP", " is", " used", " for", " applications", " that", " require", " reliability", ",", " such", " as", " file", " transfer", " and", " web", " browsing", ",", " while", " UDP", " is", " used"], "token_logprobs": [-2.241055965423584, -0.35642603039741516, -0.6483486890792847, -0.08319029957056046, -0.09721973538398743, -0.05736571550369263, -0.09674477577209473, -0.8544560670852661, -0.7154983282089233, -1.0324149131774902, -0.4558160603046417, -0.12958823144435883, -0.7910364866256714, -0.06230056285858154, -0.001730612595565617, -0.0013983005192130804, -0.2536924183368683, -0.007034653797745705, -0.005045182537287474, -0.006692495197057724, -0.07791771739721298, -0.9328421950340271, -0.0024409282486885786, -0.05086459219455719, -0.6707823872566223, -1.067812204360962, -0.19879361987113953, -0.003691764548420906, -0.8286463022232056, -0.5746944546699524, -0.23479124903678894, -0.6291559934616089, -0.055894333869218826, -0.02666451781988144, -0.6518598794937134, -0.024912375956773758, -0.7934842705726624, -0.04727228358387947, -0.0974082499742508, -0.0004619484825525433, -0.5409557223320007, -0.39112579822540283, -0.07622093707323074, -0.5257143974304199, -0.0007706294418312609, -0.05404522269964218, -0.0009111781837418675, -0.001655637752264738, -0.000536655425094068, -0.0020295039284974337]}, {"prompt": "Translate to French: 'The quick brown fox jumps over the lazy dog.'", "tokens": [" '", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".'", " '", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".'", " '", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".'", " '", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".'", " '", "The", " quick", " brown", " fox", " jumps"], "token_logprobs": [-1.5404739379882812, -0.09568878263235092, -0.3964388966560364, -0.005029051564633846, -0.00639961427077651, -0.05629534274339676, -0.0005080600967630744, -0.000296310376143083, -0.0012997282901778817, -0.0008056493825279176, -0.2808052897453308, -0.2386549711227417, -0.06094881892204285, -0.08547151833772659, -0.001320324488915503, -0.0022093667648732662, -0.003726682160049677, -0.00026592056383378804, -0.0009173714206553996, -0.0011625682236626744, -0.00039402826223522425, -0.11324162036180496, -0.08280443400144577, -0.0041139028035104275, -0.009717423468828201, -0.0018215269083157182, -0.0009371418273076415, -0.0006968930247239769, -0.000931663322262466, -0.002863594563677907, -0.00042429505265317857, -0.002447825390845537, -0.16000714898109436, -0.07294760644435883, -0.004622013308107853, -0.009443612769246101, -0.000795762927737087, -0.0010053823934867978, -0.0011485177092254162, -0.0004555141495075077, -0.0007905219099484384, -0.0027159492019563913, -0.0011853104224428535, -0.07770806550979614, -0.05550060793757439, -0.002574821701273322, -0.008324803784489632, -0.003352381056174636, -0.0014680571621283889, -0.001420085085555911]}, {"prompt": "List the first 8 prime numbers separated by commas.", "tokens": [" ", "2", ",", " ", "3", ",", " ", "5", ",", " ", "7", ",", " ", "11", ",", " ", "13", ",", " ", "17", ",", " ", "19", "\n\n", "2", ",", " ", "3", ",", " ", "5", ",", " ", "7", ",", " ", "11", ",", " ", "13", ",", " ", "17", ",", " ", "19", "\n\n", "2", ",", " "], "token_logprobs": [-1.4870697259902954, -0.22236944735050201, -0.06852153688669205, -0.28657999634742737, -0.014090458862483501, -0.014295312575995922, -0.012846332974731922, -0.009742332622408867, -0.030552230775356293, -0.03746148198843002, -0.017808306962251663, -0.05470411106944084, -0.029842637479305267, -0.02507968246936798, -0.023960433900356293, -0.013344968669116497, -0.002385748317465186, -0.12177909910678864, -0.019063003361225128, -0.00571427121758461, -0.02487039938569069, -0.008981778286397457, -0.005957346875220537, -0.8325784802436829, -2.187727451324463, -0.30473122000694275, -0.0046797990798950195, -0.0038220465648919344, -0.001281870063394308, -0.00021991695393808186, -0.0007226239540614188, -0.00119138287845999, -0.00024959311122074723, -0.0032482976093888283, -0.005473982077091932, -0.0002588890492916107, -0.0029906569980084896, -0.00163588160648942, -0.0001370812824461609, -0.0006158839096315205, -0.0009560781763866544, -0.00019786784832831472, -0.0003680505615193397, -0.0038519722875207663, -0.0007466865936294198, -0.0011756658786907792, -0.05833902582526207, -0.828909158706665, -0.028335725888609886, -0.0013637775555253029]}, {"prompt": "What year did the Apollo 11 mission land on the moon? One word answer.", "tokens": [" ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196"], "token_logprobs": [-2.659794330596924, -0.37120819091796875, -0.031042812392115593, -0.9424886703491211, -1.6484146118164062, -0.266952246427536, -0.16953285038471222, -0.3360818922519684, -1.0676932334899902, -0.0711066946387291, -0.028486358001828194, -0.08347294479608536, -0.25503069162368774, -0.027141809463500977, -0.03144628554582596, -0.04943636432290077, -0.24226386845111847, -0.03104720450937748, -0.021252987906336784, -0.04088226333260536, -0.17585168778896332, -0.0061860280111432076, -0.003955161664634943, -0.022459080442786217, -0.1503244787454605, -0.008958976715803146, -0.004205313045531511, -0.020039713010191917, -0.09068634361028671, -0.006199534051120281, -0.004930243361741304, -0.017970366403460503, -0.09262754023075104, -0.0048323748633265495, -0.0024257064796984196, -0.018915625289082527, -0.059133872389793396, -0.006135201547294855, -0.0018446111353114247, -0.016994446516036987, -0.05903026461601257, -0.008067049086093903, -0.0026764783542603254, -0.0153661435469985, -0.06573568284511566, -0.0033884986769407988, -0.00159327348228544, -0.014373928308486938, -0.04522976279258728, -0.0030625606887042522]}, {"prompt": "Summarize the plot of Romeo and Juliet in one sentence.", "tokens": [" Then", ",", " summarize", " the", " plot", " of", " Romeo", " and", " Juliet", " in", " one", " sentence", " from", " the", " perspective", " of", " Fri", "ar", " Lawrence", ".", " How", " does", " the", " perspective", " change", " the", " way", " the", " plot", " is", " presented", "?\n\n", "The", " chronological", " order", " of", " events", " related", " by", " the", " American", " Revolutionary", " War", " begins", " with", " the", " Boston", " Tea", " Party", " in"], "token_logprobs": [-2.4378561973571777, -0.4372206926345825, -1.6242061853408813, -0.33640503883361816, -0.18557290732860565, -0.5076525807380676, -1.390825629234314, -0.0038062522653490305, -0.0021510813385248184, -0.13436034321784973, -0.5073572397232056, -1.091217279434204, -1.467713713645935, -0.6165943741798401, -0.8297039866447449, -0.005109941121190786, -1.5151317119598389, -9.929640509653836e-05, -0.6393004059791565, -1.015494704246521, -1.7927199602127075, -1.0232521295547485, -1.0104897022247314, -1.5282419919967651, -0.557062029838562, -0.313935786485672, -0.5741245746612549, -0.42732518911361694, -0.6006355881690979, -0.02694873884320259, -1.1093043088912964, -0.5174976587295532, -2.28178071975708, -0.1918870508670807, -0.0004343043256085366, -1.311301275563892e-06, -6.735097849741578e-05, -0.815258264541626, -0.3514956533908844, -0.11264747381210327, -0.0015380469849333167, -0.0033385988790541887, -2.3841855067985307e-07, -0.0001802282058633864, -7.390948667307384e-06, -2.861018856492592e-06, -0.0002890407631639391, -0.011555053293704987, -0.05525360256433487, -0.0014990055933594704]}, {"prompt": "Write a SQL query selecting the top 5 customers by total order value from tables customers(id,name) and orders(id,customer_id,value).", "tokens": [" Show", " name", " and", " total", "_value", ".\n\n", "SQL", " Question", "\n\n", "Question", "\n\n", "Write", " a", " SQL", " query", " selecting", " the", " top", " ", "5", " customers", " by", " total", " order", " value", " from", " tables", " customers", "(id", ",name", ")", " and", " orders", "(id", ",c", "ustomer", "_id", ",value", ").", " Show", " name", " and", " total", "_value", ".\n\n", "Answer", "\n\n", "SELECT", " c", ".name"], "token_logprobs": [-1.1562331914901733, -1.3823962211608887, -0.01342801097780466, -0.017434202134609222, -0.3575667142868042, -0.8891351222991943, -2.7677602767944336, -1.4320193529129028, -0.29023945331573486, -0.3714871406555176, -0.6708351373672485, -0.02461908385157585, -0.00010108436981681734, -0.0002890407631639391, -5.090107151772827e-05, -0.0019791792146861553, -2.932505594799295e-05, -3.886147169396281e-05, -3.71926071238704e-05, -1.9073468138230965e-06, -2.6464111215318553e-05, -1.1801649634435307e-05, -2.52720492426306e-05, -7.748573807475623e-06, -4.6491513785440475e-06, -0.0022646752186119556, -0.0029264739714562893, -0.02070830576121807, -0.0006887924391776323, -0.0013754441170021892, -2.9205850296420977e-05, -3.576272320060525e-06, -3.2066785934148356e-05, -0.0001411338453181088, -0.0010110987350344658, -2.5510462364763953e-05, -2.4914430468925275e-05, -0.00026901919045485556, -0.0018920868169516325, -0.0006046851049177349, -0.0004441943601705134, -1.680836794548668e-05, -5.221230458118953e-05, -0.0005030558677390218, -0.0549725741147995, -0.8830746412277222, -0.0225512757897377, -1.0202833414077759, -0.009599241428077221, -0.3139813244342804]}, {"prompt": "What is the derivative of x^3 + 2x with respect to x?", "tokens": ["...", " |", " Fil", "o", "\n\n", "Text", " solution", "\n\n", "Explanation", "\n\n", "To", " find", " the", " derivative", " of", " the", " function", " with", " respect", " to", " ,", " we", " apply", " the", " power", " rule", " to", " each", " term", ".\n\n", "Step", "-", "By", "-", "Step", " Solution", "\n\n", "Step", " ", "1", "\n\n", "Ident", "ify", " the", " function", ":\n\n", "Step", " ", "2", "\n\n"], "token_logprobs": [-1.1664047241210938, -0.004055490717291832, -0.40659934282302856, -5.3881147323409095e-05, -0.011557410471141338, -0.3732331097126007, -0.5045691728591919, -0.364333838224411, -0.6674178838729858, -0.017209017649292946, -1.2156124114990234, -0.017708411440253258, -0.00391455227509141, -0.0005474975914694369, -0.0066054570488631725, -0.18282990157604218, -0.004375527147203684, -0.8677918314933777, -8.583032467868179e-06, -6.198863957251888e-06, -0.01165403425693512, -0.0023227159399539232, -0.4645668864250183, -0.187595397233963, -0.011250627227127552, -4.541770613286644e-05, -0.4258328378200531, -0.0008226824575103819, -2.8967437174287625e-05, -0.44421181082725525, -0.10686501115560532, -0.00014423283573705703, -0.0002252801787108183, 0.0, -8.583032467868179e-06, -0.003741765394806862, -3.099436753473128e-06, -6.580135959666222e-05, -2.145764938177308e-06, -5.960462772236497e-07, -0.0004985281848348677, -0.5401321649551392, -4.172316494077677e-06, -0.08981376886367798, -0.03869544342160225, -0.6356683373451233, -0.0004145239945501089, -1.1920928244535389e-07, -2.3841855067985307e-07, -5.781483559985645e-05]}, {"prompt": "Name the chemical symbol for gold and the element with atomic number 6.", "tokens": [" Also", ",", " what", " is", " the", " chemical", " symbol", " for", " iron", "?\n\n", "Under", "stand", " the", " Problem", "\n\n", "The", " question", " is", " asking", " for", " the", " chemical", " symbol", " of", " gold", ",", " the", " element", " with", " atomic", " number", " ", "6", ",", " and", " the", " chemical", " symbol", " for", " iron", ".", " This", " is", " a", " straightforward", " chemistry", " question", " requiring", " knowledge", " of"], "token_logprobs": [-1.8482177257537842, -0.14594301581382751, -1.618062138557434, -0.4034731388092041, -0.1470407247543335, -1.490329623222351, -0.5529917478561401, -0.06330690532922745, -1.8793104887008667, -0.5195470452308655, -1.0776314735412598, -0.002127052517607808, -0.0002026352594839409, -0.005099029745906591, -8.106198947643861e-06, -0.0007909983396530151, -0.017457162961363792, -0.26214274764060974, -0.008933811448514462, -0.18544486165046692, -0.3665526509284973, -0.010950352996587753, -0.694830060005188, -0.4800928235054016, -0.0872892513871193, -0.29917576909065247, -0.1388835310935974, -0.44005072116851807, -0.04216950386762619, -0.010177265852689743, -5.030505417380482e-05, -6.282132380874828e-05, -0.00015114595589693636, -0.008794858120381832, -0.0350789874792099, -0.009798052720725536, -0.027395622804760933, -0.0002932118659373373, -0.5231440663337708, -0.0002205128694185987, -0.32042166590690613, -0.7948513031005859, -1.0530134439468384, -0.08348730951547623, -0.7147690057754517, -0.520639181137085, -0.6835917234420776, -0.9855180978775024, -1.0270394086837769, -0.015679528936743736]}], "scored": [{"text": "The mitochondrion is the powerhouse of the cell, converting ", "prompt_logprobs": [null, {"53582": {"logprob": -12.147521018981934, "rank": 25065}, "154822": {"logprob": -4.139708518981934, "rank": 1}}, {"81": {"logprob": -1.3155796527862549, "rank": 2}, "4204": {"logprob": -0.3155796527862549, "rank": 1}}, {"290": {"logprob": -1.8715683836489916e-05, "rank": 1}}, {"374": {"logprob": -0.5796149969100952, "rank": 1}}, {"279": {"logprob": -1.1456704139709473, "rank": 2}, "264": {"logprob": -1.1456704139709473, "rank": 1}}, {"73538": {"logprob": -2.085251569747925, "rank": 2}, "1240": {"logprob": -0.4602515697479248, "rank": 1}}, {"315": {"logprob": -0.06836367398500443, "rank": 1}}, {"279": {"logprob": -0.027743525803089142, "rank": 1}}, {"2779": {"logprob": -0.017126640304923058, "rank": 1}}, {"11": {"logprob": -1.1407954692840576, "rank": 2}, "13": {"logprob": -1.0157954692840576, "rank": 1}}, {"33277": {"logprob": -3.3350720405578613, "rank": 8}, "323": {"logprob": -1.4600720405578613, "rank": 1}}, {"36209": {"logprob": -1.1102757453918457, "rank": 2}, "33063": {"logprob": -0.8602757453918457, "rank": 1}}, {"1119": {"logprob": -0.12434057146310806, "rank": 1}}, {"993": {"logprob": -2.4120209217071533, "rank": 3}, "66072": {"logprob": -0.5370209217071533, "rank": 1}}, {"70338": {"logprob": -0.00013660451804753393, "rank": 1}}, {"482": {"logprob": -9.30981186684221e-05, "rank": 1}}, {"2406": {"logprob": -0.004100012592971325, "rank": 1}}, {"759": {"logprob": -0.0017891604220494628, "rank": 1}}, {"91597": {"logprob": -0.00018499570433050394, "rank": 1}}, {"1526": {"logprob": -4.397093772888184, "rank": 2}, "320": {"logprob": -0.022093942388892174, "rank": 1}}, {"77673": {"logprob": -0.8620162010192871, "rank": 1}}, {"93199": {"logprob": -0.0024969372898340225, "rank": 1}}, {"2302": {"logprob": -0.0002040654799202457, "rank": 1}}, {"13": {"logprob": -0.5936529636383057, "rank": 1}}, {"1096": {"logprob": -2.2578372955322266, "rank": 3}, "21714": {"logprob": -1.257837176322937, "rank": 1}}, {"1882": {"logprob": -0.4387182593345642, "rank": 1}}, {"13657": {"logprob": -3.6266074180603027, "rank": 6}, "33482": {"logprob": -0.8766075372695923, "rank": 1}}, {"3941": {"logprob": -1.0599173307418823, "rank": 1}}, {"279": {"logprob": -0.11483214795589447, "rank": 1}}, {"9176": {"logprob": -0.05562363564968109, "rank": 1}}, {"70428": {"logprob": -0.18480263650417328, "rank": 1}}, {"38346": {"logprob": -0.06315919011831284, "rank": 1}}, {"11": {"logprob": -0.5546185970306396, "rank": 1}}, {"1380": {"logprob": -1.2288589477539062, "rank": 2}, "892": {"logprob": -1.2288589477539062, "rank": 1}}, {"279": {"logprob": -0.36046817898750305, "rank": 1}}, {"16698": {"logprob": -0.16178792715072632, "rank": 1}}, {"7557": {"logprob": -0.0009779914980754256, "rank": 1}}, {"8780": {"logprob": -0.0010868363315239549, "rank": 1}}, {"63111": {"logprob": -1.838478446006775, "rank": 2}, "20078": {"logprob": -1.713478446006775, "rank": 1}}, {"264": {"logprob": -0.05422116443514824, "rank": 1}}, {"80822": {"logprob": -0.002198542468249798, "rank": 1}}, {"20129": {"logprob": -0.03206412121653557, "rank": 1}}, {"13": {"logprob": -1.7389187812805176, "rank": 2}, "429": {"logprob": -0.8639187216758728, "rank": 1}}]}, {"text": "def quicksort(arr):\n if len(arr) <= 1:\n return arr", "prompt_logprobs": [null, {"3974": {"logprob": -4.671156883239746, "rank": 21}, "1477": {"logprob": -3.108656644821167, "rank": 1}}, {"6860": {"logprob": -0.1619689166545868, "rank": 1}}, {"10934": {"logprob": -0.7124550938606262, "rank": 1}}, {"982": {"logprob": -0.39134737849235535, "rank": 1}}, {"262": {"logprob": -0.07355262339115143, "rank": 1}}, {"421": {"logprob": -0.15880265831947327, "rank": 1}}, {"2422": {"logprob": -0.08319008350372314, "rank": 1}}, {"10934": {"logprob": -0.0004148814477957785, "rank": 1}}, {"8": {"logprob": -0.04441158473491669, "rank": 1}}, {"2651": {"logprob": -0.04771881923079491, "rank": 1}}, {"220": {"logprob": -0.003187221009284258, "rank": 1}}, {"16": {"logprob": -0.00019536493346095085, "rank": 1}}, {"510": {"logprob": -0.018494658172130585, "rank": 1}}, {"286": {"logprob": -0.0007495454628951848, "rank": 1}}, {"470": {"logprob": -0.0002919009421020746, "rank": 1}}, {"2890": {"logprob": -0.00018737945356406271, "rank": 1}}, {"198": {"logprob": -0.08063282072544098, "rank": 1}}, {"262": {"logprob": -0.0005990855861455202, "rank": 1}}, {"25964": {"logprob": -0.22211678326129913, "rank": 1}}, {"284": {"logprob": -0.009856365621089935, "rank": 1}}, {"2890": {"logprob": -0.0019270675256848335, "rank": 1}}, {"24617": {"logprob": -0.12844769656658173, "rank": 1}}, {"10934": {"logprob": -5.2569914259947836e-05, "rank": 1}}, {"8": {"logprob": -0.0713733434677124, "rank": 1}}, {"442": {"logprob": -0.006514384411275387, "rank": 1}}, {"220": {"logprob": -0.00043871314846910536, "rank": 1}}, {"17": {"logprob": -0.00027783826226368546, "rank": 1}}, {"921": {"logprob": -0.024755505844950676, "rank": 1}}, {"262": {"logprob": -0.0009921634336933494, "rank": 1}}, {"2115": {"logprob": -0.024546153843402863, "rank": 1}}, {"284": {"logprob": -0.0011714984430000186, "rank": 1}}, {"508": {"logprob": -0.001456510741263628, "rank": 1}}, {"87": {"logprob": -0.0006524579366669059, "rank": 1}}, {"369": {"logprob": -0.0003591130953282118, "rank": 1}}, {"856": {"logprob": -1.3708974620385561e-05, "rank": 1}}, {"304": {"logprob": -1.6212332411669195e-05, "rank": 1}}, {"2890": {"logprob": -7.939023635117337e-05, "rank": 1}}, {"421": {"logprob": -0.0002466136065777391, "rank": 1}}, {"856": {"logprob": -0.00011145447206217796, "rank": 1}}, {"366": {"logprob": -0.00030501006403937936, "rank": 1}}, {"25964": {"logprob": -5.23315102327615e-05, "rank": 1}}, {"921": {"logprob": -0.01134586613625288, "rank": 1}}, {"262": {"logprob": -7.486063259420916e-05, "rank": 1}}, {"6149": {"logprob": -0.031813107430934906, "rank": 1}}, {"284": {"logprob": -0.0002203936892328784, "rank": 1}}, {"508": {"logprob": -7.414542778860778e-05, "rank": 1}}, {"87": {"logprob": -3.290122185717337e-05, "rank": 1}}, {"369": {"logprob": -6.770858453819528e-05, "rank": 1}}, {"856": {"logprob": -1.3589766240329482e-05, "rank": 1}}, {"304": {"logprob": -1.3828182090946939e-05, "rank": 1}}, {"2890": {"logprob": -6.05564855504781e-05, "rank": 1}}, {"421": {"logprob": -0.00041762212640605867, "rank": 1}}, {"856": {"logprob": -3.2066785934148356e-05, "rank": 1}}, {"621": {"logprob": -0.00026174934464506805, "rank": 1}}, {"25964": {"logprob": -9.97731985989958e-05, "rank": 1}}, {"921": {"logprob": -0.0036140859592705965, "rank": 1}}, {"262": {"logprob": -0.00033301531220786273, "rank": 1}}, {"1290": {"logprob": -0.001256391522474587, "rank": 1}}, {"284": {"logprob": -0.0002641328901518136, "rank": 1}}, {"508": {"logprob": -0.00030560590676032007, "rank": 1}}, {"87": {"logprob": -5.113947918289341e-05, "rank": 1}}, {"369": {"logprob": -5.1973900554003194e-05, "rank": 1}}, {"856": {"logprob": -5.006777428206988e-06, "rank": 1}}, {"304": {"logprob": -3.933898824470816e-06, "rank": 1}}, {"2890": {"logprob": -7.974783511599526e-05, "rank": 1}}, {"421": {"logprob": -4.589452510117553e-05, "rank": 1}}, {"856": {"logprob": -1.0847986231965479e-05, "rank": 1}}, {"861": {"logprob": -8.296622399939224e-05, "rank": 1}}, {"25964": {"logprob": -3.504691630951129e-05, "rank": 1}}, {"921": {"logprob": -0.01611071638762951, "rank": 1}}, {"262": {"logprob": -0.0018378286622464657, "rank": 1}}, {"470": {"logprob": -0.0027129771187901497, "rank": 1}}, {"3974": {"logprob": -0.0012291265884414315, "rank": 1}}, {"6860": {"logprob": -3.361645576660521e-05, "rank": 1}}, {"17646": {"logprob": -0.0015704215038567781, "rank": 1}}, {"8": {"logprob": -0.00011979816190432757, "rank": 1}}, {"488": {"logprob": -1.5258672647178173e-05, "rank": 1}}, {"6149": {"logprob": -0.029879430308938026, "rank": 1}}, {"488": {"logprob": -7.199982064776123e-05, "rank": 1}}, {"3974": {"logprob": -0.0008188708452507854, "rank": 1}}, {"6860": {"logprob": -2.9205850296420977e-05, "rank": 1}}, {"27611": {"logprob": -0.0004589696181938052, "rank": 1}}, {"8": {"logprob": -3.2561628818511963, "rank": 4}, "692": {"logprob": -0.5061629414558411, "rank": 1}}]}, {"text": "In 1969, the Apollo 11 mission successfully landed the first", "prompt_logprobs": [null, {"220": {"logprob": -10.206684112548828, "rank": 1482}, "154822": {"logprob": -0.5660589933395386, "rank": 1}}, {"121818": {"logprob": -9.583924293518066, "rank": 967}, "445": {"logprob": -1.9589239358901978, "rank": 1}}, {"24": {"logprob": -2.2160422801971436, "rank": 2}, "17": {"logprob": -1.9660422801971436, "rank": 1}}, {"11": {"logprob": -0.31565120816230774, "rank": 1}}, {"279": {"logprob": -1.8757191896438599, "rank": 1}}, {"34976": {"logprob": -1.856926441192627, "rank": 1}}, {"220": {"logprob": -0.28477251529693604, "rank": 1}}, {"98965": {"logprob": -0.13288503885269165, "rank": 1}}, {"8951": {"logprob": -1.120803952217102, "rank": 1}}, {"7790": {"logprob": -2.666490077972412, "rank": 5}, "26039": {"logprob": -1.166490077972412, "rank": 1}}, {"26039": {"logprob": -0.2363465130329132, "rank": 1}}, {"279": {"logprob": -1.3420698642730713, "rank": 2}, "12671": {"logprob": -1.0920698642730713, "rank": 1}}, {"1156": {"logprob": -0.015671197324991226, "rank": 1}}, {"12671": {"logprob": -0.16529999673366547, "rank": 1}}, {"389": {"logprob": -0.018318170681595802, "rank": 1}}, {"279": {"logprob": -0.002457576571032405, "rank": 1}}, {"17309": {"logprob": -0.47859787940979004, "rank": 1}}, {"13": {"logprob": -0.4214438498020172, "rank": 1}}, {"32962": {"logprob": -1.7287052869796753, "rank": 2}, "1096": {"logprob": -1.4162052869796753, "rank": 1}}, {"44605": {"logprob": -0.0037791754584759474, "rank": 1}}, {"323": {"logprob": -0.31780102849006653, "rank": 1}}, {"37754": {"logprob": -0.07444359362125397, "rank": 1}}, {"30230": {"logprob": -0.0001851148990681395, "rank": 1}}, {"25210": {"logprob": -0.0001760566228767857, "rank": 1}}, {"7391": {"logprob": -2.2541415691375732, "rank": 4}, "14847": {"logprob": -1.0041415691375732, "rank": 1}}, {"13179": {"logprob": -1.891210913658142, "rank": 4}, "911": {"logprob": -1.266210913658142, "rank": 1}}, {"1378": {"logprob": -3.2941174507141113, "rank": 2}, "220": {"logprob": -0.044117338955402374, "rank": 1}}, {"323": {"logprob": -0.3244158923625946, "rank": 1}}, {"264": {"logprob": -0.007937673479318619, "rank": 1}}, {"8337": {"logprob": -9.626143455505371, "rank": 5}, "4279": {"logprob": -0.0011433976469561458, "rank": 1}}, {"4115": {"logprob": -0.004965473897755146, "rank": 1}}, {"4889": {"logprob": -2.2987828254699707, "rank": 3}, "389": {"logprob": -0.4237828850746155, "rank": 1}}, {"279": {"logprob": -0.12357600778341293, "rank": 1}}, {"41305": {"logprob": -0.21075278520584106, "rank": 1}}, {"11": {"logprob": -0.6706154346466064, "rank": 1}}, {"25814": {"logprob": -2.381929636001587, "rank": 2}, "1393": {"logprob": -0.3819296360015869, "rank": 1}}, {"56329": {"logprob": -0.744219183921814, "rank": 1}}, {"3684": {"logprob": -3.2368898391723633, "rank": 2}, "10464": {"logprob": -0.1118898019194603, "rank": 1}}, {"311": {"logprob": -3.483480215072632, "rank": 4}, "323": {"logprob": -0.3584801256656647, "rank": 1}}, {"4446": {"logprob": -0.005789179354906082, "rank": 1}}, {"1182": {"logprob": -0.0023563734721392393, "rank": 1}}, {"311": {"logprob": -0.08122804760932922, "rank": 1}}, {"9234": {"logprob": -0.001869836589321494, "rank": 1}}, {"13": {"logprob": -0.31999635696411133, "rank": 1}}]}, {"text": "Le petit prince demanda au renard ce que signifiait le mot a", "prompt_logprobs": [null, {"44744": {"logprob": -15.086844444274902, "rank": 19987}, "154822": {"logprob": -0.03215659037232399, "rank": 1}}, {"41490": {"logprob": -2.236527442932129, "rank": 2}, "7439": {"logprob": -1.9240275621414185, "rank": 1}}, {"137474": {"logprob": -13.464132308959961, "rank": 9108}, "320": {"logprob": -1.8938194513320923, "rank": 1}}, {"7906": {"logprob": -4.618757247924805, "rank": 10}, "34327": {"logprob": -0.9937573671340942, "rank": 1}}, {"5672": {"logprob": -5.73123025894165, "rank": 29}, "41490": {"logprob": -1.6687301397323608, "rank": 1}}, {"567": {"logprob": -0.002051512710750103, "rank": 1}}, {"3761": {"logprob": -5.122798919677734, "rank": 23}, "25": {"logprob": -1.6852988004684448, "rank": 1}}, {"1709": {"logprob": -0.22010760009288788, "rank": 1}}, {"1841": {"logprob": -0.7134836316108704, "rank": 1}}, {"333": {"logprob": -0.015017430298030376, "rank": 1}}, {"685": {"logprob": -0.0040635643526911736, "rank": 1}}, {"275": {"logprob": -0.010992445982992649, "rank": 1}}, {"512": {"logprob": -1.5149849653244019, "rank": 2}, "12480": {"logprob": -1.3899849653244019, "rank": 1}}, {"3852": {"logprob": -0.043013498187065125, "rank": 1}}, {"131231": {"logprob": -5.450429916381836, "rank": 10}, "330": {"logprob": -1.0129296779632568, "rank": 1}}, {"6496": {"logprob": -6.83045873302035e-05, "rank": 1}}, {"12053": {"logprob": -0.3574623167514801, "rank": 1}}, {"13": {"logprob": -1.2856106758117676, "rank": 1}}, {"1967": {"logprob": -1.2020219564437866, "rank": 1}}, {"5672": {"logprob": -0.04066687822341919, "rank": 1}}, {"567": {"logprob": -0.00021395778458099812, "rank": 1}}, {"3247": {"logprob": -2.827406644821167, "rank": 3}, "24324": {"logprob": -0.26490655541419983, "rank": 1}}, {"5011": {"logprob": -0.00013672371278516948, "rank": 1}}, {"64": {"logprob": -0.00018094333063345402, "rank": 1}}, {"1709": {"logprob": -0.3359103202819824, "rank": 1}}, {"44244": {"logprob": -1.0277819633483887, "rank": 2}, "272": {"logprob": -0.6527820229530334, "rank": 1}}, {"1841": {"logprob": -0.9390860199928284, "rank": 2}, "136015": {"logprob": -0.6890860199928284, "rank": 1}}, {"333": {"logprob": -0.00013541258522309363, "rank": 1}}, {"685": {"logprob": -0.0016919358167797327, "rank": 1}}, {"275": {"logprob": -0.0004472924047149718, "rank": 1}}, {"1884": {"logprob": -9.71902084350586, "rank": 48}, "74145": {"logprob": -0.1565210521221161, "rank": 1}}, {"261": {"logprob": -0.005516662262380123, "rank": 1}}, {"939": {"logprob": -0.0008032671175897121, "rank": 1}}, {"151101": {"logprob": -0.0020524642895907164, "rank": 1}}, {"11": {"logprob": -1.3468353748321533, "rank": 2}, "13": {"logprob": -0.7218353748321533, "rank": 1}}, {"1842": {"logprob": -1.5655219554901123, "rank": 1}}, {"1709": {"logprob": -0.9483869075775146, "rank": 1}}, {"4403": {"logprob": -3.9862172603607178, "rank": 13}, "1884": {"logprob": -1.8612172603607178, "rank": 1}}, {"512": {"logprob": -2.7602930068969727, "rank": 4}, "326": {"logprob": -0.7602930068969727, "rank": 1}}, {"41490": {"logprob": -3.425759792327881, "rank": 2}, "44744": {"logprob": -0.05075967311859131, "rank": 1}}, {"326": {"logprob": -2.311954975128174, "rank": 2}, "11203": {"logprob": -0.3744550347328186, "rank": 1}}, {"6": {"logprob": -0.05812050774693489, "rank": 1}}, {"138865": {"logprob": -0.024985626339912415, "rank": 1}}, {"6496": {"logprob": -0.01858804002404213, "rank": 1}}, {"285": {"logprob": -0.0001811817055568099, "rank": 1}}, {"1315": {"logprob": -0.0011703077470883727, "rank": 1}}, {"11": {"logprob": -0.022120878100395203, "rank": 1}}, {"44786": {"logprob": -0.7634887099266052, "rank": 1}}, {"38832": {"logprob": -0.6383026838302612, "rank": 1}}, {"1167": {"logprob": -6.437094270950183e-05, "rank": 1}}, {"62129": {"logprob": -0.04240342229604721, "rank": 1}}, {"326": {"logprob": -0.015435636974871159, "rank": 1}}, {"21997": {"logprob": -0.010267415083944798, "rank": 1}}, {"409": {"logprob": -0.07603368908166885, "rank": 1}}, {"326": {"logprob": -0.003307826118543744, "rank": 1}}, {"48052": {"logprob": -0.00038258862332440913, "rank": 1}}, {"265": {"logprob": -2.2172682292875834e-05, "rank": 1}}, {"13": {"logprob": -1.9888827800750732, "rank": 2}, "1842": {"logprob": -0.23888275027275085, "rank": 1}}]}, {"text": "The gradient of the loss function with respect to the weight", "prompt_logprobs": [null, {"20129": {"logprob": -8.889708518981934, "rank": 897}, "154822": {"logprob": -4.139708518981934, "rank": 1}}, {"315": {"logprob": -0.8865096569061279, "rank": 1}}, {"279": {"logprob": -0.9322892427444458, "rank": 2}, "264": {"logprob": -0.8072892427444458, "rank": 1}}, {"4709": {"logprob": -4.026505470275879, "rank": 10}, "729": {"logprob": -1.4015053510665894, "rank": 1}}, {"729": {"logprob": -0.36438724398612976, "rank": 1}}, {"448": {"logprob": -1.4475375413894653, "rank": 2}, "374": {"logprob": -1.1975375413894653, "rank": 1}}, {"5091": {"logprob": -0.00735432980582118, "rank": 1}}, {"311": {"logprob": -0.0006932000978849828, "rank": 1}}, {"279": {"logprob": -0.4142419993877411, "rank": 1}}, {"14314": {"logprob": -0.9438306093215942, "rank": 1}}, {"374": {"logprob": -1.1226654052734375, "rank": 1}}, {"24113": {"logprob": -2.259307622909546, "rank": 2}, "264": {"logprob": -1.759307622909546, "rank": 1}}, {"4566": {"logprob": -2.8481698036193848, "rank": 5}, "1667": {"logprob": -1.0981696844100952, "rank": 1}}, {"1182": {"logprob": -0.3567676842212677, "rank": 1}}, {"2674": {"logprob": -0.015955040231347084, "rank": 1}}, {"27048": {"logprob": -0.011109991930425167, "rank": 1}}, {"11": {"logprob": -1.1857377290725708, "rank": 1}}, {"18915": {"logprob": -4.114374160766602, "rank": 7}, "892": {"logprob": -0.8643743395805359, "rank": 1}}, {"279": {"logprob": -0.006285067647695541, "rank": 1}}, {"8780": {"logprob": -0.006868680007755756, "rank": 1}}, {"5912": {"logprob": -0.0005919373361393809, "rank": 1}}, {"6193": {"logprob": -1.0216705799102783, "rank": 1}}, {"553": {"logprob": -0.015778925269842148, "rank": 1}}, {"6193": {"logprob": -0.0003275334893260151, "rank": 1}}, {"504": {"logprob": -1.870853066444397, "rank": 3}, "13": {"logprob": -0.870853066444397, "rank": 1}}, {"279": {"logprob": -0.06314688175916672, "rank": 1}}, {"2550": {"logprob": -0.023715758696198463, "rank": 1}}, {"1182": {"logprob": -0.27094948291778564, "rank": 1}}, {"311": {"logprob": -0.1267653852701187, "rank": 1}}, {"279": {"logprob": -0.011979068629443645, "rank": 1}}, {"1946": {"logprob": -0.02570413611829281, "rank": 1}}, {"13": {"logprob": -0.6587228775024414, "rank": 1}}, {"794": {"logprob": -6.994905471801758, "rank": 51}, "1096": {"logprob": -1.1824054718017578, "rank": 1}}, {"65474": {"logprob": -0.005420392379164696, "rank": 1}}, {"20129": {"logprob": -1.6218022108078003, "rank": 2}, "52755": {"logprob": -0.2468022257089615, "rank": 1}}, {"36760": {"logprob": -0.003883322235196829, "rank": 1}}, {"1221": {"logprob": -3.263713836669922, "rank": 5}, "320": {"logprob": -0.5137138366699219, "rank": 1}}, {"8836": {"logprob": -0.07174212485551834, "rank": 1}}, {"1817": {"logprob": -0.8400536179542542, "rank": 2}, "279": {"logprob": -0.5900536179542542, "rank": 1}}, {"4680": {"logprob": -0.2043377012014389, "rank": 1}}, {"21070": {"logprob": -7.616705417633057, "rank": 40}, "553": {"logprob": -1.1167054176330566, "rank": 1}}, {"745": {"logprob": -0.0039456626400351524, "rank": 1}}, {"13": {"logprob": -8.379411697387695, "rank": 6}, "311": {"logprob": -0.004411607980728149, "rank": 1}}]}]}
scripts/results-fp8attn-r2.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"port": 18999, "model": "glm-5.3-flash-fp8attn", "arith_correct": true, "arith_raw": "391", "long_gen_tokens": 2400, "long_gen_degenerate": false, "long_gen_tail": "", "greedy": [{"prompt": "What is 17*23? Answer with just the number.", "tokens": [" No", " explanation", ".\n\n", "39", "1", "\n\n", "What", " is", " ", "17", "*", "23", "?", " Answer", " with", " just", " the", " number", ".", " No", " explanation", ".\n\n", "39", "1", "\n\n", "What", " is", " ", "17", "*", "23", "?", " Answer", " with", " just", " the", " number", ".", " No", " explanation", ".\n\n", "39", "1", "\n\n", "What", " is", " ", "17", "*", "23"], "token_logprobs": [-0.05944731831550598, -0.5826609134674072, -0.3849724531173706, -1.911155104637146, -0.010873118415474892, -0.25789758563041687, -1.8001893758773804, -0.34823641180992126, -0.3625602126121521, -0.5563923716545105, -0.07689584791660309, -0.034770701080560684, -0.08116638660430908, -0.02365242689847946, -0.008518549613654613, -0.004947562236338854, -0.0014207994099706411, -0.0026112052146345377, -0.007911890745162964, -0.011773505248129368, -0.0017363247461616993, -0.124687060713768, -0.3326472342014313, -0.0031424211338162422, -0.022832708433270454, -0.9107614159584045, -0.08265145123004913, -0.09264775365591049, -0.1255660206079483, -0.03304609656333923, -0.002765761222690344, -0.04369350150227547, -0.00791449286043644, -0.0014425835106521845, -0.0007397775771096349, -0.00046921687317080796, -0.000248401309363544, -0.0118564423173666, -0.0004991239402443171, -0.00014220656885299832, -0.03401881456375122, -0.062206804752349854, -0.0006727101281285286, -0.007971142418682575, -0.36260515451431274, -0.036149993538856506, -0.04544929414987564, -0.04089267924427986, -0.01693490706384182, -0.00013362467871047556]}, {"prompt": "Write a Python function that returns the nth Fibonacci number iteratively.", "tokens": [" The", " function", " should", " take", " an", " integer", " n", " as", " input", " and", " return", " the", " nth", " Fibonacci", " number", ".", " The", " Fibonacci", " sequence", " starts", " with", " ", "0", " and", " ", "1", ",", " and", " each", " subsequent", " number", " is", " the", " sum", " of", " the", " previous", " two", ".\n\n", "Oops", ",", " something", " went", " wrong", " with", " the", " submission", ".", " Please", " try"], "token_logprobs": [-1.7642946243286133, -0.7029318809509277, -0.09558022767305374, -1.2110228538513184, -0.2627769708633423, -0.0363968200981617, -0.18501845002174377, -0.27277621626853943, -0.08432750403881073, -0.05720282346010208, -0.08453457057476044, -0.006612088996917009, -0.299607515335083, -0.1252496987581253, -0.0006221981020644307, -1.0313425064086914, -0.9150235652923584, -0.2842489778995514, -0.017720239236950874, -0.5295724868774414, -0.04783110320568085, -0.16131487488746643, -0.04867612570524216, -0.02193313278257847, -0.0007107115816324949, -6.246371776796877e-05, -0.17393411695957184, -0.5940362215042114, -0.00876827072352171, -0.00829323846846819, -0.0013516347389668226, -0.0012529388768598437, -0.0002522150462027639, -6.425174069590867e-05, -8.95221673999913e-05, -0.00013100242358632386, -0.10058816522359848, -9.77468371274881e-05, -0.7992817163467407, -1.8348184823989868, -0.31329023838043213, -4.0531076592742465e-06, -0.017971185967326164, -0.00016616393986623734, -0.0022801372688263655, -7.867782187531702e-06, -0.30164211988449097, -0.0037867759820073843, -0.4540240466594696, -0.00021872512297704816]}, {"prompt": "Explain the difference between TCP and UDP in two sentences.", "tokens": [" TCP", " is", " a", " connection", "-oriented", " protocol", " that", " guarantees", " reliable", " and", " ordered", " delivery", " of", " data", ",", " while", " UDP", " is", " a", " connection", "less", " protocol", " that", " offers", " faster", " transmission", " but", " without", " reliability", " guarantees", ".", " TCP", " is", " used", " for", " applications", " requiring", " accuracy", ",", " like", " web", " browsing", " and", " email", ",", " whereas", " UDP", " suits", " real", "-time"], "token_logprobs": [-2.1664068698883057, -0.5105972290039062, -1.0036437511444092, -0.13523302972316742, -0.10164449363946915, -0.06846220046281815, -0.07941774278879166, -0.8166302442550659, -0.7640823125839233, -1.1875782012939453, -0.009914086200296879, -0.12146991491317749, -0.2796986401081085, -0.06342505663633347, -0.34167078137397766, -0.1039290651679039, -0.0016980052459985018, -0.0021799865644425154, -0.4301416873931885, -0.00293717160820961, -0.006561875808984041, -0.009775741025805473, -0.09219703078269958, -0.5810120701789856, -0.28433024883270264, -0.7065703868865967, -0.27751392126083374, -0.5059866905212402, -0.9429896473884583, -0.8121258020401001, -0.5056018233299255, -0.7258883118629456, -0.8206141591072083, -0.6789292693138123, -0.24797283113002777, -0.07828938215970993, -0.9464417695999146, -0.7371711134910583, -0.271616131067276, -0.7413150668144226, -0.034485816955566406, -0.006523622665554285, -0.20175322890281677, -0.25684863328933716, -0.030713511630892754, -0.3170405924320221, -0.005047554615885019, -0.5775002837181091, -0.057018060237169266, -0.0007781338645145297]}, {"prompt": "Translate to French: 'The quick brown fox jumps over the lazy dog.'", "tokens": [" '", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".'", " is", " a", " pang", "ram", " in", " English", ".", " Translate", " it", " to", " French", " while", " maintaining", " its", " pang", "ram", " property", " if", " possible", ".\n\n", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".", " The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog"], "token_logprobs": [-2.149756669998169, -0.20842771232128143, -0.3368588089942932, -0.002255635801702738, -0.0032970139291137457, -0.03933334723114967, -0.00045563330058939755, -0.0004489606071729213, -0.00039891392225399613, -0.0010389650706201792, -0.2811572253704071, -1.3580446243286133, -0.15982377529144287, -0.11232949048280716, -0.000291662581730634, -1.6984364986419678, -0.004039581399410963, -0.6311922669410706, -1.5507032871246338, -0.6992087960243225, -0.20567406713962555, -0.015907876193523407, -1.2523680925369263, -1.0850424766540527, -0.45235490798950195, -0.7020478844642639, -0.00033468366018496454, -1.044109582901001, -0.4560047388076782, -0.0012656782055273652, -0.7169108986854553, -1.5870269536972046, -1.0531322956085205, -0.01393517479300499, -0.0015075758565217257, -0.07642681151628494, -0.0007192885386757553, -0.0015687552513554692, -0.0008596062543801963, -0.00047672350774519145, -0.8251421451568604, -1.446233868598938, -0.03736536577343941, -0.0007247682078741491, -0.002385153668001294, -0.0027703975792974234, -0.00025412190007045865, -0.0003618539194576442, -0.000795762927737087, -0.00023398046323563904]}, {"prompt": "List the first 8 prime numbers separated by commas.", "tokens": [" The", " first", " ", "8", " prime", " numbers", " are", ":", " ", "2", ",", " ", "3", ",", " ", "5", ",", " ", "7", ",", " ", "11", ",", " ", "13", ",", " ", "17", ",", " ", "19", ".\n\n", "F", "ilo", " tutor", " solution", "\n\n", "Students", " who", " ask", " this", " question", " also", " asked", "\n\n", "Question", " Text", " ", " List", " the"], "token_logprobs": [-2.080172538757324, -0.46148520708084106, -0.7754691243171692, -0.14339658617973328, -0.17251218855381012, -0.03238016739487648, -0.08005881309509277, -0.7739989161491394, -0.11371561884880066, -0.013985958881676197, -0.026080850511789322, -0.013455298729240894, -0.004541914910078049, -0.003891515778377652, -0.0013450870756059885, -0.0017308506648987532, -0.005829001776874065, -0.0034458802547305822, -0.0020590072963386774, -0.010927713476121426, -0.0060180178843438625, -0.00455805379897356, -0.0027053682133555412, -0.0028406528290361166, -0.0010407513473182917, -0.01737164333462715, -0.008684603497385979, -0.0019155264599248767, -0.008271721191704273, -0.03573001176118851, -0.0009894242975860834, -0.6739247441291809, -0.8447352647781372, -0.0006543640629388392, -0.12604744732379913, -0.0005423743859864771, -0.009403815492987633, -0.044313397258520126, -0.0003687655262183398, -0.0027317609637975693, -2.622600959512056e-06, -5.602820692729438e-06, -4.6491513785440475e-06, -0.02632099948823452, -0.0008305437513627112, -0.020699547603726387, -0.0010898133041337132, -1.6689160474925302e-05, -0.0066014304757118225, -3.3854863431770355e-05]}, {"prompt": "What year did the Apollo 11 mission land on the moon? One word answer.", "tokens": [" ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196", "9", ".", " ", "196"], "token_logprobs": [-2.684290647506714, -0.42765599489212036, -0.03121418133378029, -1.085909366607666, -1.8752169609069824, -0.3683359622955322, -0.27957525849342346, -0.5220775604248047, -0.8821458220481873, -0.061857130378484726, -0.029933461919426918, -0.18102236092090607, -0.5030839443206787, -0.03042110800743103, -0.015802979469299316, -0.09392880648374557, -0.33354124426841736, -0.01612490974366665, -0.009449399076402187, -0.049896448850631714, -0.1424921303987503, -0.0053824507631361485, -0.004922888707369566, -0.02003258652985096, -0.07645177096128464, -0.005030712112784386, -0.005231737624853849, -0.016645830124616623, -0.08853212743997574, -0.007705252151936293, -0.004098112694919109, -0.014262407086789608, -0.059556834399700165, -0.004486969672143459, -0.0023612494114786386, -0.029799478128552437, -0.05181640386581421, -0.003469164716079831, -0.0018203369108960032, -0.03346248343586922, -0.057477597147226334, -0.0032982020638883114, -0.0016526625258848071, -0.025812994688749313, -0.040548406541347504, -0.0021870045457035303, -0.001210433547385037, -0.023893393576145172, -0.04918241128325462, -0.0023231918457895517]}, {"prompt": "Summarize the plot of Romeo and Juliet in one sentence.", "tokens": [" a", ")", " Two", " fe", "uding", " families", " come", " together", " after", " their", " children", ",", " Romeo", " and", " Juliet", ",", " fall", " in", " love", " and", " trag", "ically", " die", ".", " b", ")", " Romeo", " and", " Juliet", " have", " a", " happy", " ending", ".", " c", ")", " Romeo", " and", " Juliet", "'s", " love", " story", " is", " a", " comedy", ".", " d", ")", " Romeo", " and"], "token_logprobs": [-2.1768288612365723, -0.16833597421646118, -0.8950750827789307, -0.19481375813484192, -0.000316927267704159, -0.10694278031587601, -1.6120059490203857, -0.014888598583638668, -0.09647224843502045, -0.15219855308532715, -0.006082239560782909, -0.36868584156036377, -0.012532645836472511, -0.006764133460819721, -0.004529217258095741, -0.0006214833119884133, -0.9728213548660278, -0.0073027340695261955, -0.00018880968855228275, -0.5249180793762207, -0.6911277174949646, -5.876845170860179e-05, -0.006740925367921591, -0.17906098067760468, -0.0018563910853117704, -0.0002873722987715155, -0.06740620732307434, -0.05663299933075905, -0.00039545822073705494, -1.177451491355896, -0.002934081247076392, -0.4079383313655853, -0.26802992820739746, -0.6858858466148376, -8.940656698541716e-06, -4.005352093372494e-05, -0.4138554334640503, -0.010753422044217587, -0.00032658010604791343, -0.9866162538528442, -0.6734787821769714, -0.13450968265533447, -0.45319122076034546, -1.522828221321106, -0.09239399433135986, -0.014370872639119625, -5.4834770708112046e-05, -2.658331868587993e-05, -0.10389231890439987, -0.0012042421149089932]}, {"prompt": "Write a SQL query selecting the top 5 customers by total order value from tables customers(id,name) and orders(id,customer_id,value).", "tokens": [" Show", " name", " and", " total", "_value", ".\n\n", "SQL", " Query", ":", " Top", " ", "5", " Customers", " by", " Total", " Order", " Value", "\n\n", "This", " query", " joins", " the", " `", "customers", " and", "`", " and", " `", "orders", " tables", ",", " calculates", " the", " total", " order", " value", " for", " each", " customer", ",", " and", " returns", " the", " top", " ", "5", " customers", " by", " total", " value"], "token_logprobs": [-1.3691363334655762, -1.1203458309173584, -0.02115425281226635, -0.01775631122291088, -0.3033752143383026, -0.8740469217300415, -1.3740661144256592, -1.6019648313522339, -0.54132479429245, -0.020537111908197403, -0.01443256251513958, -0.00010907054820563644, -0.001604818389751017, -0.0038330908864736557, -0.007890010252594948, -0.0017813066951930523, -0.00010656742961145937, -0.025862017646431923, -0.9626234769821167, -0.5823020935058594, -0.4397076666355133, -0.10617304593324661, -0.13532882928848267, -0.0015550674870610237, -0.130263552069664, -0.0025500894989818335, -0.0002818902430590242, -9.917721035890281e-05, -0.00026008085114881396, -0.002825318370014429, -0.1011388823390007, -0.9381394386291504, -0.014089400880038738, -0.11425776779651642, -0.03946559876203537, -0.0001394651480950415, -0.2831369638442993, -7.176141662057489e-05, -4.279521817807108e-05, -0.013094269670546055, -0.1208435595035553, -0.2611698508262634, -0.006272273603826761, -0.00244770641438663, -0.00013064485392533243, -3.302042750874534e-05, -0.02517198584973812, -0.7001596093177795, -0.31569674611091614, -0.4387320876121521]}, {"prompt": "What is the derivative of x^3 + 2x with respect to x?", "tokens": [" A", ")", " ", "3", "x", "^", "2", " +", " ", "2", " B", ")", " ", "3", "x", "^", "2", " C", ")", " ", "3", "x", " D", ")", " ", "2", "x", "\n\n", "Der", "ivative", " of", " x", "^", "3", " is", " ", "3", "x", "^", "2", " (", "using", " power", " rule", "),", " derivative", " of", " ", "2", "x"], "token_logprobs": [-1.1832355260849, -0.06630413979291916, -0.0950939729809761, -0.009201028384268284, -0.020987922325730324, -0.020990489050745964, -0.005296365823596716, -0.704566240310669, -0.07149588316679001, -0.008433561772108078, -0.5468310713768005, -0.005816202145069838, -0.09202906489372253, -0.018634025007486343, -0.008101223036646843, -0.16332460939884186, -0.05604492872953415, -0.6768378615379333, -0.0007215518853627145, -0.5765297412872314, -0.6188015341758728, -0.02453301101922989, -0.9457128047943115, -0.0022049658000469208, -0.6346037983894348, -0.37808555364608765, -0.27482497692108154, -0.4707711338996887, -1.671670913696289, -0.018921826034784317, -0.08714864403009415, -0.4256858825683594, -0.027576664462685585, -0.011900264769792557, -0.7346628904342651, -0.021018855273723602, -0.00011646069469861686, -0.0027854950167238712, -0.04687469080090523, -0.00017677174764685333, -1.0287939310073853, -0.8071150183677673, -0.32162296772003174, -6.854299135738984e-05, -1.0570392608642578, -0.5325397849082947, -0.0003432638186495751, -0.0010032388381659985, -3.957670196541585e-05, -0.0017874945187941194]}, {"prompt": "Name the chemical symbol for gold and the element with atomic number 6.", "tokens": [" Also", ",", " what", " is", " the", " chemical", " symbol", " for", " potassium", "?\n\n", "Under", "stand", " the", " Problem", "\n\n", "The", " question", " is", " asking", " for", " the", " chemical", " symbols", " of", " gold", ",", " the", " element", " with", " atomic", " number", " ", "6", ",", " and", " potassium", ".", " It", " also", " asks", " for", " the", " chemical", " symbol", " of", " potassium", ".\n\n", "Answer", "\n\n", "Gold"], "token_logprobs": [-2.00419020652771, -0.1334722936153412, -1.5497604608535767, -0.4327820837497711, -0.1609821617603302, -1.5782102346420288, -0.4866625666618347, -0.07233412563800812, -1.6589524745941162, -0.489144891500473, -1.0709381103515625, -0.00673760985955596, -0.00014876213390380144, -0.004940326325595379, -1.2636104656849056e-05, -0.0014119903789833188, -0.028069285675883293, -0.4421171247959137, -0.007818334735929966, -0.16596214473247528, -0.4390704333782196, -0.01329709216952324, -0.47676509618759155, -0.3466499447822571, -1.0222762823104858, -0.5047532916069031, -0.6895358562469482, -0.03456873446702957, -0.002307730494067073, -0.0023528055753558874, -3.0278701160568744e-05, -7.73638384998776e-05, -0.0002330270071979612, -0.18028482794761658, -0.0076371124014258385, -0.093072310090065, -0.38200756907463074, -1.3952076435089111, -1.285137414932251, -1.2513244152069092, -0.45332419872283936, -0.14831401407718658, -1.3320817947387695, -0.36621829867362976, -0.7353503108024597, -1.2420315742492676, -1.2335261106491089, -0.0010377742582932115, -0.00013517419574782252, -0.28301292657852173]}], "scored": [{"text": "The mitochondrion is the powerhouse of the cell, converting ", "prompt_logprobs": [null, {"53582": {"logprob": -11.99929428100586, "rank": 21121}, "154822": {"logprob": -4.718044281005859, "rank": 1}}, {"81": {"logprob": -0.8291085958480835, "rank": 2}, "4204": {"logprob": -0.5791085958480835, "rank": 1}}, {"290": {"logprob": -8.34461570775602e-06, "rank": 1}}, {"374": {"logprob": -0.6503285765647888, "rank": 1}}, {"279": {"logprob": -1.0697860717773438, "rank": 2}, "264": {"logprob": -1.0697860717773438, "rank": 1}}, {"73538": {"logprob": -2.878535270690918, "rank": 3}, "1240": {"logprob": -0.37853533029556274, "rank": 1}}, {"315": {"logprob": -0.06434901058673859, "rank": 1}}, {"279": {"logprob": -0.036849040538072586, "rank": 1}}, {"2779": {"logprob": -0.021875867620110512, "rank": 1}}, {"11": {"logprob": -1.3037327527999878, "rank": 2}, "13": {"logprob": -0.9287327527999878, "rank": 1}}, {"33277": {"logprob": -2.816929817199707, "rank": 6}, "323": {"logprob": -1.504429817199707, "rank": 1}}, {"36209": {"logprob": -1.269383192062378, "rank": 2}, "33063": {"logprob": -1.269383192062378, "rank": 1}}, {"1119": {"logprob": -0.10446677356958389, "rank": 1}}, {"993": {"logprob": -2.9703941345214844, "rank": 3}, "66072": {"logprob": -0.34539419412612915, "rank": 1}}, {"70338": {"logprob": -9.953480184776708e-05, "rank": 1}}, {"482": {"logprob": -0.00014673586701974273, "rank": 1}}, {"2406": {"logprob": -0.004084459971636534, "rank": 1}}, {"759": {"logprob": -0.0030250048730522394, "rank": 1}}, {"91597": {"logprob": -0.0001419681793777272, "rank": 1}}, {"1526": {"logprob": -4.27531099319458, "rank": 2}, "320": {"logprob": -0.02531089074909687, "rank": 1}}, {"77673": {"logprob": -0.797971785068512, "rank": 1}}, {"93199": {"logprob": -0.012820087373256683, "rank": 1}}, {"2302": {"logprob": -0.00013672371278516948, "rank": 1}}, {"13": {"logprob": -0.602279543876648, "rank": 1}}, {"1096": {"logprob": -2.468958854675293, "rank": 3}, "21714": {"logprob": -1.1564587354660034, "rank": 1}}, {"1882": {"logprob": -0.6217438578605652, "rank": 1}}, {"13657": {"logprob": -3.98716139793396, "rank": 7}, "33482": {"logprob": -0.9871614575386047, "rank": 1}}, {"3941": {"logprob": -1.2418617010116577, "rank": 1}}, {"279": {"logprob": -0.08991227298974991, "rank": 1}}, {"9176": {"logprob": -0.1417350172996521, "rank": 1}}, {"70428": {"logprob": -0.189726322889328, "rank": 1}}, {"38346": {"logprob": -0.05072477087378502, "rank": 1}}, {"11": {"logprob": -0.5768770575523376, "rank": 1}}, {"1380": {"logprob": -2.294529914855957, "rank": 3}, "892": {"logprob": -0.6695299744606018, "rank": 1}}, {"279": {"logprob": -0.5602529048919678, "rank": 1}}, {"16698": {"logprob": -0.3928229510784149, "rank": 1}}, {"7557": {"logprob": -0.003911108709871769, "rank": 1}}, {"8780": {"logprob": -0.0006998711614869535, "rank": 1}}, {"63111": {"logprob": -2.287539482116699, "rank": 5}, "323": {"logprob": -1.6625394821166992, "rank": 1}}, {"264": {"logprob": -0.13558076322078705, "rank": 1}}, {"80822": {"logprob": -0.00720900297164917, "rank": 1}}, {"20129": {"logprob": -0.1351807564496994, "rank": 1}}, {"13": {"logprob": -1.8071370124816895, "rank": 3}, "429": {"logprob": -0.8071370720863342, "rank": 1}}]}, {"text": "def quicksort(arr):\n if len(arr) <= 1:\n return arr", "prompt_logprobs": [null, {"3974": {"logprob": -4.304945945739746, "rank": 16}, "11619": {"logprob": -3.242445707321167, "rank": 1}}, {"6860": {"logprob": -0.4801536798477173, "rank": 1}}, {"10934": {"logprob": -0.33804360032081604, "rank": 1}}, {"982": {"logprob": -0.5233579277992249, "rank": 1}}, {"262": {"logprob": -0.1534377932548523, "rank": 1}}, {"421": {"logprob": -0.1228206679224968, "rank": 1}}, {"2422": {"logprob": -0.14614543318748474, "rank": 1}}, {"10934": {"logprob": -0.0006597249885089695, "rank": 1}}, {"8": {"logprob": -0.0171370692551136, "rank": 1}}, {"2651": {"logprob": -0.036145396530628204, "rank": 1}}, {"220": {"logprob": -0.0077273729257285595, "rank": 1}}, {"16": {"logprob": -0.00028200942324474454, "rank": 1}}, {"510": {"logprob": -0.007974453270435333, "rank": 1}}, {"286": {"logprob": -0.0004468158003874123, "rank": 1}}, {"470": {"logprob": -0.0002090712368953973, "rank": 1}}, {"2890": {"logprob": -0.0006658005877397954, "rank": 1}}, {"198": {"logprob": -0.10033900290727615, "rank": 1}}, {"262": {"logprob": -0.0006992755807004869, "rank": 1}}, {"25964": {"logprob": -0.1318204700946808, "rank": 1}}, {"284": {"logprob": -0.006611023098230362, "rank": 1}}, {"2890": {"logprob": -0.000780754373408854, "rank": 1}}, {"24617": {"logprob": -0.15622957050800323, "rank": 1}}, {"10934": {"logprob": -6.353653589030728e-05, "rank": 1}}, {"8": {"logprob": -0.09078758955001831, "rank": 1}}, {"442": {"logprob": -0.024294177070260048, "rank": 1}}, {"220": {"logprob": -0.0007382289622910321, "rank": 1}}, {"17": {"logprob": -6.735097849741578e-05, "rank": 1}}, {"921": {"logprob": -0.027924852445721626, "rank": 1}}, {"262": {"logprob": -0.0006946296198293567, "rank": 1}}, {"2115": {"logprob": -0.02876264788210392, "rank": 1}}, {"284": {"logprob": -0.0025351073127239943, "rank": 1}}, {"508": {"logprob": -0.0033736478071659803, "rank": 1}}, {"87": {"logprob": -0.0006858142442069948, "rank": 1}}, {"369": {"logprob": -0.0008480527903884649, "rank": 1}}, {"856": {"logprob": -3.8742269680369645e-05, "rank": 1}}, {"304": {"logprob": -3.671578815556131e-05, "rank": 1}}, {"2890": {"logprob": -7.784063927829266e-05, "rank": 1}}, {"421": {"logprob": -0.00023040501400828362, "rank": 1}}, {"856": {"logprob": -8.237022848334163e-05, "rank": 1}}, {"366": {"logprob": -0.0003231241717003286, "rank": 1}}, {"25964": {"logprob": -0.00012444675667211413, "rank": 1}}, {"921": {"logprob": -0.00883361604064703, "rank": 1}}, {"262": {"logprob": -2.8609820219571702e-05, "rank": 1}}, {"6149": {"logprob": -0.0168969314545393, "rank": 1}}, {"284": {"logprob": -0.0002779574424494058, "rank": 1}}, {"508": {"logprob": -9.095255518332124e-05, "rank": 1}}, {"87": {"logprob": -0.0001003691868390888, "rank": 1}}, {"369": {"logprob": -4.327203714638017e-05, "rank": 1}}, {"856": {"logprob": -5.364403477869928e-06, "rank": 1}}, {"304": {"logprob": -2.47952248173533e-05, "rank": 1}}, {"2890": {"logprob": -1.0013530300057027e-05, "rank": 1}}, {"421": {"logprob": -0.00025722055579535663, "rank": 1}}, {"856": {"logprob": -1.6093124941107817e-05, "rank": 1}}, {"621": {"logprob": -0.00026890001026913524, "rank": 1}}, {"25964": {"logprob": -8.248942322097719e-05, "rank": 1}}, {"921": {"logprob": -0.0020585316233336926, "rank": 1}}, {"262": {"logprob": -8.296622399939224e-05, "rank": 1}}, {"1290": {"logprob": -0.0008143446175381541, "rank": 1}}, {"284": {"logprob": -0.00011729506513802335, "rank": 1}}, {"508": {"logprob": -0.00018082413589581847, "rank": 1}}, {"87": {"logprob": -9.822363062994555e-05, "rank": 1}}, {"369": {"logprob": -3.7788631743751466e-05, "rank": 1}}, {"856": {"logprob": -1.1920858014491387e-05, "rank": 1}}, {"304": {"logprob": -1.0251946150674485e-05, "rank": 1}}, {"2890": {"logprob": -0.000219321038457565, "rank": 1}}, {"421": {"logprob": -0.00010668662434909493, "rank": 1}}, {"856": {"logprob": -5.4834770708112046e-05, "rank": 1}}, {"861": {"logprob": -6.854299135738984e-05, "rank": 1}}, {"25964": {"logprob": -0.00012420836719684303, "rank": 1}}, {"921": {"logprob": -0.005786572117358446, "rank": 1}}, {"262": {"logprob": -0.0006461439770646393, "rank": 1}}, {"470": {"logprob": -0.0022813265677541494, "rank": 1}}, {"3974": {"logprob": -0.0012848464539274573, "rank": 1}}, {"6860": {"logprob": -4.088794958079234e-05, "rank": 1}}, {"17646": {"logprob": -0.001450320822186768, "rank": 1}}, {"8": {"logprob": -4.6967357775429264e-05, "rank": 1}}, {"488": {"logprob": -2.7417760065873154e-05, "rank": 1}}, {"6149": {"logprob": -0.002877264516428113, "rank": 1}}, {"488": {"logprob": -3.313963316031732e-05, "rank": 1}}, {"3974": {"logprob": -0.00189268181566149, "rank": 1}}, {"6860": {"logprob": -3.9219088648678735e-05, "rank": 1}}, {"27611": {"logprob": -0.0007070187130011618, "rank": 1}}, {"8": {"logprob": -4.178679943084717, "rank": 4}, "692": {"logprob": -0.3036801517009735, "rank": 1}}]}, {"text": "In 1969, the Apollo 11 mission successfully landed the first", "prompt_logprobs": [null, {"220": {"logprob": -6.029693126678467, "rank": 10}, "314": {"logprob": -4.967193126678467, "rank": 1}}, {"121818": {"logprob": -9.606537818908691, "rank": 434}, "220": {"logprob": -0.9815381765365601, "rank": 1}}, {"24": {"logprob": -2.0329174995422363, "rank": 2}, "17": {"logprob": -1.7829174995422363, "rank": 1}}, {"11": {"logprob": -0.31987690925598145, "rank": 1}}, {"279": {"logprob": -1.9132108688354492, "rank": 1}}, {"34976": {"logprob": -2.6488564014434814, "rank": 2}, "356": {"logprob": -1.8988564014434814, "rank": 1}}, {"220": {"logprob": -0.19582052528858185, "rank": 1}}, {"98965": {"logprob": -0.2852461040019989, "rank": 1}}, {"8951": {"logprob": -0.9289902448654175, "rank": 1}}, {"7790": {"logprob": -2.858114242553711, "rank": 5}, "26039": {"logprob": -1.2331143617630005, "rank": 1}}, {"26039": {"logprob": -0.18613982200622559, "rank": 1}}, {"279": {"logprob": -1.6074539422988892, "rank": 2}, "12671": {"logprob": -0.7324539422988892, "rank": 1}}, {"1156": {"logprob": -0.012066347524523735, "rank": 1}}, {"12671": {"logprob": -0.14000581204891205, "rank": 1}}, {"389": {"logprob": -0.01755310222506523, "rank": 1}}, {"279": {"logprob": -0.002092554699629545, "rank": 1}}, {"17309": {"logprob": -0.4337178170681, "rank": 1}}, {"13": {"logprob": -0.43373528122901917, "rank": 1}}, {"32962": {"logprob": -2.1533522605895996, "rank": 3}, "1096": {"logprob": -1.27835214138031, "rank": 1}}, {"44605": {"logprob": -0.005716878920793533, "rank": 1}}, {"323": {"logprob": -0.2691037654876709, "rank": 1}}, {"37754": {"logprob": -0.13107122480869293, "rank": 1}}, {"30230": {"logprob": -0.00026842328952625394, "rank": 1}}, {"25210": {"logprob": -0.00013147920253686607, "rank": 1}}, {"7391": {"logprob": -1.5601450204849243, "rank": 3}, "6116": {"logprob": -1.1851450204849243, "rank": 1}}, {"13179": {"logprob": -2.0817222595214844, "rank": 4}, "220": {"logprob": -1.081722378730774, "rank": 1}}, {"1378": {"logprob": -3.4176437854766846, "rank": 2}, "220": {"logprob": -0.04264368489384651, "rank": 1}}, {"323": {"logprob": -0.36177992820739746, "rank": 1}}, {"264": {"logprob": -0.007384978234767914, "rank": 1}}, {"8337": {"logprob": -8.001594543457031, "rank": 3}, "4279": {"logprob": -0.0015944637125357985, "rank": 1}}, {"4115": {"logprob": -0.005849741864949465, "rank": 1}}, {"4889": {"logprob": -2.773193597793579, "rank": 3}, "389": {"logprob": -0.3981935977935791, "rank": 1}}, {"279": {"logprob": -0.12501713633537292, "rank": 1}}, {"41305": {"logprob": -0.19807034730911255, "rank": 1}}, {"11": {"logprob": -0.6754268407821655, "rank": 1}}, {"25814": {"logprob": -2.6186599731445312, "rank": 3}, "1393": {"logprob": -0.49365997314453125, "rank": 1}}, {"56329": {"logprob": -0.8500800728797913, "rank": 1}}, {"3684": {"logprob": -3.0732178688049316, "rank": 4}, "10464": {"logprob": -0.19821789860725403, "rank": 1}}, {"311": {"logprob": -4.267587184906006, "rank": 4}, "323": {"logprob": -0.39258724451065063, "rank": 1}}, {"4446": {"logprob": -0.011126614175736904, "rank": 1}}, {"1182": {"logprob": -0.004629132803529501, "rank": 1}}, {"311": {"logprob": -0.10327742993831635, "rank": 1}}, {"9234": {"logprob": -0.0027505443431437016, "rank": 1}}, {"13": {"logprob": -0.5373736619949341, "rank": 1}}]}, {"text": "Le petit prince demanda au renard ce que signifiait le mot a", "prompt_logprobs": [null, {"44744": {"logprob": -12.572216987609863, "rank": 41520}, "154822": {"logprob": -2.923779249191284, "rank": 1}}, {"41490": {"logprob": -0.9264012575149536, "rank": 1}}, {"137474": {"logprob": -13.093412399291992, "rank": 7731}, "320": {"logprob": -2.679349422454834, "rank": 1}}, {"7906": {"logprob": -6.2329559326171875, "rank": 17}, "549": {"logprob": -1.3579559326171875, "rank": 1}}, {"5672": {"logprob": -6.581137180328369, "rank": 36}, "12955": {"logprob": -1.5186371803283691, "rank": 1}}, {"567": {"logprob": -0.0030964307952672243, "rank": 1}}, {"3761": {"logprob": -4.804666519165039, "rank": 18}, "25": {"logprob": -1.8046667575836182, "rank": 1}}, {"1709": {"logprob": -0.45440393686294556, "rank": 1}}, {"1841": {"logprob": -0.639039933681488, "rank": 1}}, {"333": {"logprob": -0.02071344293653965, "rank": 1}}, {"685": {"logprob": -0.006723164115101099, "rank": 1}}, {"275": {"logprob": -0.031483713537454605, "rank": 1}}, {"512": {"logprob": -1.3050472736358643, "rank": 1}}, {"3852": {"logprob": -0.03355332463979721, "rank": 1}}, {"131231": {"logprob": -2.143789291381836, "rank": 3}, "12480": {"logprob": -0.8937894105911255, "rank": 1}}, {"6496": {"logprob": -4.5060096454108134e-05, "rank": 1}}, {"12053": {"logprob": -0.08265694230794907, "rank": 1}}, {"13": {"logprob": -1.3231407403945923, "rank": 1}}, {"1967": {"logprob": -1.6883678436279297, "rank": 1}}, {"5672": {"logprob": -0.028587035834789276, "rank": 1}}, {"567": {"logprob": -0.00023231192608363926, "rank": 1}}, {"3247": {"logprob": -4.198516845703125, "rank": 3}, "24324": {"logprob": -0.3235168755054474, "rank": 1}}, {"5011": {"logprob": -9.238292841473594e-05, "rank": 1}}, {"64": {"logprob": -0.000161038784426637, "rank": 1}}, {"1709": {"logprob": -0.9964639544487, "rank": 1}}, {"44244": {"logprob": -0.6082456707954407, "rank": 1}}, {"1841": {"logprob": -0.8662095069885254, "rank": 1}}, {"333": {"logprob": -0.00024530262453481555, "rank": 1}}, {"685": {"logprob": -0.0020377126056700945, "rank": 1}}, {"275": {"logprob": -0.00032431588624604046, "rank": 1}}, {"1884": {"logprob": -10.306013107299805, "rank": 81}, "74145": {"logprob": -0.30601295828819275, "rank": 1}}, {"261": {"logprob": -0.008320665918290615, "rank": 1}}, {"939": {"logprob": -0.0034964873921126127, "rank": 1}}, {"151101": {"logprob": -0.00400431826710701, "rank": 1}}, {"11": {"logprob": -1.565002679824829, "rank": 2}, "13": {"logprob": -0.6900027394294739, "rank": 1}}, {"1842": {"logprob": -1.4882816076278687, "rank": 1}}, {"1709": {"logprob": -0.8718181848526001, "rank": 1}}, {"4403": {"logprob": -3.8140883445739746, "rank": 10}, "26566": {"logprob": -1.5015884637832642, "rank": 1}}, {"512": {"logprob": -3.1226296424865723, "rank": 4}, "389": {"logprob": -0.9351297616958618, "rank": 1}}, {"41490": {"logprob": -2.0325772762298584, "rank": 2}, "44744": {"logprob": -0.15757738053798676, "rank": 1}}, {"326": {"logprob": -0.4843297004699707, "rank": 1}}, {"6": {"logprob": -0.07232591509819031, "rank": 1}}, {"138865": {"logprob": -0.04204629734158516, "rank": 1}}, {"6496": {"logprob": -0.004899519495666027, "rank": 1}}, {"285": {"logprob": -9.989239333663136e-05, "rank": 1}}, {"1315": {"logprob": -0.0004888770054094493, "rank": 1}}, {"11": {"logprob": -0.014798511750996113, "rank": 1}}, {"44786": {"logprob": -0.31077122688293457, "rank": 1}}, {"38832": {"logprob": -1.2125306129455566, "rank": 2}, "34467": {"logprob": -0.6500306725502014, "rank": 1}}, {"1167": {"logprob": -0.00010775939153973013, "rank": 1}}, {"62129": {"logprob": -0.02684812620282173, "rank": 1}}, {"326": {"logprob": -0.010926770977675915, "rank": 1}}, {"21997": {"logprob": -0.012683204375207424, "rank": 1}}, {"409": {"logprob": -0.05550748482346535, "rank": 1}}, {"326": {"logprob": -0.010232017375528812, "rank": 1}}, {"48052": {"logprob": -0.0007099968497641385, "rank": 1}}, {"265": {"logprob": -3.671578815556131e-05, "rank": 1}}, {"13": {"logprob": -2.3397529125213623, "rank": 2}, "1842": {"logprob": -0.21475301682949066, "rank": 1}}]}, {"text": "The gradient of the loss function with respect to the weight", "prompt_logprobs": [null, {"20129": {"logprob": -8.93679428100586, "rank": 971}, "154822": {"logprob": -4.718044281005859, "rank": 1}}, {"315": {"logprob": -0.7948035001754761, "rank": 1}}, {"279": {"logprob": -0.8554935455322266, "rank": 2}, "264": {"logprob": -0.8554935455322266, "rank": 1}}, {"4709": {"logprob": -5.191474914550781, "rank": 12}, "729": {"logprob": -0.8789747953414917, "rank": 1}}, {"729": {"logprob": -0.4046950340270996, "rank": 1}}, {"448": {"logprob": -1.2519729137420654, "rank": 1}}, {"5091": {"logprob": -0.008649504743516445, "rank": 1}}, {"311": {"logprob": -0.0007245299639180303, "rank": 1}}, {"279": {"logprob": -0.4113398492336273, "rank": 1}}, {"14314": {"logprob": -1.0141392946243286, "rank": 1}}, {"374": {"logprob": -1.0500236749649048, "rank": 1}}, {"24113": {"logprob": -2.4504289627075195, "rank": 3}, "264": {"logprob": -1.3254289627075195, "rank": 1}}, {"4566": {"logprob": -3.016113519668579, "rank": 5}, "1667": {"logprob": -0.8911135792732239, "rank": 1}}, {"1182": {"logprob": -0.33518368005752563, "rank": 1}}, {"2674": {"logprob": -0.0243801549077034, "rank": 1}}, {"27048": {"logprob": -0.009953626431524754, "rank": 1}}, {"11": {"logprob": -1.1306613683700562, "rank": 1}}, {"18915": {"logprob": -4.054294109344482, "rank": 8}, "892": {"logprob": -0.9292941093444824, "rank": 1}}, {"279": {"logprob": -0.004714800976216793, "rank": 1}}, {"8780": {"logprob": -0.008106661960482597, "rank": 1}}, {"5912": {"logprob": -0.0008181562297977507, "rank": 1}}, {"6193": {"logprob": -0.8360027074813843, "rank": 1}}, {"553": {"logprob": -0.011555761098861694, "rank": 1}}, {"6193": {"logprob": -0.0003383779258001596, "rank": 1}}, {"504": {"logprob": -1.5542991161346436, "rank": 2}, "13": {"logprob": -0.6792991161346436, "rank": 1}}, {"279": {"logprob": -0.06295906752347946, "rank": 1}}, {"2550": {"logprob": -0.01975620910525322, "rank": 1}}, {"1182": {"logprob": -0.2929789125919342, "rank": 1}}, {"311": {"logprob": -0.06669185310602188, "rank": 1}}, {"279": {"logprob": -0.006463930010795593, "rank": 1}}, {"1946": {"logprob": -0.03742450475692749, "rank": 1}}, {"13": {"logprob": -0.44941771030426025, "rank": 1}}, {"794": {"logprob": -7.993696689605713, "rank": 91}, "1096": {"logprob": -1.306196689605713, "rank": 1}}, {"65474": {"logprob": -0.03822512552142143, "rank": 1}}, {"20129": {"logprob": -1.6242085695266724, "rank": 2}, "52755": {"logprob": -0.24920859932899475, "rank": 1}}, {"36760": {"logprob": -0.003473916556686163, "rank": 1}}, {"1221": {"logprob": -2.801966667175293, "rank": 5}, "320": {"logprob": -0.676966667175293, "rank": 1}}, {"8836": {"logprob": -0.05548933148384094, "rank": 1}}, {"1817": {"logprob": -1.2364280223846436, "rank": 2}, "279": {"logprob": -0.36142802238464355, "rank": 1}}, {"4680": {"logprob": -0.08117572963237762, "rank": 1}}, {"21070": {"logprob": -7.158165454864502, "rank": 37}, "553": {"logprob": -0.9706655144691467, "rank": 1}}, {"745": {"logprob": -0.002050679875537753, "rank": 1}}, {"13": {"logprob": -7.630202770233154, "rank": 6}, "311": {"logprob": -0.005202920641750097, "rank": 1}}]}]}
scripts/results-longrep-prod-topup.json ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model": "glm-5.3-flash",
3
+ "ctx": 300000,
4
+ "gen": 2200,
5
+ "rounds": [
6
+ {
7
+ "round": 1,
8
+ "prompt_tokens": 259632,
9
+ "completion_tokens": 2712,
10
+ "wall_s": 69.2,
11
+ "finish_reason": "length",
12
+ "four_gram_max": 2,
13
+ "four_gram_top": "as a function of",
14
+ "eight_gram_max": 1,
15
+ "eight_gram_top": "The user wants a detailed, well-structured essay of",
16
+ "max_consec_line_repeat": 1,
17
+ "degenerate_4gram_ge12": false,
18
+ "tail": "nce length, output length, and the specific attention implementation used. Standardized benchmarks like MLPerf provide reference implementations, but long-context evaluation often requires custom setups.\n\nKey metrics include: prefill throughput (tokens/second for processing the input), decode throughput (tokens/second for generation, measured at various context lengths), time-to-first-token (TTFT,"
19
+ }
20
+ ],
21
+ "verdict": "PASS"
22
+ }
scripts/results-longrep-recal.json ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model": "glm-5.3-flash-recal",
3
+ "ctx": 260000,
4
+ "gen": 2200,
5
+ "rounds": [
6
+ {
7
+ "round": 1,
8
+ "prompt_tokens": 225032,
9
+ "completion_tokens": 2712,
10
+ "wall_s": 64.1,
11
+ "finish_reason": "length",
12
+ "four_gram_max": 2,
13
+ "four_gram_top": "at least 2,000 words",
14
+ "eight_gram_max": 1,
15
+ "eight_gram_top": "The user wants a detailed essay of at",
16
+ "max_consec_line_repeat": 1,
17
+ "degenerate_4gram_ge12": false,
18
+ "tail": "hmarks but degenerate during extended generation. The most informative evaluations combine these approaches, testing models under conditions that approximate real-world usage while maintaining the controlled variables needed for scientific comparison. As context windows continue to expand and models are deployed in increasingly demanding applications, the sophistication of evaluation methodologies"
19
+ },
20
+ {
21
+ "round": 2,
22
+ "prompt_tokens": 224997,
23
+ "completion_tokens": 2712,
24
+ "wall_s": 58.4,
25
+ "finish_reason": "length",
26
+ "four_gram_max": 3,
27
+ "four_gram_top": "- Why long context",
28
+ "eight_gram_max": 1,
29
+ "eight_gram_top": "The user has provided a long filler document",
30
+ "max_consec_line_repeat": 1,
31
+ "degenerate_4gram_ge12": false,
32
+ "tail": "asymmetry; per-channel/per-token grouping; outliers\n- Eviction/compression alternatives (sinks, heavy hitters) as complementary\n- Evaluation protocol: sweep precision, measure NIAH/perplexity deltas, latency, memory\n- Sensitivity of retrieval to key perturbations; softmax sensitivity\n- Practical guidance: keep K higher precision or per-channel scales; quantize V aggressively; validate at multiple\n"
33
+ }
34
+ ],
35
+ "verdict": "PASS"
36
+ }
scripts/results-recal.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"port": 18997, "model": "glm-5.3-flash-recal", "arith_correct": true, "arith_raw": "391", "long_gen_tokens": 2400, "long_gen_degenerate": false, "long_gen_tail": "colm McLean, a North Carolina trucking entrepreneur, who transformed the concept into an industry. In 1937, waiting at a New Jersey dock to deliver cotton bales, McLean watched longshoremen unload his truck and wondered why the trailer itself could not simply be lifted aboard ship. Two decades later", "greedy": [{"prompt": "What is 17*23? Answer with just the number.", "tokens": [" No", " steps", ".\n\n", "17", "*", "23", " =", " ", "39", "1", "\n\n", "What", " is", " ", "17", "*", "23", "?", " Answer", " with", " just", " the", " number", ".", " No", " steps", ".\n\n", "17", "*", "23", " =", " ", "39", "1", "\n\n", "What", " is", " ", "17", "*", "23", "?", " Answer", " with", " just", " the", " number", ".", " No", " steps"], "token_logprobs": [-0.4283646047115326, -0.8302481174468994, -0.7684009075164795, -2.117204427719116, -0.5783661603927612, -0.0016233850037679076, -0.19239051640033722, -0.01290905848145485, -0.03103969246149063, -0.0007241725688800216, -0.6487613320350647, -1.2282342910766602, -0.099908247590065, -0.17945438623428345, -0.6979775428771973, -0.22714421153068542, -0.06954788416624069, -0.0803070217370987, -0.06223234534263611, -0.005233516450971365, -0.00413954583927989, -0.0009398810216225684, -0.000753357307985425, -0.004806393291801214, -0.0025078770704567432, -0.0010458719916641712, -0.07194270938634872, -0.7732672691345215, -0.27333709597587585, -0.000514017534442246, -0.020685069262981415, -0.007856657728552818, -0.0038069647271186113, -0.0007522851810790598, -0.08510196954011917, -0.7591567635536194, -0.058796048164367676, -0.09666924178600311, -0.1526058316230774, -0.11327855288982391, -0.006106054875999689, -0.03733344003558159, -0.022014297544956207, -0.001930517959408462, -0.002409295178949833, -0.0009560781763866544, -0.00044276448898017406, -0.0055913482792675495, -0.0021686863619834185, -0.0005178302526473999]}, {"prompt": "Write a Python function that returns the nth Fibonacci number iteratively.", "tokens": [" The", " function", " should", " handle", " edge", " cases", " such", " as", " n", " being", " ", "0", " or", " negative", ",", " and", " should", " raise", " a", " ValueError", " for", " negative", " inputs", ".", " Include", " a", " doc", "string", " explaining", " the", " function", "'s", " purpose", ",", " parameters", ",", " and", " return", " value", ".", " Also", ",", " provide", " a", " brief", " explanation", " of", " how", " the", " iterative"], "token_logprobs": [-1.7125780582427979, -0.4118247628211975, -0.06626643240451813, -0.8713309168815613, -1.0301413536071777, -0.001022769371047616, -1.1581568717956543, -0.000692961853928864, -0.4308229982852936, -1.2453869581222534, -0.40210381150245667, -0.014363117516040802, -0.06541772931814194, -0.4419555366039276, -0.7307236194610596, -0.3139662742614746, -1.110009789466858, -1.1964412927627563, -0.21601350605487823, -0.02184286154806614, -0.4048725366592407, -0.5554516911506653, -0.3687801659107208, -0.7828818559646606, -1.351998209953308, -1.1804431676864624, -0.44461870193481445, -9.619726915843785e-05, -1.0190600156784058, -0.06387954205274582, -0.1252431720495224, -0.11087284237146378, -0.3524990379810333, -0.3216642737388611, -0.2980508804321289, -0.0005819296347908676, -0.22718894481658936, -0.010853542946279049, -0.06558777391910553, -0.6468213796615601, -1.2185460329055786, -0.04967788979411125, -0.3311481475830078, -1.0537712574005127, -0.7178796529769897, -0.6968652009963989, -0.003608265658840537, -0.4601861238479614, -0.02148589864373207, -0.16876986622810364]}, {"prompt": "Explain the difference between TCP and UDP in two sentences.", "tokens": [" TCP", " is", " a", " connection", "-oriented", " protocol", " that", " guarantees", " reliable", " delivery", " of", " data", ",", " while", " UDP", " is", " a", " connection", "less", " protocol", " that", " offers", " faster", " transmission", " but", " no", " guarantee", " of", " delivery", ".", " TCP", " is", " used", " for", " applications", " that", " require", " reliability", ",", " such", " as", " web", " browsing", " and", " file", " transfer", ",", " while", " UDP", " is"], "token_logprobs": [-2.090955972671509, -0.5807188153266907, -0.6299022436141968, -0.094386987388134, -0.0746878907084465, -0.07779927551746368, -0.07845890522003174, -0.747550904750824, -0.5429121255874634, -0.9415457248687744, -0.24737223982810974, -0.16371817886829376, -0.8035799264907837, -0.07114866375923157, -0.0016529004788026214, -0.0022967883851379156, -0.20383068919181824, -0.009675039909780025, -0.0039132460951805115, -0.005179083440452814, -0.042136818170547485, -0.7342923879623413, -0.6511363387107849, -0.397271990776062, -0.05916476994752884, -0.7529175281524658, -0.3890419900417328, -0.01524322759360075, -0.07018107920885086, -0.7142979502677917, -0.6906774640083313, -1.079809308052063, -0.6512539982795715, -0.08807812631130219, -0.037931352853775024, -1.201765775680542, -0.014155339449644089, -0.9300481081008911, -0.10236047208309174, -0.26440510153770447, -0.0012617491884157062, -0.43938934803009033, -0.0037161121144890785, -0.06061328947544098, -0.3512558043003082, -0.05963242053985596, -0.011930185370147228, -0.024258339777588844, -0.002258847001940012, -0.000878544058650732]}, {"prompt": "Translate to French: 'The quick brown fox jumps over the lazy dog.'", "tokens": [" The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".", " Translate", " to", " French", ":", " '", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".'", " The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".", " Translate", " to", " French", ":", " '", "The", " quick", " brown", " fox", " jumps", " over", " the", " lazy", " dog", ".'"], "token_logprobs": [-1.1523641347885132, -0.2720477879047394, -0.003867766121402383, -0.0030585199128836393, -0.012130653485655785, -0.0009170140838250518, -0.0012963948538526893, -0.002657455625012517, -0.00037377048283815384, -0.5484561920166016, -0.7724074721336365, -0.1692289412021637, -0.4490843117237091, -0.07576142251491547, -0.030435331165790558, -0.3027973175048828, -0.09130847454071045, -0.0012478192802518606, -0.0011681645410135388, -0.001986198825761676, -0.0005021026590839028, -0.00030620177858509123, -0.00042524831951595843, -0.0005006728461012244, -0.09140682965517044, -0.11110466718673706, -0.006918403785675764, -0.00017069313616957515, -0.0004648081958293915, -0.00046433156239800155, -0.00014101465058047324, -0.0005024601123295724, -0.00010466027742950246, -0.0004822045157197863, -0.1681683361530304, -0.3355959951877594, -0.004126368090510368, -0.019850173965096474, -0.0024078681599348783, -0.0019803689792752266, -0.005063922610133886, -0.003282280405983329, -0.0012979424791410565, -0.0007796823629178107, -0.0010578995570540428, -0.0015069806249812245, -0.00040880427695810795, -0.00047803416964598, -0.00238277530297637, -0.010288417339324951]}, {"prompt": "List the first 8 prime numbers separated by commas.", "tokens": [" The", " first", " ", "8", " prime", " numbers", " are", " ", "2", ",", " ", "3", ",", " ", "5", ",", " ", "7", ",", " ", "11", ",", " ", "13", ",", " ", "17", ",", " ", "19", ".", " The", " first", " ", "8", " prime", " numbers", " are", " ", "2", ",", " ", "3", ",", " ", "5", ",", " ", "7", ","], "token_logprobs": [-1.9227274656295776, -0.36947253346443176, -0.8774216175079346, -0.3116287887096405, -0.16907936334609985, -0.01911165751516819, -0.3083363473415375, -0.7933971285820007, -0.020083412528038025, -0.021743718534708023, -0.0749625489115715, -0.0073406025767326355, -0.005515476688742638, -0.01110044214874506, -0.0010720703285187483, -0.01756809465587139, -0.022437982261180878, -0.00117649941239506, -0.021333975717425346, -0.012800903990864754, -0.0036791746970266104, -0.004396890755742788, -0.0367869958281517, -0.0010638536186888814, -0.04046918824315071, -0.06783471256494522, -0.0025001477915793657, -0.02640831284224987, -0.38845351338386536, -0.004914585035294294, -0.8016967177391052, -1.3962464332580566, -0.6582569479942322, -0.2056090533733368, -0.0720541924238205, -0.10379152745008469, -0.006433726754039526, -0.10055345296859741, -0.12687954306602478, -0.008681177161633968, -0.007219062652438879, -0.0019591916352510452, -0.004031982738524675, -0.0029844765085726976, -0.0007657456444576383, -0.001416394836269319, -0.0035835590679198503, -0.0012085284106433392, -0.002910427749156952, -0.010971812531352043]}, {"prompt": "What year did the Apollo 11 mission land on the moon? One word answer.", "tokens": [" ", "196", "9", ".", " What", " is", " the", " capital", " of", " France", "?", " Paris", ".", " What", " is", " the", " chemical", " symbol", " for", " gold", "?", " Au", ".", " What", " is", " the", " largest", " planet", " in", " our", " solar", " system", "?", " Jupiter", ".", " What", " is", " the", " smallest", " country", " in", " the", " world", "?", " Vatican", " City", ".", " What", " is", " the"], "token_logprobs": [-2.7124290466308594, -0.3913920223712921, -0.01463863905519247, -1.092811942100525, -2.1443774700164795, -1.3379065990447998, -0.13503849506378174, -0.958187460899353, -0.285135418176651, -0.18988151848316193, -0.02478097379207611, -0.5247228145599365, -0.09138224273920059, -0.9088083505630493, -0.20166923105716705, -0.2834227383136749, -0.7886925339698792, -0.030525637790560722, -0.009081723168492317, -0.17181292176246643, -0.012758180499076843, -0.09472210705280304, -0.08664198964834213, -0.7232208251953125, -0.10857682675123215, -0.028182869777083397, -0.9209654927253723, -0.1850530207157135, -0.007249833550304174, -0.03830544278025627, -0.021468747407197952, -0.0032597046811133623, -0.007155505940318108, -0.03332309052348137, -0.14019833505153656, -0.6948305368423462, -0.09906408935785294, -0.014980672858655453, -1.4651743173599243, -0.6528022289276123, -0.006624167785048485, -0.0046563055366277695, -0.0031499075703322887, -0.07221724092960358, -0.09695599228143692, -0.02494516409933567, -0.08302673697471619, -0.37270092964172363, -0.052639178931713104, -0.008783986791968346]}, {"prompt": "Summarize the plot of Romeo and Juliet in one sentence.", "tokens": [" a", ")", " Two", " fe", "uding", " families", "'", " children", " fall", " in", " love", ",", " leading", " to", " tragedy", ".", " b", ")", " Romeo", " and", " Juliet", "'s", " love", " conqu", "ers", " all", " obstacles", ".", " c", ")", " A", " tale", " of", " two", " star", "-cross", "ed", " lovers", " in", " Ver", "ona", ".", " d", ")", " Juliet", "'s", " family", " approves", " of", " Romeo"], "token_logprobs": [-2.3392810821533203, -0.10204856842756271, -1.361631989479065, -0.5811580419540405, -0.0005198557628318667, -0.09456302225589752, -0.6495636105537415, -0.005426201969385147, -0.09120042622089386, -0.0004615910293068737, -0.00010191874753218144, -0.2914047837257385, -0.13328774273395538, -0.00018737945356406271, -0.7392728924751282, -0.4069141149520874, -0.005618376191705465, -0.00024768622824922204, -0.7918832302093506, -0.10475999861955643, -0.0008551992941647768, -0.6953730583190918, -0.822887122631073, -0.8305034637451172, -0.0001867835089797154, -0.15267275273799896, -0.09982873499393463, -0.016188016161322594, -0.0003054867556784302, -0.00011765264935093, -1.0296519994735718, -0.9595357775688171, -9.512448741588742e-05, -1.5427056550979614, -0.7888911962509155, -0.002102428348734975, -0.0001147919538198039, -0.0014054430648684502, -1.030067801475525, -0.6341811418533325, -0.00017975145601667464, -0.03642084449529648, -0.00011324241495458409, -6.186770770000294e-05, -0.9281691312789917, -0.22670204937458038, -1.588585615158081, -0.766884446144104, -0.002062814310193062, -0.4287776052951813]}, {"prompt": "Write a SQL query selecting the top 5 customers by total order value from tables customers(id,name) and orders(id,customer_id,value).", "tokens": [" Show", " customer", " name", " and", " total", " value", ".\n\n", "SQL", " Query", " for", " Top", " ", "5", " Customers", " by", " Total", " Order", " Value", "\n\n", "Here", "'s", " the", " SQL", " query", " to", " select", " the", " top", " ", "5", " customers", " by", " total", " order", " value", ":\n\n", "```", "sql", "\n", "SELECT", " \n", " ", " c", ".name", ",\n", " ", " SUM", "(o", ".value", ")"], "token_logprobs": [-1.6018240451812744, -0.9797091484069824, -0.04700856655836105, -0.05061054602265358, -0.2660576403141022, -0.5960054993629456, -0.9499276876449585, -2.297227621078491, -1.144747018814087, -0.7545561790466309, -0.006804035045206547, -0.03843094781041145, -8.809178689261898e-05, -0.0005497612874023616, -0.11588076502084732, -0.05537891760468483, -0.0021207479294389486, -8.630380034446716e-05, -0.006848789751529694, -0.6885873675346375, -0.027542104944586754, -0.35561972856521606, -0.007601502817124128, -0.001456867903470993, -0.3115942180156708, -0.7130357027053833, -0.0012830605264753103, -9.476689592702314e-05, -6.735097849741578e-05, -1.4662635294371285e-05, -6.174850568640977e-05, -0.003825371852144599, -0.00872194766998291, -0.00016199229867197573, -0.000746448349673301, -0.1673102229833603, -0.5343515872955322, -0.010359915904700756, -0.0013297295663505793, -0.014357241801917553, -0.3822961151599884, -0.0005974177038297057, -0.0017119289841502905, -0.048926349729299545, -0.705405592918396, -3.635817120084539e-05, -0.005964101292192936, -0.0005857420619577169, -0.00032693761750124395, -5.793403761344962e-05]}, {"prompt": "What is the derivative of x^3 + 2x with respect to x?", "tokens": ["...", " |", " Fil", "o", "\n\n", "Question", "\n\n", "Question", "\n\n", "What", " is", " the", " derivative", " of", " x", "^", "3", " +", " ", "2", "x", " with", " respect", " to", " x", "?\n\n", "What", " is", " the", " derivative", " of", " x", "^", "3", " +", " ", "2", "x", " with", " respect", " to", " x", "?\n\n", "Asked", " Feb", " ", "25", " at", " ", "05"], "token_logprobs": [-1.0744279623031616, -0.008752081543207169, -0.10809064656496048, -0.00011896379146492109, -0.006470681168138981, -0.494012713432312, -0.002767900936305523, -0.0001597276859683916, -0.4611479640007019, -1.1507537364959717, -0.0002992897352669388, -0.0005302215577103198, -0.0006624649395234883, -9.965400386136025e-05, -0.24284321069717407, -0.0005015069036744535, -6.985420623095706e-05, -0.00016878610767889768, -2.6225699912174605e-05, -2.002696055569686e-05, -1.168244216387393e-05, -0.0009104635682888329, -1.3470558769768104e-05, -2.7179348762729205e-05, -0.0005187834613025188, -0.07130607962608337, -0.44891107082366943, -0.0007736074039712548, -0.000972036796156317, -0.0009658439084887505, -8.582700684200972e-05, -0.02769053727388382, -0.0016212427290156484, -6.592056161025539e-05, -0.00028534632292576134, -4.0411134250462055e-05, -1.2040065485052764e-05, -3.564294092939235e-05, -0.0013760393485426903, -7.152555099310121e-07, -4.529942543740617e-06, -0.00020168177434243262, -0.01772363670170307, -0.9932729005813599, -0.5437155365943909, -0.008759289979934692, -1.4395854473114014, -0.00016199229867197573, -0.0001705739414319396, -2.2031147480010986]}, {"prompt": "Name the chemical symbol for gold and the element with atomic number 6.", "tokens": [" Also", ",", " what", " is", " the", " chemical", " symbol", " for", " sodium", "?\n\n", "Under", "stand", " the", " Problem", "\n\n", "The", " question", " is", " asking", " for", " the", " chemical", " symbols", " of", " gold", " and", " sodium", ",", " as", " well", " as", " the", " element", " with", " atomic", " number", " ", "6", ".", " This", " is", " a", " straightforward", " chemistry", " question", ".\n\n", "Answer", "\n\n", "Gold", ":"], "token_logprobs": [-2.2000410556793213, -0.17005524039268494, -1.8717553615570068, -0.5096925497055054, -0.17935913801193237, -1.6047992706298828, -0.4883747696876526, -0.06896502524614334, -1.721140742301941, -0.5719624757766724, -1.2447757720947266, -0.002695262897759676, -0.0002731903805397451, -0.0044097090139985085, -5.590759246842936e-05, -0.002639264799654484, -0.05336974188685417, -0.2923423945903778, -0.010575325228273869, -0.12636613845825195, -0.4551885724067688, -0.008549043908715248, -0.5778136253356934, -0.30563753843307495, -0.9775493741035461, -0.5769633054733276, -0.12113772332668304, -0.009877494536340237, -0.3929138779640198, -1.0132738680113107e-05, -4.362964682513848e-05, -0.05101730301976204, -0.6842418313026428, -0.04075660929083824, -0.012288807891309261, -6.198863957251888e-06, -2.658331868587993e-05, -1.9788545614574105e-05, -0.2618888318538666, -0.49099308252334595, -1.0397895574569702, -0.09386748820543289, -0.5011305212974548, -0.7632831335067749, -0.8371487259864807, -1.0974842309951782, -0.0003195490571670234, -2.825220326485578e-05, -0.2264319360256195, -0.17046868801116943]}], "scored": [{"text": "The mitochondrion is the powerhouse of the cell, converting ", "prompt_logprobs": [null, {"53582": {"logprob": -11.88830852508545, "rank": 20834}, "154822": {"logprob": -4.341433525085449, "rank": 1}}, {"81": {"logprob": -0.976696789264679, "rank": 2}, "4204": {"logprob": -0.47669678926467896, "rank": 1}}, {"290": {"logprob": -8.702239938429557e-06, "rank": 1}}, {"374": {"logprob": -0.5717750787734985, "rank": 1}}, {"279": {"logprob": -1.036670446395874, "rank": 1}}, {"73538": {"logprob": -3.7466423511505127, "rank": 3}, "1240": {"logprob": -0.24664238095283508, "rank": 1}}, {"315": {"logprob": -0.09506958723068237, "rank": 1}}, {"279": {"logprob": -0.026692954823374748, "rank": 1}}, {"2779": {"logprob": -0.015260251238942146, "rank": 1}}, {"11": {"logprob": -1.3379920721054077, "rank": 2}, "13": {"logprob": -1.0879920721054077, "rank": 1}}, {"33277": {"logprob": -3.904132843017578, "rank": 11}, "323": {"logprob": -1.5291329622268677, "rank": 1}}, {"36209": {"logprob": -1.4794025421142578, "rank": 2}, "4802": {"logprob": -1.3544025421142578, "rank": 1}}, {"1119": {"logprob": -0.1331220418214798, "rank": 1}}, {"993": {"logprob": -3.0450491905212402, "rank": 3}, "66072": {"logprob": -0.4200492799282074, "rank": 1}}, {"70338": {"logprob": -0.0003352795320097357, "rank": 1}}, {"482": {"logprob": -7.939023635117337e-05, "rank": 1}}, {"2406": {"logprob": -0.0007200032705441117, "rank": 1}}, {"759": {"logprob": -0.0009296386269852519, "rank": 1}}, {"91597": {"logprob": -0.0002631794777698815, "rank": 1}}, {"1526": {"logprob": -3.6748030185699463, "rank": 2}, "320": {"logprob": -0.0498029962182045, "rank": 1}}, {"77673": {"logprob": -1.29654860496521, "rank": 2}, "34423": {"logprob": -0.7965485453605652, "rank": 1}}, {"93199": {"logprob": -0.00412779301404953, "rank": 1}}, {"2302": {"logprob": -0.00014065706636756659, "rank": 1}}, {"13": {"logprob": -0.5752795338630676, "rank": 1}}, {"1096": {"logprob": -2.4610178470611572, "rank": 3}, "21714": {"logprob": -1.3985178470611572, "rank": 1}}, {"1882": {"logprob": -0.7489160299301147, "rank": 1}}, {"13657": {"logprob": -3.69407320022583, "rank": 10}, "33482": {"logprob": -1.5690733194351196, "rank": 1}}, {"3941": {"logprob": -1.1760808229446411, "rank": 2}, "518": {"logprob": -1.1760808229446411, "rank": 1}}, {"279": {"logprob": -0.2964847981929779, "rank": 1}}, {"9176": {"logprob": -0.11559481918811798, "rank": 1}}, {"70428": {"logprob": -0.23392535746097565, "rank": 1}}, {"38346": {"logprob": -0.08119023591279984, "rank": 1}}, {"11": {"logprob": -0.5858933329582214, "rank": 1}}, {"1380": {"logprob": -1.9772648811340332, "rank": 2}, "892": {"logprob": -0.7272648811340332, "rank": 1}}, {"279": {"logprob": -0.6106369495391846, "rank": 1}}, {"16698": {"logprob": -0.4787136912345886, "rank": 1}}, {"7557": {"logprob": -0.00492016039788723, "rank": 1}}, {"8780": {"logprob": -0.001347110839560628, "rank": 1}}, {"63111": {"logprob": -1.8965904712677002, "rank": 2}, "320": {"logprob": -1.8965904712677002, "rank": 1}}, {"264": {"logprob": -0.09094314277172089, "rank": 1}}, {"80822": {"logprob": -0.003181635867804289, "rank": 1}}, {"20129": {"logprob": -0.06077831983566284, "rank": 1}}, {"13": {"logprob": -1.994498610496521, "rank": 2}, "429": {"logprob": -0.4944986402988434, "rank": 1}}]}, {"text": "def quicksort(arr):\n if len(arr) <= 1:\n return arr", "prompt_logprobs": [null, {"3974": {"logprob": -7.575308322906494, "rank": 230}, "1815": {"logprob": -2.356558322906494, "rank": 1}}, {"6860": {"logprob": -0.2686464190483093, "rank": 1}}, {"10934": {"logprob": -0.7622413635253906, "rank": 1}}, {"982": {"logprob": -0.7858560085296631, "rank": 2}, "11": {"logprob": -0.6608560085296631, "rank": 1}}, {"262": {"logprob": -0.08289364725351334, "rank": 1}}, {"421": {"logprob": -0.17532221972942352, "rank": 1}}, {"2422": {"logprob": -0.02028563991189003, "rank": 1}}, {"10934": {"logprob": -0.0005225961795076728, "rank": 1}}, {"8": {"logprob": -0.061090465635061264, "rank": 1}}, {"2651": {"logprob": -0.1808052957057953, "rank": 1}}, {"220": {"logprob": -0.023333726450800896, "rank": 1}}, {"16": {"logprob": -0.0004866131057497114, "rank": 1}}, {"510": {"logprob": -0.015296528115868568, "rank": 1}}, {"286": {"logprob": -0.0012301980750635266, "rank": 1}}, {"470": {"logprob": -0.00012957210128661245, "rank": 1}}, {"2890": {"logprob": -0.00175453198608011, "rank": 1}}, {"198": {"logprob": -0.08293380588293076, "rank": 1}}, {"262": {"logprob": -0.0005878866068087518, "rank": 1}}, {"25964": {"logprob": -0.22315366566181183, "rank": 1}}, {"284": {"logprob": -0.008056524209678173, "rank": 1}}, {"2890": {"logprob": -0.0010807631770148873, "rank": 1}}, {"24617": {"logprob": -0.16870814561843872, "rank": 1}}, {"10934": {"logprob": -0.00091856240760535, "rank": 1}}, {"8": {"logprob": -0.320453405380249, "rank": 1}}, {"442": {"logprob": -0.020847247913479805, "rank": 1}}, {"220": {"logprob": -0.0025009801611304283, "rank": 1}}, {"17": {"logprob": -0.0022025867365300655, "rank": 1}}, {"921": {"logprob": -0.02611871063709259, "rank": 1}}, {"262": {"logprob": -0.0007001094636507332, "rank": 1}}, {"2115": {"logprob": -0.06169889122247696, "rank": 1}}, {"284": {"logprob": -0.003107839496806264, "rank": 1}}, {"508": {"logprob": -0.004781835246831179, "rank": 1}}, {"87": {"logprob": -0.0019395602867007256, "rank": 1}}, {"369": {"logprob": -0.0003147821989841759, "rank": 1}}, {"856": {"logprob": -4.2199197196168825e-05, "rank": 1}}, {"304": {"logprob": -4.279521817807108e-05, "rank": 1}}, {"2890": {"logprob": -0.00010311071673640981, "rank": 1}}, {"421": {"logprob": -0.00023445718397852033, "rank": 1}}, {"856": {"logprob": -0.00040189296123571694, "rank": 1}}, {"366": {"logprob": -0.0007267932523973286, "rank": 1}}, {"25964": {"logprob": -0.00019131260341964662, "rank": 1}}, {"921": {"logprob": -0.014532433822751045, "rank": 1}}, {"262": {"logprob": -7.188061863416806e-05, "rank": 1}}, {"6149": {"logprob": -0.06814421713352203, "rank": 1}}, {"284": {"logprob": -0.0012931802775710821, "rank": 1}}, {"508": {"logprob": -0.00021908267808612436, "rank": 1}}, {"87": {"logprob": -5.9126061387360096e-05, "rank": 1}}, {"369": {"logprob": -9.16677454370074e-05, "rank": 1}}, {"856": {"logprob": -2.729855441430118e-05, "rank": 1}}, {"304": {"logprob": -5.4238757002167404e-05, "rank": 1}}, {"2890": {"logprob": -2.0861407392658293e-05, "rank": 1}}, {"421": {"logprob": -0.0002650863316375762, "rank": 1}}, {"856": {"logprob": -3.373566141817719e-05, "rank": 1}}, {"621": {"logprob": -0.0009291622554883361, "rank": 1}}, {"25964": {"logprob": -0.00017867876158561558, "rank": 1}}, {"921": {"logprob": -0.0041108159348368645, "rank": 1}}, {"262": {"logprob": -0.0006653240998275578, "rank": 1}}, {"1290": {"logprob": -0.0016655157087370753, "rank": 1}}, {"284": {"logprob": -0.0005004345439374447, "rank": 1}}, {"508": {"logprob": -0.0007721779984422028, "rank": 1}}, {"87": {"logprob": -6.401333666872233e-05, "rank": 1}}, {"369": {"logprob": -5.340433563105762e-05, "rank": 1}}, {"856": {"logprob": -1.168244216387393e-05, "rank": 1}}, {"304": {"logprob": -5.8412379075889476e-06, "rank": 1}}, {"2890": {"logprob": -0.00013565097469836473, "rank": 1}}, {"421": {"logprob": -0.0003771070914808661, "rank": 1}}, {"856": {"logprob": -4.2914423829643056e-05, "rank": 1}}, {"861": {"logprob": -0.00018630675913300365, "rank": 1}}, {"25964": {"logprob": -0.00010752100206445903, "rank": 1}}, {"921": {"logprob": -0.012149614281952381, "rank": 1}}, {"262": {"logprob": -0.0031711787451058626, "rank": 1}}, {"470": {"logprob": -0.004390481859445572, "rank": 1}}, {"3974": {"logprob": -0.0016160060185939074, "rank": 1}}, {"6860": {"logprob": -3.45700973412022e-05, "rank": 1}}, {"17646": {"logprob": -0.002913280390202999, "rank": 1}}, {"8": {"logprob": -0.00032395837479270995, "rank": 1}}, {"488": {"logprob": -5.4834770708112046e-05, "rank": 1}}, {"6149": {"logprob": -0.009906177408993244, "rank": 1}}, {"488": {"logprob": -6.735097849741578e-05, "rank": 1}}, {"3974": {"logprob": -0.0002640137099660933, "rank": 1}}, {"6860": {"logprob": -1.7762025890988298e-05, "rank": 1}}, {"27611": {"logprob": -0.000482442817883566, "rank": 1}}, {"8": {"logprob": -3.615476608276367, "rank": 4}, "692": {"logprob": -0.3654765188694, "rank": 1}}]}, {"text": "In 1969, the Apollo 11 mission successfully landed the first", "prompt_logprobs": [null, {"220": {"logprob": -7.480617523193359, "rank": 64}, "154822": {"logprob": -1.6056172847747803, "rank": 1}}, {"121818": {"logprob": -6.2249884605407715, "rank": 64}, "17": {"logprob": -2.1624884605407715, "rank": 1}}, {"24": {"logprob": -1.972672700881958, "rank": 2}, "23": {"logprob": -1.972672700881958, "rank": 1}}, {"11": {"logprob": -0.36826807260513306, "rank": 1}}, {"279": {"logprob": -1.79671049118042, "rank": 1}}, {"34976": {"logprob": -2.965151786804199, "rank": 2}, "356": {"logprob": -1.6526517868041992, "rank": 1}}, {"220": {"logprob": -0.36428818106651306, "rank": 1}}, {"98965": {"logprob": -0.17343902587890625, "rank": 1}}, {"8951": {"logprob": -0.887779712677002, "rank": 1}}, {"7790": {"logprob": -2.6589407920837402, "rank": 5}, "26039": {"logprob": -1.0339406728744507, "rank": 1}}, {"26039": {"logprob": -0.14171536266803741, "rank": 1}}, {"279": {"logprob": -1.7570018768310547, "rank": 2}, "12671": {"logprob": -0.8820018172264099, "rank": 1}}, {"1156": {"logprob": -0.01747344620525837, "rank": 1}}, {"12671": {"logprob": -0.14814411103725433, "rank": 1}}, {"389": {"logprob": -0.02152218483388424, "rank": 1}}, {"279": {"logprob": -0.0021354984492063522, "rank": 1}}, {"17309": {"logprob": -0.6993345022201538, "rank": 1}}, {"13": {"logprob": -0.508336067199707, "rank": 1}}, {"32962": {"logprob": -1.9407068490982056, "rank": 3}, "1096": {"logprob": -1.4407068490982056, "rank": 1}}, {"44605": {"logprob": -0.0060303411446511745, "rank": 1}}, {"323": {"logprob": -0.2022213637828827, "rank": 1}}, {"37754": {"logprob": -0.10406894236803055, "rank": 1}}, {"30230": {"logprob": -0.00046921687317080796, "rank": 1}}, {"25210": {"logprob": -0.00011419598013162613, "rank": 1}}, {"7391": {"logprob": -1.8751344680786133, "rank": 3}, "6116": {"logprob": -0.7501344084739685, "rank": 1}}, {"13179": {"logprob": -2.2342491149902344, "rank": 5}, "220": {"logprob": -1.234249234199524, "rank": 1}}, {"1378": {"logprob": -2.358257293701172, "rank": 2}, "220": {"logprob": -0.1082572266459465, "rank": 1}}, {"323": {"logprob": -0.1909279227256775, "rank": 1}}, {"264": {"logprob": -0.010183047503232956, "rank": 1}}, {"8337": {"logprob": -8.188130378723145, "rank": 2}, "4279": {"logprob": -0.0006299418746493757, "rank": 1}}, {"4115": {"logprob": -0.004795359913259745, "rank": 1}}, {"4889": {"logprob": -2.0878002643585205, "rank": 3}, "389": {"logprob": -0.7128003239631653, "rank": 1}}, {"279": {"logprob": -0.1015268936753273, "rank": 1}}, {"41305": {"logprob": -0.10137588530778885, "rank": 1}}, {"11": {"logprob": -0.6127365827560425, "rank": 1}}, {"25814": {"logprob": -2.4811112880706787, "rank": 3}, "1393": {"logprob": -0.35611119866371155, "rank": 1}}, {"56329": {"logprob": -0.9727568626403809, "rank": 1}}, {"3684": {"logprob": -1.9196480512619019, "rank": 2}, "10464": {"logprob": -0.29464805126190186, "rank": 1}}, {"311": {"logprob": -3.663879632949829, "rank": 4}, "323": {"logprob": -0.2888796925544739, "rank": 1}}, {"4446": {"logprob": -0.008053804747760296, "rank": 1}}, {"1182": {"logprob": -0.0013903246726840734, "rank": 1}}, {"311": {"logprob": -0.06407589465379715, "rank": 1}}, {"9234": {"logprob": -0.0017547699389979243, "rank": 1}}, {"13": {"logprob": -0.2483280450105667, "rank": 1}}]}, {"text": "Le petit prince demanda au renard ce que signifiait le mot a", "prompt_logprobs": [null, {"44744": {"logprob": -15.774243354797363, "rank": 21121}, "154822": {"logprob": -0.016431139782071114, "rank": 1}}, {"41490": {"logprob": -1.6070984601974487, "rank": 1}}, {"137474": {"logprob": -13.035755157470703, "rank": 7549}, "284": {"logprob": -2.012317419052124, "rank": 1}}, {"7906": {"logprob": -4.875985145568848, "rank": 11}, "549": {"logprob": -1.2509849071502686, "rank": 1}}, {"5672": {"logprob": -6.697552680969238, "rank": 39}, "73000": {"logprob": -1.7600524425506592, "rank": 1}}, {"567": {"logprob": -0.0008012421894818544, "rank": 1}}, {"3761": {"logprob": -4.256261825561523, "rank": 11}, "25": {"logprob": -1.8812617063522339, "rank": 1}}, {"1709": {"logprob": -0.24003396928310394, "rank": 1}}, {"1841": {"logprob": -0.6200358271598816, "rank": 1}}, {"333": {"logprob": -0.008285081014037132, "rank": 1}}, {"685": {"logprob": -0.002595986006781459, "rank": 1}}, {"275": {"logprob": -0.004389532376080751, "rank": 1}}, {"512": {"logprob": -2.3708930015563965, "rank": 3}, "12480": {"logprob": -0.6208929419517517, "rank": 1}}, {"3852": {"logprob": -0.01753881201148033, "rank": 1}}, {"131231": {"logprob": -1.6062474250793457, "rank": 3}, "12480": {"logprob": -0.7312474846839905, "rank": 1}}, {"6496": {"logprob": -5.1377883210079744e-05, "rank": 1}}, {"12053": {"logprob": -0.2506871521472931, "rank": 1}}, {"13": {"logprob": -1.3148317337036133, "rank": 1}}, {"1967": {"logprob": -1.235216736793518, "rank": 1}}, {"5672": {"logprob": -0.03868994116783142, "rank": 1}}, {"567": {"logprob": -0.0002735478919930756, "rank": 1}}, {"3247": {"logprob": -4.084001064300537, "rank": 4}, "24324": {"logprob": -0.33400094509124756, "rank": 1}}, {"5011": {"logprob": -0.00015960850578267127, "rank": 1}}, {"64": {"logprob": -0.0003146630187984556, "rank": 1}}, {"1709": {"logprob": -0.6572995781898499, "rank": 1}}, {"44244": {"logprob": -0.6856521368026733, "rank": 1}}, {"1841": {"logprob": -1.0484671592712402, "rank": 2}, "136015": {"logprob": -0.7984670996665955, "rank": 1}}, {"333": {"logprob": -0.000735608336981386, "rank": 1}}, {"685": {"logprob": -0.0027479289565235376, "rank": 1}}, {"275": {"logprob": -0.0019393223337829113, "rank": 1}}, {"1884": {"logprob": -9.258537292480469, "rank": 46}, "74145": {"logprob": -0.25853681564331055, "rank": 1}}, {"261": {"logprob": -0.0052758511155843735, "rank": 1}}, {"939": {"logprob": -0.003109622048214078, "rank": 1}}, {"151101": {"logprob": -0.00441350694745779, "rank": 1}}, {"11": {"logprob": -1.9404969215393066, "rank": 2}, "13": {"logprob": -0.6904968619346619, "rank": 1}}, {"1842": {"logprob": -1.7482638359069824, "rank": 2}, "1884": {"logprob": -1.3732638359069824, "rank": 1}}, {"1709": {"logprob": -1.00454843044281, "rank": 1}}, {"4403": {"logprob": -3.0520520210266113, "rank": 6}, "26566": {"logprob": -1.6770519018173218, "rank": 1}}, {"512": {"logprob": -2.200911045074463, "rank": 3}, "326": {"logprob": -0.7634111642837524, "rank": 1}}, {"41490": {"logprob": -3.5975301265716553, "rank": 3}, "44744": {"logprob": -0.09753023087978363, "rank": 1}}, {"326": {"logprob": -0.5964891314506531, "rank": 1}}, {"6": {"logprob": -0.13926775753498077, "rank": 1}}, {"138865": {"logprob": -0.022586939856410027, "rank": 1}}, {"6496": {"logprob": -0.08105723559856415, "rank": 1}}, {"285": {"logprob": -0.00013469743134919554, "rank": 1}}, {"1315": {"logprob": -0.0005261705373413861, "rank": 1}}, {"11": {"logprob": -0.03950696811079979, "rank": 1}}, {"44786": {"logprob": -0.5267423391342163, "rank": 1}}, {"38832": {"logprob": -2.8039584159851074, "rank": 3}, "34467": {"logprob": -0.49145829677581787, "rank": 1}}, {"1167": {"logprob": -4.2676016164477915e-05, "rank": 1}}, {"62129": {"logprob": -0.0924116000533104, "rank": 1}}, {"326": {"logprob": -0.026161447167396545, "rank": 1}}, {"21997": {"logprob": -0.0627172589302063, "rank": 1}}, {"409": {"logprob": -0.05548763647675514, "rank": 1}}, {"326": {"logprob": -0.004424425773322582, "rank": 1}}, {"48052": {"logprob": -0.001262344536371529, "rank": 1}}, {"265": {"logprob": -0.000164018536452204, "rank": 1}}, {"13": {"logprob": -1.8726966381072998, "rank": 2}, "1842": {"logprob": -0.24769659340381622, "rank": 1}}]}, {"text": "The gradient of the loss function with respect to the weight", "prompt_logprobs": [null, {"20129": {"logprob": -8.96643352508545, "rank": 969}, "154822": {"logprob": -4.341433525085449, "rank": 1}}, {"315": {"logprob": -0.7039494514465332, "rank": 1}}, {"279": {"logprob": -0.9713228940963745, "rank": 2}, "264": {"logprob": -0.7213228940963745, "rank": 1}}, {"4709": {"logprob": -3.9720547199249268, "rank": 10}, "729": {"logprob": -1.0970547199249268, "rank": 1}}, {"729": {"logprob": -0.33797481656074524, "rank": 1}}, {"448": {"logprob": -1.44989812374115, "rank": 1}}, {"5091": {"logprob": -0.008337335661053658, "rank": 1}}, {"311": {"logprob": -0.0006673493189737201, "rank": 1}}, {"279": {"logprob": -0.3867085874080658, "rank": 1}}, {"14314": {"logprob": -0.8176753520965576, "rank": 1}}, {"374": {"logprob": -1.3674771785736084, "rank": 1}}, {"24113": {"logprob": -2.3279004096984863, "rank": 3}, "264": {"logprob": -1.7029004096984863, "rank": 1}}, {"4566": {"logprob": -2.6241183280944824, "rank": 4}, "1667": {"logprob": -1.124118447303772, "rank": 1}}, {"1182": {"logprob": -0.36660346388816833, "rank": 1}}, {"2674": {"logprob": -0.03230930119752884, "rank": 1}}, {"27048": {"logprob": -0.015215049497783184, "rank": 1}}, {"11": {"logprob": -1.1618281602859497, "rank": 1}}, {"18915": {"logprob": -3.7651920318603516, "rank": 6}, "892": {"logprob": -0.8901921510696411, "rank": 1}}, {"279": {"logprob": -0.01076273899525404, "rank": 1}}, {"8780": {"logprob": -0.009176341816782951, "rank": 1}}, {"5912": {"logprob": -0.0011264891363680363, "rank": 1}}, {"6193": {"logprob": -1.2604855298995972, "rank": 2}, "1526": {"logprob": -1.2604855298995972, "rank": 1}}, {"553": {"logprob": -0.02797655388712883, "rank": 1}}, {"6193": {"logprob": -0.00028046013903804123, "rank": 1}}, {"504": {"logprob": -1.6509439945220947, "rank": 2}, "13": {"logprob": -0.7759440541267395, "rank": 1}}, {"279": {"logprob": -0.052063919603824615, "rank": 1}}, {"2550": {"logprob": -0.07074390351772308, "rank": 1}}, {"1182": {"logprob": -0.15821382403373718, "rank": 1}}, {"311": {"logprob": -0.08365529775619507, "rank": 1}}, {"279": {"logprob": -0.06887133419513702, "rank": 1}}, {"1946": {"logprob": -0.07873330265283585, "rank": 1}}, {"13": {"logprob": -0.4378916621208191, "rank": 1}}, {"794": {"logprob": -7.841183662414551, "rank": 88}, "1096": {"logprob": -1.3411836624145508, "rank": 1}}, {"65474": {"logprob": -0.024642810225486755, "rank": 1}}, {"20129": {"logprob": -1.5382769107818604, "rank": 2}, "52755": {"logprob": -0.28827694058418274, "rank": 1}}, {"36760": {"logprob": -0.003080387134104967, "rank": 1}}, {"1221": {"logprob": -3.1721279621124268, "rank": 5}, "320": {"logprob": -0.422127902507782, "rank": 1}}, {"8836": {"logprob": -0.09941805154085159, "rank": 1}}, {"1817": {"logprob": -1.4260128736495972, "rank": 2}, "279": {"logprob": -0.3010128438472748, "rank": 1}}, {"4680": {"logprob": -0.2558543384075165, "rank": 1}}, {"21070": {"logprob": -6.881373405456543, "rank": 35}, "553": {"logprob": -1.1938731670379639, "rank": 1}}, {"745": {"logprob": -0.007097034715116024, "rank": 1}}, {"13": {"logprob": -8.131097793579102, "rank": 5}, "311": {"logprob": -0.006097879726439714, "rank": 1}}]}]}
scripts/validate.py ADDED
@@ -0,0 +1,157 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Correctness suite against one running server; dumps JSON for later A/B.
2
+
3
+ Usage: python3 validate.py <port> <model-name> <out.json>
4
+
5
+ Collects:
6
+ 1. 17*23 deterministic arithmetic check (temp 0).
7
+ 2. 700+ token generation; flags degenerate repetition (4-gram loop scan).
8
+ 3. 10 fixed greedy generations (50 tok, logprobs=5) - token ids + logprobs.
9
+ 4. prompt_logprobs teacher-forced scoring of 5 fixed paragraphs -
10
+ per-token logprob under identical context (the clean A/B signal).
11
+ """
12
+
13
+ import json
14
+ import sys
15
+ import urllib.request
16
+
17
+ PORT, MODEL, OUT = int(sys.argv[1]), sys.argv[2], sys.argv[3]
18
+ BASE = f"http://127.0.0.1:{PORT}"
19
+
20
+ GEN_PROMPTS = [
21
+ "What is 17*23? Answer with just the number.",
22
+ "Write a Python function that returns the nth Fibonacci number iteratively.",
23
+ "Explain the difference between TCP and UDP in two sentences.",
24
+ "Translate to French: 'The quick brown fox jumps over the lazy dog.'",
25
+ "List the first 8 prime numbers separated by commas.",
26
+ "What year did the Apollo 11 mission land on the moon? One word answer.",
27
+ "Summarize the plot of Romeo and Juliet in one sentence.",
28
+ "Write a SQL query selecting the top 5 customers by total order value from tables customers(id,name) and orders(id,customer_id,value).",
29
+ "What is the derivative of x^3 + 2x with respect to x?",
30
+ "Name the chemical symbol for gold and the element with atomic number 6.",
31
+ ]
32
+
33
+ SCORE_TEXTS = [
34
+ "The mitochondrion is the powerhouse of the cell, converting nutrients into adenosine triphosphate through oxidative phosphorylation. This process occurs across the inner mitochondrial membrane, where the electron transport chain establishes a proton gradient.",
35
+ "def quicksort(arr):\n if len(arr) <= 1:\n return arr\n pivot = arr[len(arr) // 2]\n left = [x for x in arr if x < pivot]\n middle = [x for x in arr if x == pivot]\n right = [x for x in arr if x > pivot]\n return quicksort(left) + middle + quicksort(right)",
36
+ "In 1969, the Apollo 11 mission successfully landed the first humans on the Moon. Neil Armstrong and Buzz Aldrin spent approximately two and a quarter hours outside the spacecraft, collecting lunar material to bring back to Earth.",
37
+ "Le petit prince demanda au renard ce que signifiait le mot apprivoiser. Le renard expliqua que cela signifiait creer des liens, et que si le prince l'apprivoisait, ils auraient besoin l'un de l'autre.",
38
+ "The gradient of the loss function with respect to the weights is computed via backpropagation, applying the chain rule layer by layer from the output back to the input. Stochastic gradient descent then updates each weight proportionally.",
39
+ ]
40
+
41
+
42
+ def post(path, payload, timeout=600):
43
+ req = urllib.request.Request(
44
+ BASE + path,
45
+ data=json.dumps(payload).encode(),
46
+ headers={"Content-Type": "application/json"},
47
+ )
48
+ with urllib.request.urlopen(req, timeout=timeout) as r:
49
+ return json.loads(r.read())
50
+
51
+
52
+ def degenerate(text, n=4, thresh=12):
53
+ words = text.split()
54
+ if len(words) < n * thresh:
55
+ return False
56
+ grams = {}
57
+ for i in range(len(words) - n):
58
+ g = tuple(words[i : i + n])
59
+ grams[g] = grams.get(g, 0) + 1
60
+ return max(grams.values()) >= thresh
61
+
62
+
63
+ out = {"port": PORT, "model": MODEL}
64
+
65
+ # 1. arithmetic
66
+ r = post(
67
+ "/v1/chat/completions",
68
+ {
69
+ "model": MODEL,
70
+ "messages": [{"role": "user", "content": GEN_PROMPTS[0]}],
71
+ "temperature": 0,
72
+ "max_tokens": 2048,
73
+ },
74
+ )
75
+ msg = r["choices"][0]["message"]
76
+ arith = (msg.get("content") or "") + " " + (msg.get("reasoning_content") or "")
77
+ out["arith_correct"] = "391" in arith
78
+ out["arith_raw"] = (msg.get("content") or "")[:200]
79
+
80
+ # 2. long generation
81
+ r = post(
82
+ "/v1/chat/completions",
83
+ {
84
+ "model": MODEL,
85
+ "messages": [
86
+ {
87
+ "role": "user",
88
+ "content": "Write a detailed 800-word essay on the history of container shipping, covering its origins, standardization, and global economic impact.",
89
+ }
90
+ ],
91
+ "temperature": 0,
92
+ "max_tokens": 2400,
93
+ },
94
+ )
95
+ msg = r["choices"][0]["message"]
96
+ essay = (msg.get("reasoning_content") or "") + (msg.get("content") or "")
97
+ out["long_gen_tokens"] = r["usage"]["completion_tokens"]
98
+ out["long_gen_degenerate"] = degenerate(essay)
99
+ out["long_gen_tail"] = essay[-300:]
100
+
101
+ # 3. greedy generations with logprobs (completions API for raw control)
102
+ gens = []
103
+ for p in GEN_PROMPTS:
104
+ r = post(
105
+ "/v1/completions",
106
+ {
107
+ "model": MODEL,
108
+ "prompt": p,
109
+ "temperature": 0,
110
+ "max_tokens": 50,
111
+ "logprobs": 5,
112
+ },
113
+ )
114
+ ch = r["choices"][0]
115
+ gens.append(
116
+ {
117
+ "prompt": p,
118
+ "tokens": ch["logprobs"]["tokens"],
119
+ "token_logprobs": ch["logprobs"]["token_logprobs"],
120
+ }
121
+ )
122
+ out["greedy"] = gens
123
+
124
+ # 4. teacher-forced prompt logprobs
125
+ scored = []
126
+ for t in SCORE_TEXTS:
127
+ r = post(
128
+ "/v1/completions",
129
+ {
130
+ "model": MODEL,
131
+ "prompt": t,
132
+ "temperature": 0,
133
+ "max_tokens": 1,
134
+ "prompt_logprobs": 1,
135
+ },
136
+ )
137
+ ch = r["choices"][0]
138
+ plp = ch.get("prompt_logprobs")
139
+ toks = []
140
+ if plp:
141
+ for pos in plp:
142
+ if pos is None:
143
+ toks.append(None)
144
+ continue
145
+ # dict: token_id -> {logprob, rank, decoded_token}; the entry with
146
+ # rank field present; chosen token is the key matching prompt token
147
+ entry = {
148
+ tid: {"logprob": v["logprob"], "rank": v.get("rank")}
149
+ for tid, v in pos.items()
150
+ }
151
+ toks.append(entry)
152
+ scored.append({"text": t[:60], "prompt_logprobs": toks})
153
+ out["scored"] = scored
154
+
155
+ json.dump(out, open(OUT, "w"))
156
+ print(json.dumps({k: v for k, v in out.items() if k not in ("greedy", "scored")}, indent=1))
157
+ print(f"greedy prompts: {len(gens)}, scored texts: {len(scored)} -> {OUT}")
serving/Dockerfile ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Matched-pair runtime for GLM-5.3-Flash-NVFP4-FP8ATTN-512K.
2
+ # Base: the public per-model vLLM image for glm5_next on SM120 (not redistributed here).
3
+ # The four COPY lines are the ENTIRE delta — see README.md in this directory.
4
+ #
5
+ # docker build -t local/vllm-glm53:fp8attn-512k .
6
+ FROM cstechdev/vllm:glm53-flash-nope-sm120-cu130-20260826-r1
7
+
8
+ # (1) KDA layers: stop stripping quant_config at construction (kda.py:168-175 upstream)
9
+ COPY kda.py /usr/local/lib/python3.12/dist-packages/vllm/models/glm5next/nvidia/kda.py
10
+ # (2) MLA layers (+ MTP draft): quant_config=None -> real config (model.py:329 upstream)
11
+ COPY model.py /usr/local/lib/python3.12/dist-packages/vllm/models/glm5next/nvidia/model.py
12
+ # (3) ModelOptMixedPrecisionConfig: FP8_BLOCK128/64/32 dispatch, fused-name resolver,
13
+ # MTP draft-prefix aliases, block-FP8 ParallelLMHead loader (vocab-sharded scales)
14
+ COPY modelopt.py /usr/local/lib/python3.12/dist-packages/vllm/model_executor/layers/quantization/modelopt.py
15
+ # (4) SM120-tuned w8a8 block-FP8 triton config for the KDA fused in_proj shape
16
+ # (N=12576, K=4096, block [32,32]) — worth +60% decode on its own
17
+ COPY configs/*.json /usr/local/lib/python3.12/dist-packages/vllm/model_executor/layers/quantization/utils/configs/
serving/README.md ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # serving/ — the matched-pair runtime
2
+
3
+ This checkpoint stores attention, shared/dense-MLP, and `lm_head` weights as block-FP8
4
+ (`F8_E4M3` + FP32 `weight_scale_inv`). The public `glm5_next` vLLM images cannot load that:
5
+ they build every attention layer **unquantized** (the official checkpoints keep attention BF16,
6
+ so the model code strips `quant_config` at layer construction), and they have no FP8
7
+ `ParallelLMHead` loader. The result on an unpatched image is a `KeyError` on the first attention
8
+ scale tensor, or a vocab-embedding shape assert.
9
+
10
+ The fix is four files on top of `cstechdev/vllm:glm53-flash-nope-sm120-cu130-20260826-r1`
11
+ (vLLM `0.1.dev20051+g487ecf187`), applied by the Dockerfile here:
12
+
13
+ | file | target path in image | semantic change |
14
+ |---|---|---|
15
+ | `kda.py` | `vllm/models/glm5next/nvidia/kda.py` | remove the save/`None`/restore strip of `vllm_config.quant_config` around KDA base-class construction (lines 168–175 upstream) — the layer now sees the real quant config; the checkpoint's `ignore` list still keeps anything BF16 that should stay BF16 |
16
+ | `model.py` | `vllm/models/glm5next/nvidia/model.py` | `Glm5NextDecoderLayer.__init__`: MLA attention gets `quant_config=quant_config` instead of `quant_config=None` (line 329 upstream); one site covers the 11 MLA layers and the MTP draft layer. The vision-tower `quant_config=None` site is deliberately untouched (upstream warns quantizing the tower NaNs image features; this checkpoint ships the tower BF16) |
17
+ | `modelopt.py` | `vllm/model_executor/layers/quantization/modelopt.py` | `ModelOptMixedPrecisionConfig`: `FP8_BLOCK128` / `FP8_BLOCK64` / `FP8_BLOCK32` per-layer dispatch to dynamic-activation block `Fp8LinearMethod`, fused-module name resolution, MTP draft-prefix aliases, and a `ParallelLMHead` method whose `weight_scale_inv` loader shards scale rows by vocab shard / 128 (exact: 154880 and the 77440-row TP2 shard divide by 128) |
18
+ | `configs/N=12576,K=4096,…block_shape=[32,32].json` | `vllm/model_executor/layers/quantization/utils/configs/` | autotuned triton tile configs for the KDA fused in_proj GEMM on RTX PRO 6000 Blackwell (SM120) — vLLM ships zero SM120 block-FP8 configs; the default config costs 313 µs/call vs 22.3 µs tuned (43.8% of decode GPU time → ~3%) |
19
+
20
+ Safety property (measured): this patched image is **bitwise identical** to the vendor image for
21
+ BF16-attention checkpoints — the parent NVFP4 checkpoint produces 100.00% teacher-forced
22
+ agreement with |Δlogprob| = 0.00000 under it, because its `quantization_config.ignore` already
23
+ excludes every attention module. The patch only *allows* quantized attention when a checkpoint's
24
+ manifest asks for it.
25
+
26
+ All three `.py` files are Apache-2.0 vLLM-tree files (SPDX headers retained) carrying local
27
+ modifications; they are **not** MIT-licensed model weights. Credit: the vLLM project; the
28
+ official `glm5_next` per-model image as packaged by
29
+ [chriswritescode-dev/glm-5.3-flash-sm120](https://github.com/chriswritescode-dev/glm-5.3-flash-sm120)
30
+ (our base-image lineage). The base image is pulled from Docker Hub at build time and is not
31
+ redistributed in this repo.
32
+
33
+ Parallel-work credit: [local-inference-lab](https://github.com/local-inference-lab/vllm)
34
+ independently landed the equivalent MLA quant-config passthrough in their public vLLM fork
35
+ (`dev/jovian-judgement@8590bf9c`, 2026-08-29), paired with MXFP8 attention via the b12x SM120
36
+ kernels. This patch set does the same for the official per-model-image code path and adds the
37
+ block-[32,32] FP8 dispatch for the fused KDA in_proj plus the block-FP8 lm_head loader.
38
+
39
+ Numerics note for the [32,32] block: the tuned configs keep `BLOCK_SIZE_K=32`, the same k-split
40
+ as the default config, so tuned vs untuned kernels are bit-identical in reduction order.
serving/configs/N=12576,K=4096,device_name=NVIDIA_RTX_PRO_6000_Blackwell_Workstation_Edition,dtype=fp8_w8a8,block_shape=[32,32].json ADDED
@@ -0,0 +1,90 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "1": {
3
+ "BLOCK_SIZE_M": 16,
4
+ "BLOCK_SIZE_N": 64,
5
+ "BLOCK_SIZE_K": 32,
6
+ "GROUP_SIZE_M": 1,
7
+ "num_warps": 4,
8
+ "num_stages": 6
9
+ },
10
+ "2": {
11
+ "BLOCK_SIZE_M": 16,
12
+ "BLOCK_SIZE_N": 128,
13
+ "BLOCK_SIZE_K": 32,
14
+ "GROUP_SIZE_M": 32,
15
+ "num_warps": 4,
16
+ "num_stages": 4
17
+ },
18
+ "4": {
19
+ "BLOCK_SIZE_M": 16,
20
+ "BLOCK_SIZE_N": 128,
21
+ "BLOCK_SIZE_K": 32,
22
+ "GROUP_SIZE_M": 32,
23
+ "num_warps": 4,
24
+ "num_stages": 4
25
+ },
26
+ "8": {
27
+ "BLOCK_SIZE_M": 16,
28
+ "BLOCK_SIZE_N": 128,
29
+ "BLOCK_SIZE_K": 32,
30
+ "GROUP_SIZE_M": 1,
31
+ "num_warps": 4,
32
+ "num_stages": 4
33
+ },
34
+ "16": {
35
+ "BLOCK_SIZE_M": 16,
36
+ "BLOCK_SIZE_N": 128,
37
+ "BLOCK_SIZE_K": 32,
38
+ "GROUP_SIZE_M": 1,
39
+ "num_warps": 4,
40
+ "num_stages": 6
41
+ },
42
+ "64": {
43
+ "BLOCK_SIZE_M": 64,
44
+ "BLOCK_SIZE_N": 64,
45
+ "BLOCK_SIZE_K": 32,
46
+ "GROUP_SIZE_M": 8,
47
+ "num_warps": 4,
48
+ "num_stages": 3
49
+ },
50
+ "256": {
51
+ "BLOCK_SIZE_M": 128,
52
+ "BLOCK_SIZE_N": 64,
53
+ "BLOCK_SIZE_K": 32,
54
+ "GROUP_SIZE_M": 32,
55
+ "num_warps": 4,
56
+ "num_stages": 2
57
+ },
58
+ "1024": {
59
+ "BLOCK_SIZE_M": 64,
60
+ "BLOCK_SIZE_N": 128,
61
+ "BLOCK_SIZE_K": 32,
62
+ "GROUP_SIZE_M": 8,
63
+ "num_warps": 4,
64
+ "num_stages": 2
65
+ },
66
+ "2048": {
67
+ "BLOCK_SIZE_M": 128,
68
+ "BLOCK_SIZE_N": 128,
69
+ "BLOCK_SIZE_K": 32,
70
+ "GROUP_SIZE_M": 8,
71
+ "num_warps": 4,
72
+ "num_stages": 2
73
+ },
74
+ "4096": {
75
+ "BLOCK_SIZE_M": 128,
76
+ "BLOCK_SIZE_N": 128,
77
+ "BLOCK_SIZE_K": 32,
78
+ "GROUP_SIZE_M": 8,
79
+ "num_warps": 4,
80
+ "num_stages": 2
81
+ },
82
+ "8192": {
83
+ "BLOCK_SIZE_M": 128,
84
+ "BLOCK_SIZE_N": 128,
85
+ "BLOCK_SIZE_K": 32,
86
+ "GROUP_SIZE_M": 1,
87
+ "num_warps": 4,
88
+ "num_stages": 2
89
+ }
90
+ }
serving/kda.py ADDED
@@ -0,0 +1,655 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+ """GLM5-Next KDA (linear-attention) layer.
4
+
5
+ Model-specific, self-contained KDA: separate q/k/v short-conv + the GLM5-Next
6
+ spec-decode verify path + the bounded ``safe_gate`` variant, and ``_forward`` is
7
+ an eager break point under Breakable CUDA Graph
8
+ (``@eager_break_during_capture``).
9
+
10
+ Moved out of the shared ``kimi_gdn_linear_attn.py`` (which reverts to Kimi
11
+ Linear's fused-conv version): the separate-conv layout + spec-verify are
12
+ GLM5-Next-only. ``forward`` calls ``self._forward`` directly (no
13
+ ``torch.ops.vllm.kda_attention`` indirection) so the only un-capturable work is
14
+ the decorated ``_forward``.
15
+ """
16
+
17
+ import torch
18
+ from torch import nn
19
+
20
+ from vllm.compilation.breakable_cudagraph import eager_break_during_capture
21
+ from vllm.config import VllmConfig, get_current_vllm_config
22
+ from vllm.distributed import divide
23
+ from vllm.forward_context import get_forward_context
24
+ from vllm.model_executor.layers.linear import (
25
+ ColumnParallelLinear,
26
+ MergedColumnParallelLinear,
27
+ RowParallelLinear,
28
+ )
29
+ from vllm.model_executor.layers.mamba.gdn.base import GatedDeltaNetAttention
30
+ from vllm.model_executor.layers.mamba.mamba_utils import (
31
+ MambaStateDtypeCalculator,
32
+ MambaStateShapeCalculator,
33
+ is_conv_state_dim_first,
34
+ )
35
+ from vllm.model_executor.layers.mamba.ops.causal_conv1d import (
36
+ causal_conv1d_fn,
37
+ causal_conv1d_update,
38
+ )
39
+ from vllm.model_executor.layers.mamba.ops.gather_initial_states import (
40
+ gather_initial_states,
41
+ )
42
+ from vllm.model_executor.layers.mamba.ops.scatter_states import scatter_states
43
+ from vllm.model_executor.model_loader.weight_utils import sharded_weight_loader
44
+ from vllm.model_executor.utils import (
45
+ maybe_disable_graph_partition,
46
+ set_weight_attrs,
47
+ )
48
+ from vllm.platforms import current_platform
49
+ from vllm.third_party.flash_linear_attention.ops.kda import (
50
+ FusedRMSNormGated,
51
+ chunk_kda_with_fused_gate,
52
+ fused_recurrent_kda,
53
+ )
54
+ from vllm.transformers_utils.configs.kimi_linear import KimiLinearConfig
55
+ from vllm.v1.attention.backends.gdn_attn import GDNAttentionMetadata
56
+
57
+
58
+ class _Glm5NextMergedColumnParallelLinear(MergedColumnParallelLinear):
59
+ """Merged projection with multiple replicated output shards.
60
+
61
+ Extends K3's ``_KimiGDNMergedColumnParallelLinear`` to support two
62
+ replicated shards (f_a, g_a) instead of one. Pre-multiplies each
63
+ replicated entry's output_size by tp_size so the per-rank shard
64
+ divides back to the full size, and forces tp_rank=0 during weight
65
+ loading for replicated shards.
66
+ """
67
+
68
+ def __init__(
69
+ self,
70
+ input_size: int,
71
+ output_sizes: list[int],
72
+ replicated_shard_ids: tuple[int, ...],
73
+ tp_size: int,
74
+ **kwargs,
75
+ ) -> None:
76
+ self.replicated_shard_ids = set(replicated_shard_ids)
77
+ output_sizes = output_sizes.copy()
78
+ for sid in self.replicated_shard_ids:
79
+ output_sizes[sid] *= tp_size
80
+ super().__init__(input_size, output_sizes, **kwargs)
81
+
82
+ def weight_loader(
83
+ self,
84
+ param: nn.Parameter,
85
+ loaded_weight: torch.Tensor,
86
+ loaded_shard_id: tuple[int, ...] | int | None = None,
87
+ ) -> None:
88
+ tp_rank = self.tp_rank
89
+ param_tp_rank = getattr(param, "tp_rank", None)
90
+ if loaded_shard_id in self.replicated_shard_ids:
91
+ self.tp_rank = 0
92
+ if param_tp_rank is not None:
93
+ param.tp_rank = 0
94
+ try:
95
+ super().weight_loader(param, loaded_weight, loaded_shard_id)
96
+ finally:
97
+ self.tp_rank = tp_rank
98
+ if param_tp_rank is not None:
99
+ param.tp_rank = param_tp_rank
100
+
101
+ def weight_loader_v2(
102
+ self,
103
+ param: nn.Parameter,
104
+ loaded_weight: torch.Tensor,
105
+ loaded_shard_id: tuple[int, ...] | int | None = None,
106
+ ) -> None:
107
+ tp_rank = self.tp_rank
108
+ param_tp_rank = getattr(param, "tp_rank", None)
109
+ if loaded_shard_id in self.replicated_shard_ids:
110
+ self.tp_rank = 0
111
+ if param_tp_rank is not None:
112
+ param.tp_rank = 0
113
+ try:
114
+ super().weight_loader_v2(param, loaded_weight, loaded_shard_id)
115
+ finally:
116
+ self.tp_rank = tp_rank
117
+ if param_tp_rank is not None:
118
+ param.tp_rank = param_tp_rank
119
+
120
+
121
+ @torch.compile(
122
+ dynamic=True,
123
+ backend=current_platform.simple_compile_backend,
124
+ options=maybe_disable_graph_partition(current_platform.simple_compile_backend),
125
+ )
126
+ def _cast_sigmoid(x: torch.Tensor) -> torch.Tensor:
127
+ """Fuse the fp32 cast + sigmoid into one Inductor kernel."""
128
+ return x.float().sigmoid()
129
+
130
+
131
+ class Glm5NextLinearAttention(GatedDeltaNetAttention):
132
+ # Declared int (set in __init__ from config) so mypy doesn't see the
133
+ # getattr-derived `Any | None` at the kernel call sites.
134
+ head_dim: int
135
+ num_heads: int
136
+ conv_size: int
137
+
138
+ def get_state_dtype(
139
+ self,
140
+ ) -> tuple[torch.dtype, torch.dtype]:
141
+ if self.model_config is None or self.cache_config is None:
142
+ raise ValueError("model_config and cache_config must be set")
143
+ return MambaStateDtypeCalculator.kda_state_dtype(
144
+ self.model_config.dtype, self.cache_config.mamba_cache_dtype
145
+ )
146
+
147
+ def get_state_shape(
148
+ self,
149
+ ) -> tuple[tuple[int, ...], tuple[int, ...]]:
150
+ # conv_state width must include num_spec so the spec-decode conv update
151
+ # (causal_conv1d_update with num_accepted_tokens + max_query_len) can
152
+ # slide the window across the draft-verify tokens without reading past
153
+ # the allocated width. Matches qwen_gdn_linear_attn.get_state_shape.
154
+ return MambaStateShapeCalculator.kda_state_shape(
155
+ self.tp_size,
156
+ self.num_heads,
157
+ self.head_dim,
158
+ conv_kernel_size=self.conv_size,
159
+ num_spec=self.num_spec,
160
+ )
161
+
162
+ def __init__(
163
+ self,
164
+ config: KimiLinearConfig,
165
+ vllm_config: VllmConfig,
166
+ prefix: str = "",
167
+ ) -> None:
168
+ # LOCAL PATCH (fp8attn-r2): pass the real quant config through so KDA
169
+ # projections can be FP8-resident when the checkpoint declares them in
170
+ # a MIXED_PRECISION quantized_layers manifest. Checkpoints that keep
171
+ # attention BF16 (e.g. the stock NVFP4 export) are unaffected: their
172
+ # quantization_config `ignore` list names every self_attn module
173
+ # (including the fused `in_proj_qkvbfg_a` spelling), so every KDA
174
+ # linear still resolves to UnquantizedLinearMethod.
175
+ # Was: save/None/restore strip of vllm_config.quant_config.
176
+ super().__init__(config, vllm_config, prefix)
177
+
178
+ # Linear-attention head config: read the flattened top-level fields when
179
+ # present (new schema); fall back to the legacy linear_attn_config dict
180
+ # otherwise (shared base is also used by KimiLinearConfig). Narrow via
181
+ # locals so the int-typed attrs are assigned a non-None value.
182
+ head_dim = getattr(config, "linear_head_dim", None)
183
+ num_heads = getattr(config, "linear_num_heads", None)
184
+ conv_size = getattr(config, "linear_conv_kernel_dim", None)
185
+ if head_dim is None or num_heads is None or conv_size is None:
186
+ kda_config = config.linear_attn_config # type: ignore[attr-defined]
187
+ assert kda_config is not None, "linear_attn_config must be set"
188
+ head_dim = kda_config["head_dim"]
189
+ num_heads = kda_config["num_heads"]
190
+ conv_size = kda_config["short_conv_kernel_size"]
191
+ assert head_dim is not None
192
+ assert num_heads is not None
193
+ assert conv_size is not None
194
+ self.head_dim = head_dim
195
+ self.num_heads = num_heads
196
+ self.conv_size = conv_size
197
+ assert self.num_heads % self.tp_size == 0
198
+ self.local_num_heads = divide(self.num_heads, self.tp_size)
199
+
200
+ projection_size = self.head_dim * self.num_heads
201
+ self.local_projection_size = divide(projection_size, self.tp_size)
202
+
203
+ # Merge q, k, v, b, f_a, g_a projections into one GEMM (6→1 launches).
204
+ # Order matches checkpoint's fused_qkvbfg_a_proj convention.
205
+ # Shards 4 (f_a) and 5 (g_a) are replicated across TP ranks.
206
+ self.in_proj_qkvbfg_a = _Glm5NextMergedColumnParallelLinear(
207
+ self.hidden_size,
208
+ [
209
+ projection_size, # q (shard 0)
210
+ projection_size, # k (shard 1)
211
+ projection_size, # v (shard 2)
212
+ self.num_heads, # b (shard 3)
213
+ self.head_dim, # f_a (shard 4, replicated)
214
+ self.head_dim, # g_a (shard 5, replicated)
215
+ ],
216
+ replicated_shard_ids=(4, 5),
217
+ tp_size=self.tp_size,
218
+ bias=False,
219
+ quant_config=self.quant_config,
220
+ prefix=f"{prefix}.in_proj_qkvbfg_a",
221
+ )
222
+
223
+ self.f_b_proj = ColumnParallelLinear(
224
+ self.head_dim,
225
+ projection_size,
226
+ bias=False,
227
+ quant_config=self.quant_config,
228
+ prefix=f"{prefix}.f_b_proj",
229
+ )
230
+ self.dt_bias = nn.Parameter(
231
+ torch.empty(divide(projection_size, self.tp_size), dtype=torch.float32)
232
+ )
233
+
234
+ set_weight_attrs(self.dt_bias, {"weight_loader": sharded_weight_loader(0)})
235
+
236
+ self.q_conv1d = ColumnParallelLinear(
237
+ input_size=self.conv_size,
238
+ output_size=projection_size,
239
+ bias=False,
240
+ params_dtype=torch.float32,
241
+ prefix=f"{prefix}.q_conv1d",
242
+ )
243
+ self.k_conv1d = ColumnParallelLinear(
244
+ input_size=self.conv_size,
245
+ output_size=projection_size,
246
+ bias=False,
247
+ params_dtype=torch.float32,
248
+ prefix=f"{prefix}.k_conv1d",
249
+ )
250
+ self.v_conv1d = ColumnParallelLinear(
251
+ input_size=self.conv_size,
252
+ output_size=projection_size,
253
+ bias=False,
254
+ params_dtype=torch.float32,
255
+ prefix=f"{prefix}.v_conv1d",
256
+ )
257
+ # unsqueeze to fit conv1d weights shape into the linear weights shape.
258
+ # Can't do this in `weight_loader` since it already exists in
259
+ # `ColumnParallelLinear` and `set_weight_attrs`
260
+ # doesn't allow to override it
261
+ self.q_conv1d.weight.data = self.q_conv1d.weight.data.unsqueeze(1)
262
+ self.k_conv1d.weight.data = self.k_conv1d.weight.data.unsqueeze(1)
263
+ self.v_conv1d.weight.data = self.v_conv1d.weight.data.unsqueeze(1)
264
+ # Lazily-built merged q|k|v conv weight (built on first forward, after
265
+ # weights are loaded). See _forward.
266
+ self._merged_conv_weight: torch.Tensor | None = None
267
+
268
+ self.A_log = nn.Parameter(
269
+ torch.empty(1, 1, self.local_num_heads, 1, dtype=torch.float32)
270
+ )
271
+ set_weight_attrs(self.A_log, {"weight_loader": sharded_weight_loader(2)})
272
+
273
+ self.g_b_proj = ColumnParallelLinear(
274
+ self.head_dim,
275
+ projection_size,
276
+ bias=False,
277
+ quant_config=self.quant_config,
278
+ prefix=f"{prefix}.g_b_proj",
279
+ )
280
+ self.o_norm = FusedRMSNormGated(self.head_dim, activation="sigmoid")
281
+ self.o_proj = RowParallelLinear(
282
+ projection_size,
283
+ self.hidden_size,
284
+ bias=False,
285
+ quant_config=self.quant_config,
286
+ prefix=f"{prefix}.o_proj",
287
+ )
288
+
289
+ compilation_config = get_current_vllm_config().compilation_config
290
+ if prefix in compilation_config.static_forward_context:
291
+ raise ValueError(f"Duplicate layer name: {prefix}")
292
+ compilation_config.static_forward_context[prefix] = self
293
+
294
+ # GLM5-Next checkpoints A_log as 1-D (num_heads,); the param is 4-D, so
295
+ # reshape on load before the sharded loader runs.
296
+ def _a_log_weight_loader(param, loaded_weight):
297
+ if loaded_weight.dim() == 1:
298
+ loaded_weight = loaded_weight.view([1, 1, -1, 1])
299
+ return sharded_weight_loader(2)(param, loaded_weight)
300
+
301
+ self.A_log.weight_loader = _a_log_weight_loader
302
+
303
+ # Bounded KDA gate variant: GLM5-Next uses
304
+ # y = lower_bound * sigmoid(exp(A)*(g+g_bias)) instead of the default
305
+ # unbounded y = -exp(A)*softplus(g+g_bias). Read by _forward.
306
+ linear_lower_bound = getattr(config, "linear_lower_bound", None)
307
+ if linear_lower_bound is not None:
308
+ self.kda_safe_gate = True
309
+ self.kda_lower_bound = linear_lower_bound
310
+ else:
311
+ legacy = getattr(config, "linear_attn_config", None) or {}
312
+ if legacy.get("safe_gate", True):
313
+ self.kda_safe_gate = True
314
+ self.kda_lower_bound = legacy.get("lower_bound", -5.0)
315
+ else:
316
+ self.kda_safe_gate = False
317
+ self.kda_lower_bound = -5.0
318
+ # Process-global conv-state layout, resolved once here instead of on
319
+ # every _forward call (it reads an env-derived flag each time).
320
+ self._conv_state_dim_first = is_conv_state_dim_first()
321
+
322
+ def forward(
323
+ self,
324
+ hidden_states: torch.Tensor,
325
+ positions: torch.Tensor,
326
+ ) -> torch.Tensor:
327
+ num_tokens = hidden_states.size(0)
328
+ # One merged GEMM for q, k, v, b, f_a, g_a (replaces 6 separate GEMMs).
329
+ projected = self.in_proj_qkvbfg_a(hidden_states)[0]
330
+ qkv, beta_raw, f_a, g_a = projected.split(
331
+ [
332
+ 3 * self.local_projection_size,
333
+ self.local_num_heads,
334
+ self.head_dim,
335
+ self.head_dim,
336
+ ],
337
+ dim=-1,
338
+ )
339
+
340
+ # Beta stays raw (bf16) here: the recurrent kernel sigmoids it in fp32
341
+ # at load (SIGMOID_BETA), and only the chunked prefill path needs the
342
+ # pre-computed fp32 sigmoid — computed lazily in _forward. Pure decode
343
+ # / spec-verify steps then skip the _cast_sigmoid kernel and its fp32
344
+ # intermediate entirely.
345
+ beta = beta_raw.unsqueeze(0)
346
+ g1 = self.f_b_proj(f_a)[0]
347
+ g1 = g1.reshape(1, -1, self.local_num_heads, self.head_dim)
348
+
349
+ g_proj_states = self.g_b_proj(g_a)[0]
350
+ # Must stay 3D: rms_norm_gated reads H from g.shape[-2].
351
+ g2 = g_proj_states.reshape(-1, self.local_num_heads, self.head_dim)
352
+
353
+ core_attn_out = torch.empty(
354
+ (1, num_tokens, self.local_num_heads, self.head_dim),
355
+ dtype=hidden_states.dtype,
356
+ device=hidden_states.device,
357
+ )
358
+ # Call _forward directly (not via the registered op) so the KDA core
359
+ # is an eager break point under Breakable CG, mirroring KimiK3's KDA
360
+ # (vllm/models/kimi_k3/nvidia/kda.py). torch.ops.vllm.kda_attention is
361
+ # neither a splitting op nor @eager_break_during_capture-decorated, so
362
+ # routing through it lets the host-branching prefill body be
363
+ # Inductor-compiled + stream-captured under PIECEWISE -> stale garbage.
364
+ # qkv stays merged through the short-conv (one conv call, not three).
365
+ self._forward(
366
+ qkv_proj_states=qkv,
367
+ g1=g1,
368
+ beta=beta,
369
+ core_attn_out=core_attn_out,
370
+ )
371
+ core_attn_out = self.o_norm(core_attn_out, g2)
372
+ core_attn_out = core_attn_out.reshape(core_attn_out.size(1), -1)
373
+ return self.o_proj(core_attn_out)[0]
374
+
375
+ @eager_break_during_capture
376
+ def _forward(
377
+ self,
378
+ qkv_proj_states: torch.Tensor,
379
+ g1: torch.Tensor,
380
+ beta: torch.Tensor,
381
+ core_attn_out: torch.Tensor,
382
+ ) -> None:
383
+ forward_context = get_forward_context()
384
+ attn_metadata_raw = forward_context.attn_metadata
385
+
386
+ if attn_metadata_raw is None:
387
+ # # V1 profile run
388
+ return
389
+
390
+ assert isinstance(attn_metadata_raw, dict)
391
+ attn_metadata_narrowed = attn_metadata_raw[self.prefix]
392
+ assert isinstance(attn_metadata_narrowed, GDNAttentionMetadata)
393
+ has_initial_state = attn_metadata_narrowed.has_initial_state
394
+ non_spec_query_start_loc = attn_metadata_narrowed.non_spec_query_start_loc
395
+ non_spec_state_indices_tensor = (
396
+ attn_metadata_narrowed.non_spec_state_indices_tensor
397
+ ) # noqa: E501
398
+ num_actual_tokens = attn_metadata_narrowed.num_actual_tokens
399
+ # Spec-decode metadata (all None when speculative decoding is disabled).
400
+ spec_sequence_masks = attn_metadata_narrowed.spec_sequence_masks
401
+ spec_query_start_loc = attn_metadata_narrowed.spec_query_start_loc
402
+ spec_state_indices_tensor = attn_metadata_narrowed.spec_state_indices_tensor
403
+ spec_token_indx = attn_metadata_narrowed.spec_token_indx
404
+ non_spec_token_indx = attn_metadata_narrowed.non_spec_token_indx
405
+ num_accepted_tokens = attn_metadata_narrowed.num_accepted_tokens
406
+ num_spec_decodes = attn_metadata_narrowed.num_spec_decodes
407
+ use_spec = spec_sequence_masks is not None and num_spec_decodes > 0
408
+ # KDA gate variant: GLM5-Next checkpoints with
409
+ # linear_attn_config["safe_gate"]=True use the bounded gate
410
+ # y=lower_bound*sigmoid(exp(A)*(g+g_bias)) instead of the default
411
+ # unbounded y=-exp(A)*softplus(g+g_bias). Both attrs are always set
412
+ # in __init__ (this class is GLM5Next-only).
413
+ safe_gate = self.kda_safe_gate
414
+ lower_bound = self.kda_lower_bound
415
+ constant_caches = self.kv_cache
416
+
417
+ qkv_proj_states = qkv_proj_states[:num_actual_tokens]
418
+ g1 = g1[:, :num_actual_tokens]
419
+ beta = beta[:, :num_actual_tokens]
420
+
421
+ (conv_state, recurrent_state) = constant_caches
422
+ # conv_state must be (..., dim, width-1) for the conv kernels.
423
+ # DS layout stores it that way directly; SD layout needs a transpose.
424
+ # Layout is process-global and resolved once at init (see __init__).
425
+ if not self._conv_state_dim_first:
426
+ conv_state = conv_state.transpose(-1, -2)
427
+
428
+ # One merged short-conv over q|k|v instead of three separate calls. The
429
+ # 1D conv is independent per channel, so concatenating q/k/v along the
430
+ # channel dim and running a single causal_conv1d is bit-identical to
431
+ # three calls. The merged weight is q|k|v conv weights concatenated;
432
+ # built once and cached (params are fixed after load). conv_state is
433
+ # already stored as the merged q|k|v state, so it is used directly.
434
+ if self._merged_conv_weight is None:
435
+
436
+ def _w(m):
437
+ return m.weight.view(m.weight.size(0), m.weight.size(2))
438
+
439
+ self._merged_conv_weight = torch.cat(
440
+ [_w(self.q_conv1d), _w(self.k_conv1d), _w(self.v_conv1d)],
441
+ dim=0,
442
+ ).contiguous()
443
+ conv_weights = self._merged_conv_weight
444
+ conv_bias = self.q_conv1d.bias
445
+
446
+ # Split projections / gating into spec (draft-verify) and non-spec token
447
+ # groups when speculative decoding is active. Spec tokens carry
448
+ # num_spec+1 recurrent-state columns each and are advanced with
449
+ # num_accepted_tokens for rejection-sampling rollback; non-spec tokens
450
+ # are one-per-request. Mirrors olmo_gdn_linear_attn.py. Projections are
451
+ # [n, *] (token dim 0); g1/beta are [1, n, h, d] (token dim 1).
452
+ if use_spec:
453
+ # In a pure spec-verify step (no non-spec tokens) the metadata
454
+ # builder sets spec_token_indx = arange(num_actual_tokens), making
455
+ # the index_select calls below identity copies. Skip them on this
456
+ # steady-state decode hot path. The outputs alias the inputs here;
457
+ # the downstream conv/recurrent kernels read them without mutating
458
+ # in place, so the aliasing is safe.
459
+ if non_spec_token_indx is None or non_spec_token_indx.numel() == 0:
460
+ qkv_spec = qkv_proj_states
461
+ g1_spec = g1
462
+ beta_spec = beta
463
+ else:
464
+ qkv_spec = qkv_proj_states.index_select(0, spec_token_indx)
465
+ g1_spec = g1.index_select(1, spec_token_indx)
466
+ beta_spec = beta.index_select(1, spec_token_indx)
467
+ if non_spec_token_indx is not None and non_spec_token_indx.numel() > 0:
468
+ qkv_ns = qkv_proj_states.index_select(0, non_spec_token_indx)
469
+ g1_ns = g1.index_select(1, non_spec_token_indx)
470
+ beta_ns = beta.index_select(1, non_spec_token_indx)
471
+ else:
472
+ qkv_ns = g1_ns = beta_ns = None
473
+ else:
474
+ qkv_spec = g1_spec = beta_spec = None
475
+ qkv_ns, g1_ns, beta_ns = qkv_proj_states, g1, beta
476
+
477
+ # --- causal conv1d: spec (draft-verify) path ---
478
+ if use_spec:
479
+ assert spec_state_indices_tensor is not None
480
+ assert num_accepted_tokens is not None
481
+ conv_idx = spec_state_indices_tensor[:, 0][:num_spec_decodes]
482
+ conv_mql = spec_state_indices_tensor.size(-1)
483
+ qkv_spec = causal_conv1d_update(
484
+ qkv_spec,
485
+ conv_state,
486
+ conv_weights,
487
+ conv_bias,
488
+ activation="silu",
489
+ conv_state_indices=conv_idx,
490
+ num_accepted_tokens=num_accepted_tokens,
491
+ query_start_loc=spec_query_start_loc,
492
+ max_query_len=conv_mql,
493
+ )
494
+ q_spec, k_spec, v_spec = qkv_spec.split(self.local_projection_size, dim=-1)
495
+
496
+ # --- causal conv1d: non-spec path (prefill or plain decode) ---
497
+ q_ns = k_ns = v_ns = None
498
+ if attn_metadata_narrowed.num_prefills > 0:
499
+ assert qkv_ns is not None
500
+ qkv_ns = causal_conv1d_fn(
501
+ qkv_ns.transpose(0, 1),
502
+ conv_weights,
503
+ conv_bias,
504
+ activation="silu",
505
+ conv_states=conv_state,
506
+ has_initial_state=has_initial_state,
507
+ cache_indices=non_spec_state_indices_tensor,
508
+ query_start_loc=non_spec_query_start_loc,
509
+ metadata=attn_metadata_narrowed,
510
+ ).transpose(0, 1)
511
+ q_ns, k_ns, v_ns = qkv_ns.split(self.local_projection_size, dim=-1)
512
+ elif attn_metadata_narrowed.num_decodes > 0:
513
+ assert non_spec_state_indices_tensor is not None
514
+ decode_conv_indices = non_spec_state_indices_tensor[
515
+ : attn_metadata_narrowed.num_decodes
516
+ ]
517
+ qkv_ns = causal_conv1d_update(
518
+ qkv_ns,
519
+ conv_state,
520
+ conv_weights,
521
+ conv_bias,
522
+ activation="silu",
523
+ conv_state_indices=decode_conv_indices,
524
+ )
525
+ q_ns, k_ns, v_ns = qkv_ns.split(self.local_projection_size, dim=-1)
526
+
527
+ def _rearr(x):
528
+ return x.reshape(1, -1, self.local_num_heads, self.head_dim)
529
+
530
+ # --- core attention: spec (draft-verify) path ---
531
+ core_attn_out_spec = None
532
+ # In a pure spec-verify step (no non-spec tokens) the recurrent kernel
533
+ # can write straight into the layer output buffer, skipping the
534
+ # fresh allocation + copy below. Mixed steps must scatter via
535
+ # spec_token_indx, so they keep the kernel-managed output.
536
+ spec_out = (
537
+ core_attn_out[0, :num_actual_tokens].unsqueeze(0)
538
+ if non_spec_token_indx is None or non_spec_token_indx.numel() == 0
539
+ else None
540
+ )
541
+ if use_spec:
542
+ assert spec_state_indices_tensor is not None
543
+ assert num_accepted_tokens is not None
544
+ assert spec_query_start_loc is not None
545
+ # Gate computed inside the recurrent kernel (COMPUTE_GATE) from
546
+ # raw g1 — replicates fused_kda_gate's arithmetic bit-for-bit and
547
+ # skips its launch + fp32 [n, H, D] intermediate per layer.
548
+ core_attn_out_spec, _ = fused_recurrent_kda(
549
+ q=_rearr(q_spec),
550
+ k=_rearr(k_spec),
551
+ v=_rearr(v_spec),
552
+ g=g1_spec,
553
+ beta=beta_spec,
554
+ initial_state=recurrent_state,
555
+ use_qk_l2norm_in_kernel=True,
556
+ cu_seqlens=spec_query_start_loc[: num_spec_decodes + 1],
557
+ ssm_state_indices=spec_state_indices_tensor,
558
+ num_accepted_tokens=num_accepted_tokens,
559
+ out=spec_out,
560
+ sigmoid_beta=True,
561
+ a_log=self.A_log,
562
+ g_bias=self.dt_bias,
563
+ compute_gate=True,
564
+ lower_bound=lower_bound,
565
+ )
566
+
567
+ # --- core attention: non-spec path (prefill or plain decode) ---
568
+ core_attn_out_non_spec = None
569
+ # Only the plain-decode recurrent kernel can write straight into the
570
+ # layer output buffer; the chunked prefill kernel cannot, so this
571
+ # stays None there and the merge copy below runs as before.
572
+ ns_out = None
573
+ if attn_metadata_narrowed.num_prefills > 0:
574
+ assert q_ns is not None
575
+ assert non_spec_state_indices_tensor is not None
576
+ assert has_initial_state is not None
577
+ initial_state = gather_initial_states(
578
+ recurrent_state, non_spec_state_indices_tensor, has_initial_state
579
+ )
580
+ (
581
+ core_attn_out_non_spec,
582
+ last_recurrent_state,
583
+ ) = chunk_kda_with_fused_gate(
584
+ q=_rearr(q_ns),
585
+ k=_rearr(k_ns),
586
+ v=_rearr(v_ns),
587
+ raw_g=g1_ns,
588
+ # Chunk path wants the pre-sigmoided fp32 beta (its kernels
589
+ # don't sigmoid); beta_ns is raw bf16 from forward.
590
+ beta=_cast_sigmoid(beta_ns.squeeze(0)).unsqueeze(0),
591
+ A_log=self.A_log,
592
+ g_bias=self.dt_bias,
593
+ initial_state=initial_state,
594
+ output_final_state=True,
595
+ use_qk_l2norm_in_kernel=True,
596
+ cu_seqlens=non_spec_query_start_loc,
597
+ safe_gate=safe_gate,
598
+ lower_bound=lower_bound,
599
+ )
600
+ # Init cache
601
+ scatter_states(
602
+ recurrent_state,
603
+ last_recurrent_state,
604
+ non_spec_state_indices_tensor,
605
+ )
606
+ elif attn_metadata_narrowed.num_decodes > 0:
607
+ assert non_spec_query_start_loc is not None
608
+ assert non_spec_state_indices_tensor is not None
609
+ # Plain decode step (no spec tokens): token order is dense, so the
610
+ # kernel can write straight into the layer output buffer. A mixed
611
+ # step scatters non-spec output via non_spec_token_indx instead.
612
+ # Gate computed in-kernel (COMPUTE_GATE), beta sigmoided in-kernel.
613
+ if not use_spec:
614
+ ns_out = spec_out
615
+ core_attn_out_non_spec, _ = fused_recurrent_kda(
616
+ q=_rearr(q_ns),
617
+ k=_rearr(k_ns),
618
+ v=_rearr(v_ns),
619
+ g=g1_ns,
620
+ beta=beta_ns,
621
+ initial_state=recurrent_state,
622
+ use_qk_l2norm_in_kernel=True,
623
+ cu_seqlens=non_spec_query_start_loc[
624
+ : attn_metadata_narrowed.num_decodes + 1
625
+ ],
626
+ ssm_state_indices=non_spec_state_indices_tensor,
627
+ out=ns_out,
628
+ sigmoid_beta=True,
629
+ a_log=self.A_log,
630
+ g_bias=self.dt_bias,
631
+ compute_gate=True,
632
+ lower_bound=lower_bound,
633
+ )
634
+
635
+ # --- merge spec / non-spec outputs back into token order ---
636
+ if use_spec and core_attn_out_non_spec is not None:
637
+ assert core_attn_out_spec is not None
638
+ merged = torch.empty(
639
+ (1, num_actual_tokens, *core_attn_out_spec.shape[2:]),
640
+ dtype=core_attn_out_non_spec.dtype,
641
+ device=core_attn_out_non_spec.device,
642
+ )
643
+ merged.index_copy_(1, spec_token_indx, core_attn_out_spec)
644
+ merged.index_copy_(1, non_spec_token_indx, core_attn_out_non_spec)
645
+ core_attn_out[0, :num_actual_tokens] = merged.squeeze(0)
646
+ elif use_spec:
647
+ assert core_attn_out_spec is not None
648
+ if spec_out is None:
649
+ core_attn_out[0, :num_actual_tokens] = core_attn_out_spec.squeeze(0)
650
+ else:
651
+ assert core_attn_out_non_spec is not None
652
+ if ns_out is None:
653
+ core_attn_out[0, :num_actual_tokens] = core_attn_out_non_spec[
654
+ 0, :num_actual_tokens
655
+ ]
serving/model.py ADDED
@@ -0,0 +1,1229 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
+
4
+ from collections.abc import Iterable
5
+ from typing import ClassVar, Literal
6
+
7
+ import torch
8
+ from torch import nn
9
+
10
+ from vllm.config import ParallelConfig, VllmConfig
11
+ from vllm.distributed import (
12
+ get_ep_group,
13
+ get_pp_group,
14
+ get_tensor_model_parallel_rank,
15
+ get_tensor_model_parallel_world_size,
16
+ tensor_model_parallel_all_gather,
17
+ )
18
+ from vllm.logger import init_logger
19
+ from vllm.model_executor.layers.activation import SiluAndMul, SiluAndMulWithClamp
20
+ from vllm.model_executor.layers.fused_moe import (
21
+ FusedMoEFactory,
22
+ GateLinear,
23
+ fused_moe_make_expert_params_mapping,
24
+ )
25
+ from vllm.model_executor.layers.layernorm import RMSNorm
26
+ from vllm.model_executor.layers.linear import (
27
+ MergedColumnParallelLinear,
28
+ RowParallelLinear,
29
+ )
30
+ from vllm.model_executor.layers.logits_processor import LogitsProcessor
31
+ from vllm.model_executor.layers.mamba.mamba_utils import (
32
+ MambaStateCopyFunc,
33
+ MambaStateCopyFuncCalculator,
34
+ MambaStateDtypeCalculator,
35
+ MambaStateShapeCalculator,
36
+ )
37
+ from vllm.model_executor.layers.mhc import (
38
+ MHCFusedPostPreOp,
39
+ MHCPostOp,
40
+ MHCPreOp,
41
+ hc_contract,
42
+ hc_expand,
43
+ )
44
+ from vllm.model_executor.layers.quantization import QuantizationConfig
45
+ from vllm.model_executor.layers.quantization.utils.quant_utils import (
46
+ GroupShape,
47
+ scaled_dequantize,
48
+ )
49
+ from vllm.model_executor.layers.vocab_parallel_embedding import (
50
+ ParallelLMHead,
51
+ VocabParallelEmbedding,
52
+ )
53
+ from vllm.model_executor.model_loader.weight_utils import (
54
+ default_weight_loader,
55
+ maybe_remap_kv_scale_name,
56
+ )
57
+ from vllm.model_executor.models.deepseek_v2 import _get_moe_router_dtype
58
+ from vllm.model_executor.models.glm4_1v import (
59
+ Glm4vDummyInputsBuilder,
60
+ Glm4vForConditionalGeneration,
61
+ )
62
+ from vllm.model_executor.models.interfaces import (
63
+ HasInnerState,
64
+ IsHybrid,
65
+ MixtureOfExperts,
66
+ SupportsPP,
67
+ )
68
+ from vllm.model_executor.models.utils import (
69
+ AutoWeightsLoader,
70
+ PPMissingLayer,
71
+ init_vllm_registered_model,
72
+ is_pp_missing_parameter,
73
+ make_layers,
74
+ maybe_prefix,
75
+ sequence_parallel_chunk,
76
+ )
77
+ from vllm.models.common.ops.sequence_parallel import (
78
+ sp_all_gather,
79
+ sp_reduce_scatter,
80
+ sp_shard,
81
+ )
82
+ from vllm.multimodal import MULTIMODAL_REGISTRY
83
+ from vllm.platforms import current_platform
84
+ from vllm.sequence import IntermediateTensors
85
+ from vllm.transformers_utils.configs.glm5_next import Glm5NextConfig
86
+
87
+ from .attention import Glm5NextMLAAttention
88
+ from .kda import Glm5NextLinearAttention
89
+ from .multimodal import (
90
+ Glm5NextMultiModalProcessor,
91
+ Glm5NextProcessingInfo,
92
+ Glm5NextVisionTransformer,
93
+ )
94
+
95
+ logger = init_logger(__name__)
96
+
97
+
98
+ class Glm5NextMLP(nn.Module):
99
+ def __init__(
100
+ self,
101
+ hidden_size: int,
102
+ intermediate_size: int,
103
+ hidden_act: str,
104
+ quant_config: QuantizationConfig | None = None,
105
+ reduce_results: bool = True,
106
+ is_sequence_parallel=False,
107
+ prefix: str = "",
108
+ swiglu_limit: float | None = None,
109
+ ) -> None:
110
+ super().__init__()
111
+
112
+ # If is_sequence_parallel, the input and output tensors are sharded
113
+ # across the ranks within the tp_group. In this case the weights are
114
+ # replicated and no collective ops are needed.
115
+ # Otherwise we use standard TP with an allreduce at the end.
116
+ self.gate_up_proj = MergedColumnParallelLinear(
117
+ hidden_size,
118
+ [intermediate_size] * 2,
119
+ bias=False,
120
+ quant_config=quant_config,
121
+ disable_tp=is_sequence_parallel,
122
+ prefix=f"{prefix}.gate_up_proj",
123
+ )
124
+ self.down_proj = RowParallelLinear(
125
+ intermediate_size,
126
+ hidden_size,
127
+ bias=False,
128
+ quant_config=quant_config,
129
+ reduce_results=reduce_results,
130
+ disable_tp=is_sequence_parallel,
131
+ prefix=f"{prefix}.down_proj",
132
+ )
133
+ if hidden_act != "silu":
134
+ raise ValueError(
135
+ f"Unsupported activation: {hidden_act}. Only silu is supported for now."
136
+ )
137
+
138
+ self.swiglu_limit = swiglu_limit
139
+ if self.swiglu_limit is not None:
140
+ self.act_fn = SiluAndMulWithClamp(swiglu_limit=self.swiglu_limit)
141
+ else:
142
+ self.act_fn = SiluAndMul()
143
+
144
+ def forward(self, x):
145
+ gate_up, _ = self.gate_up_proj(x)
146
+ x = self.act_fn(gate_up)
147
+ x, _ = self.down_proj(x)
148
+ return x
149
+
150
+
151
+ class Glm5NextMoE(nn.Module):
152
+ def __init__(
153
+ self,
154
+ config: Glm5NextConfig,
155
+ parallel_config: ParallelConfig,
156
+ quant_config: QuantizationConfig | None = None,
157
+ prefix: str = "",
158
+ apply_routed_scale_to_output: bool = False,
159
+ ):
160
+ super().__init__()
161
+ self.tp_size = get_tensor_model_parallel_world_size()
162
+ self.tp_rank = get_tensor_model_parallel_rank()
163
+
164
+ self.routed_scaling_factor = getattr(config, "routed_scaling_factor", 1.0)
165
+
166
+ self.ep_group = get_ep_group().device_group
167
+ self.ep_rank = get_ep_group().rank_in_group
168
+ self.ep_size = self.ep_group.size()
169
+ self.n_routed_experts: int = config.n_routed_experts
170
+ self.n_shared_experts: int = config.n_shared_experts
171
+
172
+ self.is_sequence_parallel = parallel_config.use_sequence_parallel_moe
173
+
174
+ if config.hidden_act != "silu":
175
+ raise ValueError(
176
+ f"Unsupported activation: {config.hidden_act}. "
177
+ "Only silu is supported for now."
178
+ )
179
+
180
+ self.router_dtype = _get_moe_router_dtype(config)
181
+ self.gate = GateLinear(
182
+ config.hidden_size,
183
+ config.n_routed_experts,
184
+ out_dtype=self.router_dtype,
185
+ prefix=f"{prefix}.gate",
186
+ )
187
+ if getattr(config, "topk_method", None) == "noaux_tc":
188
+ self.gate.e_score_correction_bias = nn.Parameter(
189
+ torch.empty(config.n_routed_experts, dtype=torch.float32)
190
+ )
191
+ else:
192
+ self.gate.e_score_correction_bias = None
193
+
194
+ # Load balancing settings.
195
+ eplb_config = parallel_config.eplb_config
196
+ self.enable_eplb = parallel_config.enable_eplb
197
+
198
+ self.n_redundant_experts = eplb_config.num_redundant_experts
199
+ self.n_logical_experts = self.n_routed_experts
200
+ self.n_physical_experts = self.n_logical_experts + self.n_redundant_experts
201
+ self.n_local_physical_experts = self.n_physical_experts // self.ep_size
202
+
203
+ self.physical_expert_start = self.ep_rank * self.n_local_physical_experts
204
+ self.physical_expert_end = (
205
+ self.physical_expert_start + self.n_local_physical_experts
206
+ )
207
+
208
+ swiglu_limit = getattr(config, "swiglu_limit", None)
209
+ if config.n_shared_experts is None:
210
+ self.shared_experts = None
211
+ else:
212
+ intermediate_size = config.moe_intermediate_size * config.n_shared_experts
213
+
214
+ self.shared_experts = Glm5NextMLP(
215
+ hidden_size=config.hidden_size,
216
+ intermediate_size=intermediate_size,
217
+ hidden_act=config.hidden_act,
218
+ quant_config=quant_config,
219
+ is_sequence_parallel=self.is_sequence_parallel,
220
+ reduce_results=False,
221
+ prefix=f"{prefix}.shared_experts",
222
+ swiglu_limit=swiglu_limit,
223
+ )
224
+
225
+ self.experts = FusedMoEFactory(
226
+ shared_experts=self.shared_experts,
227
+ gate=self.gate,
228
+ num_experts=config.n_routed_experts,
229
+ top_k=config.num_experts_per_token,
230
+ hidden_size=config.hidden_size,
231
+ intermediate_size=config.moe_intermediate_size,
232
+ renormalize=getattr(config, "norm_topk_prob", True),
233
+ quant_config=quant_config,
234
+ use_grouped_topk=True,
235
+ num_expert_group=getattr(config, "n_group", 1),
236
+ topk_group=getattr(config, "topk_group", 1),
237
+ prefix=f"{prefix}.experts",
238
+ scoring_func=getattr(config, "scoring_func", "softmax"),
239
+ routed_scaling_factor=self.routed_scaling_factor,
240
+ apply_routed_scale_to_output=apply_routed_scale_to_output,
241
+ e_score_correction_bias=self.gate.e_score_correction_bias,
242
+ enable_eplb=self.enable_eplb,
243
+ num_redundant_experts=self.n_redundant_experts,
244
+ is_sequence_parallel=self.is_sequence_parallel,
245
+ n_shared_experts=None,
246
+ router_logits_dtype=self.gate.out_dtype,
247
+ swiglu_limit=swiglu_limit,
248
+ )
249
+
250
+ def forward(
251
+ self,
252
+ hidden_states: torch.Tensor,
253
+ already_sequence_parallel: bool = False,
254
+ ) -> torch.Tensor:
255
+ num_tokens, hidden_dim = hidden_states.shape
256
+
257
+ # Chunk the hidden states so they aren't replicated across TP ranks.
258
+ # This avoids duplicate computation in self.experts.
259
+ if self.is_sequence_parallel and not already_sequence_parallel:
260
+ hidden_states = sequence_parallel_chunk(hidden_states)
261
+
262
+ # The router is always external (self.gate); main's MoERunner expects
263
+ # pre-computed router_logits, so compute them here unconditionally.
264
+ router_logits, _ = self.gate(hidden_states)
265
+ final_hidden_states = self.experts(
266
+ hidden_states=hidden_states, router_logits=router_logits
267
+ )
268
+
269
+ if self.is_sequence_parallel and not already_sequence_parallel:
270
+ final_hidden_states = tensor_model_parallel_all_gather(
271
+ final_hidden_states, 0
272
+ )
273
+ final_hidden_states = final_hidden_states[:num_tokens]
274
+
275
+ return final_hidden_states.view(num_tokens, hidden_dim)
276
+
277
+
278
+ class Glm5NextDecoderLayer(nn.Module):
279
+ def __init__(
280
+ self,
281
+ vllm_config: VllmConfig,
282
+ config: Glm5NextConfig,
283
+ layer_idx: int,
284
+ prefix: str = "",
285
+ topk_indices_buffer: torch.Tensor | None = None,
286
+ is_mtp_layer: bool = False,
287
+ **kwargs,
288
+ ) -> None:
289
+ super().__init__()
290
+
291
+ cache_config = vllm_config.cache_config
292
+ quant_config = vllm_config.quant_config
293
+ parallel_config = vllm_config.parallel_config
294
+
295
+ self.hidden_size = config.hidden_size
296
+ self.layer_idx = layer_idx
297
+ self.is_moe = config.is_moe
298
+ self.num_hidden_layers = config.num_hidden_layers
299
+ self.rms_norm_eps = config.rms_norm_eps
300
+ self.num_experts = config.n_routed_experts
301
+ self.is_mtp_layer = is_mtp_layer
302
+ self.mhc = config.mhc
303
+ self.layer_kind = "kda" if config.is_kda_layer(layer_idx) else "mla"
304
+ self.is_sequence_parallel = parallel_config.use_sequence_parallel_moe
305
+
306
+ if config.is_kda_layer(layer_idx):
307
+ self.self_attn = Glm5NextLinearAttention(
308
+ config=config,
309
+ vllm_config=vllm_config,
310
+ prefix=f"{prefix}.self_attn",
311
+ )
312
+ else:
313
+ # MLA layers require the latent head dims, which are guaranteed set
314
+ # on MLA configs; narrow away the `int | None`.
315
+ assert config.v_head_dim is not None
316
+ assert config.kv_lora_rank is not None
317
+ self.self_attn = Glm5NextMLAAttention(
318
+ vllm_config=vllm_config,
319
+ config=config,
320
+ hidden_size=self.hidden_size,
321
+ num_heads=config.num_attention_heads,
322
+ qk_nope_head_dim=config.qk_nope_head_dim,
323
+ qk_rope_head_dim=config.qk_rope_head_dim,
324
+ v_head_dim=config.v_head_dim,
325
+ q_lora_rank=config.q_lora_rank,
326
+ kv_lora_rank=config.kv_lora_rank,
327
+ max_position_embeddings=config.max_position_embeddings,
328
+ cache_config=cache_config,
329
+ # LOCAL PATCH (fp8attn-r2): was quant_config=None ("MLA
330
+ # projections are BF16 in checkpoint"). Pass the real config so
331
+ # FP8-serialized MLA projections can stay FP8-resident; BF16
332
+ # checkpoints still resolve every self_attn module to
333
+ # UnquantizedLinearMethod via the config's ignore list.
334
+ quant_config=quant_config,
335
+ prefix=f"{prefix}.self_attn",
336
+ topk_indices_buffer=topk_indices_buffer,
337
+ skip_rope=getattr(config, "mla_nope", False),
338
+ )
339
+
340
+ # MTP layers sit past the base model's hidden layers (layer_idx >=
341
+ # num_hidden_layers), so they're outside mlp_layer_types; default them
342
+ # to the last base layer's MLP type (sparse/MoE for these checkpoints).
343
+ mlp_layer_types = config.mlp_layer_types
344
+ mlp_type = (
345
+ mlp_layer_types[layer_idx]
346
+ if layer_idx < len(mlp_layer_types)
347
+ else (mlp_layer_types[-1] if mlp_layer_types else "sparse")
348
+ )
349
+ if self.is_moe and self.num_experts is not None and mlp_type == "sparse":
350
+ self.mlp = Glm5NextMoE(
351
+ config=config,
352
+ parallel_config=parallel_config,
353
+ quant_config=quant_config,
354
+ prefix=f"{prefix}.mlp",
355
+ )
356
+ else:
357
+ self.mlp = Glm5NextMLP(
358
+ hidden_size=self.hidden_size,
359
+ intermediate_size=config.intermediate_size,
360
+ hidden_act=config.hidden_act,
361
+ quant_config=quant_config,
362
+ prefix=f"{prefix}.mlp",
363
+ swiglu_limit=config.swiglu_limit,
364
+ )
365
+ self.input_layernorm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
366
+ # Cached for the hot forward path (isinstance per layer per step).
367
+ self._mlp_is_moe = isinstance(self.mlp, Glm5NextMoE)
368
+ # In SP, the attention output projection leaves a partial sum; the
369
+ # decoder-layer reduce_scatter after attention completes it (DSv4 pattern).
370
+ # MTP layers use the non-mHC path which has no sp_reduce_scatter, so
371
+ # their o_proj must still reduce normally.
372
+ if self.is_sequence_parallel and not is_mtp_layer:
373
+ self.self_attn.o_proj.reduce_results = False
374
+ self.post_attention_layernorm = RMSNorm(
375
+ config.hidden_size, eps=config.rms_norm_eps
376
+ )
377
+
378
+ if self.mhc and not is_mtp_layer:
379
+ # mhc config
380
+ self.mhc_num_residual_streams = config.mhc_num_residual_streams
381
+ self.mhc_no_norm_weight = config.mhc_no_norm_weight
382
+ self.mhc_tau = config.mhc_tau
383
+ self.hc_eps = config.hc_eps
384
+ self.mhc_sinkhorn_iterations = config.mhc_sinkhorn_iterations
385
+ self.mhc_post_mult_value = config.mhc_post_mult_value
386
+
387
+ n = config.mhc_num_residual_streams
388
+ d_model = n * self.hidden_size
389
+ mix_hc = (2 + n) * n
390
+
391
+ self.n = n
392
+
393
+ # attn hc
394
+ self.hc_attn_fn = nn.Parameter(
395
+ torch.empty(mix_hc, d_model, dtype=torch.float32)
396
+ )
397
+ self.hc_attn_base = nn.Parameter(torch.empty(mix_hc, dtype=torch.float32))
398
+ self.hc_attn_scale = nn.Parameter(torch.empty(3, dtype=torch.float32))
399
+
400
+ # ffn hc
401
+ self.hc_ffn_fn = nn.Parameter(
402
+ torch.empty(mix_hc, d_model, dtype=torch.float32)
403
+ )
404
+ self.hc_ffn_base = nn.Parameter(torch.empty(mix_hc, dtype=torch.float32))
405
+ self.hc_ffn_scale = nn.Parameter(torch.empty(3, dtype=torch.float32))
406
+
407
+ self.mhc_pre_op = MHCPreOp()
408
+ self.mhc_post_op = MHCPostOp()
409
+ self.mhc_fused_post_pre_op = MHCFusedPostPreOp()
410
+
411
+ def forward(
412
+ self,
413
+ positions: torch.Tensor,
414
+ hidden_states: torch.Tensor,
415
+ residual: torch.Tensor | None = None,
416
+ post: torch.Tensor | None = None,
417
+ comb: torch.Tensor | None = None,
418
+ ) -> tuple[
419
+ torch.Tensor,
420
+ torch.Tensor | None,
421
+ torch.Tensor | None,
422
+ torch.Tensor | None,
423
+ ]:
424
+ # 70B or MTP layers: KDA + MoE without HC.
425
+ if not self.mhc or self.is_mtp_layer:
426
+ residual = hidden_states
427
+ hidden_states = self.input_layernorm(hidden_states)
428
+
429
+ attn_output = self.self_attn(
430
+ hidden_states=hidden_states,
431
+ positions=positions,
432
+ )
433
+ hidden_states, residual = self.post_attention_layernorm(
434
+ attn_output, residual=residual
435
+ )
436
+ hidden_states = self.mlp(hidden_states)
437
+ if self.is_mtp_layer:
438
+ # Return the unsummed pair: the MTP caller feeds it straight
439
+ # into shared_head's fused_add_rms_norm (one kernel instead of
440
+ # a separate residual-add + norm). The sum itself is unchanged
441
+ # (fp32-accumulated inside the fused kernel).
442
+ return hidden_states, residual, None, None
443
+ hidden_states = residual + hidden_states
444
+ return hidden_states, residual, None, None
445
+
446
+ # mHC start. `post`/`comb` carry the previous layer's deferred
447
+ # hc_post inputs (its ffn-pre outputs); when present, fuse that
448
+ # hc_post with this layer's attn hc_pre into one kernel (inter-layer
449
+ # fusion). Layer 0 has no incoming state -> standalone hc_pre.
450
+ x = hidden_states
451
+ if post is None:
452
+ if self.layer_idx == 0:
453
+ x = hc_expand(x, self.n)
454
+ residual = x
455
+ post, comb, x = self.hc_pre(
456
+ x,
457
+ self.hc_attn_fn,
458
+ self.hc_attn_scale,
459
+ self.hc_attn_base,
460
+ norm_weight=self.input_layernorm.weight.data,
461
+ norm_eps=self.input_layernorm.variance_epsilon,
462
+ )
463
+ else:
464
+ residual, post, comb, x = self.hc_fused_post_pre(
465
+ x,
466
+ residual,
467
+ post,
468
+ comb,
469
+ self.hc_attn_fn,
470
+ self.hc_attn_scale,
471
+ self.hc_attn_base,
472
+ norm_weight=self.input_layernorm.weight.data,
473
+ norm_eps=self.input_layernorm.variance_epsilon,
474
+ )
475
+
476
+ # Attention needs the full token sequence; mHC above ran on the SP
477
+ # shard. Gather for attention, scatter back afterward (DSv4 pattern).
478
+ if self.is_sequence_parallel:
479
+ x = sp_all_gather(x)[: positions.shape[0]]
480
+
481
+ x = self.self_attn(
482
+ hidden_states=x,
483
+ positions=positions,
484
+ )
485
+
486
+ if self.is_sequence_parallel:
487
+ x = sp_reduce_scatter(x)
488
+
489
+ # Fuse post-attn hc_post + pre-FFN hc_pre (+ RMSNorm) into one kernel.
490
+ residual, post, comb, x = self.hc_fused_post_pre(
491
+ x,
492
+ residual,
493
+ post,
494
+ comb,
495
+ self.hc_ffn_fn,
496
+ self.hc_ffn_scale,
497
+ self.hc_ffn_base,
498
+ norm_weight=self.post_attention_layernorm.weight.data,
499
+ norm_eps=self.post_attention_layernorm.variance_epsilon,
500
+ )
501
+
502
+ # Fully Connected
503
+ if self._mlp_is_moe:
504
+ x = self.mlp(x, already_sequence_parallel=self.is_sequence_parallel)
505
+ else:
506
+ x = self.mlp(x)
507
+
508
+ # mHC end. The last mHC layer materializes its final hc_post (nothing
509
+ # to fuse with) then contracts; every other layer defers its hc_post to
510
+ # the next layer's fused pre, returning the state.
511
+ if self.layer_idx == self.num_hidden_layers - 1:
512
+ x = self.hc_post(x, residual, post, comb)
513
+ x = hc_contract(x, self.n)
514
+ return x, None, None, None
515
+
516
+ return x, residual, post, comb
517
+
518
+ def hc_pre(
519
+ self,
520
+ x: torch.Tensor,
521
+ hc_fn: torch.Tensor,
522
+ hc_scale: torch.Tensor,
523
+ hc_base: torch.Tensor,
524
+ norm_weight: torch.Tensor | None = None,
525
+ norm_eps: float = 0.0,
526
+ ):
527
+ post_mix, res_mix, layer_input = self.mhc_pre_op(
528
+ residual=x,
529
+ fn=hc_fn,
530
+ hc_scale=hc_scale,
531
+ hc_base=hc_base,
532
+ rms_eps=self.rms_norm_eps,
533
+ hc_pre_eps=self.hc_eps,
534
+ hc_sinkhorn_eps=self.hc_eps,
535
+ hc_post_mult_value=self.mhc_post_mult_value,
536
+ sinkhorn_repeat=self.mhc_sinkhorn_iterations,
537
+ norm_weight=norm_weight,
538
+ norm_eps=norm_eps,
539
+ )
540
+ return post_mix, res_mix, layer_input
541
+
542
+ def hc_post(
543
+ self,
544
+ x: torch.Tensor,
545
+ residual: torch.Tensor,
546
+ post: torch.Tensor,
547
+ comb: torch.Tensor,
548
+ ):
549
+ return self.mhc_post_op(x, residual, post, comb)
550
+
551
+ def hc_fused_post_pre(
552
+ self,
553
+ x: torch.Tensor,
554
+ residual: torch.Tensor,
555
+ post: torch.Tensor,
556
+ comb: torch.Tensor,
557
+ hc_fn: torch.Tensor,
558
+ hc_scale: torch.Tensor,
559
+ hc_base: torch.Tensor,
560
+ norm_weight: torch.Tensor | None = None,
561
+ norm_eps: float = 0.0,
562
+ ):
563
+ return self.mhc_fused_post_pre_op(
564
+ x=x,
565
+ residual=residual,
566
+ post_layer_mix=post,
567
+ comb_res_mix=comb,
568
+ fn=hc_fn,
569
+ hc_scale=hc_scale,
570
+ hc_base=hc_base,
571
+ rms_eps=self.rms_norm_eps,
572
+ hc_pre_eps=self.hc_eps,
573
+ hc_sinkhorn_eps=self.hc_eps,
574
+ hc_post_mult_value=self.mhc_post_mult_value,
575
+ sinkhorn_repeat=self.mhc_sinkhorn_iterations,
576
+ n_splits=1,
577
+ tile_n=1,
578
+ norm_weight=norm_weight,
579
+ norm_eps=norm_eps,
580
+ )
581
+
582
+
583
+ class Glm5NextModel(nn.Module):
584
+ def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):
585
+ super().__init__()
586
+
587
+ config = vllm_config.model_config.hf_config
588
+ self.config = config
589
+
590
+ self.vocab_size = config.vocab_size
591
+ self.device = current_platform.device_type
592
+
593
+ """
594
+ if config.index_topk is not None:
595
+ topk_indices_buffer = torch.empty(
596
+ vllm_config.scheduler_config.max_num_batched_tokens,
597
+ config.index_topk,
598
+ dtype=torch.int32,
599
+ device=self.device,
600
+ )
601
+ else:
602
+ """
603
+ # `index_topk` is declared on Glm5NextTextConfig with a default of None,
604
+ # so hasattr() is True even for full-MLA configs (no kpool indexer).
605
+ # Gate on the value being set instead.
606
+ self.is_v32 = getattr(config, "index_topk", None) is not None
607
+ if self.is_v32:
608
+ topk_tokens = config.index_topk
609
+ # kpool widens the topk buffer: selecting topk_tokens//kpool pools and
610
+ # expanding them yields topk_tokens token indices, plus an always-
611
+ # selected tail of up to kpool-1 incomplete-pool tokens. The attention
612
+ # backend reads the width dynamically via topk_indices.shape[1].
613
+ kpool = getattr(config, "index_kpool", 1) or 1
614
+ buffer_width = topk_tokens
615
+ # The sparse MLA attention kernel
616
+ # (triton_convert_req_index_to_global_index) tiles the topk
617
+ # dimension in BLOCK_N=128 columns and requires the buffer width
618
+ # to be a multiple of it; otherwise it raises
619
+ # "NUM_TOPK_TOKENS must be divisible by BLOCK_N". Round up: the
620
+ # extra slots stay -1 (the indexer op initializes the buffer to
621
+ # -1) and are masked out by the attention kernel, so they do not
622
+ # affect the softmax over the selected tokens.
623
+ sparse_topk_block_n = 128
624
+ buffer_width = (
625
+ (buffer_width + sparse_topk_block_n - 1) // sparse_topk_block_n
626
+ ) * sparse_topk_block_n
627
+ topk_indices_buffer = torch.empty(
628
+ vllm_config.scheduler_config.max_num_batched_tokens,
629
+ buffer_width,
630
+ dtype=torch.int32,
631
+ device=self.device,
632
+ )
633
+ else:
634
+ # Full-MLA config (no kpool sparse indexer): no topk buffer.
635
+ topk_indices_buffer = None
636
+
637
+ if get_pp_group().is_first_rank:
638
+ self.embed_tokens = VocabParallelEmbedding(
639
+ config.vocab_size,
640
+ config.hidden_size,
641
+ prefix=f"{prefix}.embed_tokens",
642
+ )
643
+ else:
644
+ self.embed_tokens = PPMissingLayer()
645
+
646
+ def get_layer(prefix: str):
647
+ layer_idx = int(prefix.rsplit(".", 1)[1])
648
+ return Glm5NextDecoderLayer(
649
+ vllm_config=vllm_config,
650
+ config=config,
651
+ layer_idx=layer_idx,
652
+ prefix=prefix,
653
+ topk_indices_buffer=topk_indices_buffer,
654
+ )
655
+
656
+ self.start_layer, self.end_layer, self.layers = make_layers(
657
+ config.num_hidden_layers,
658
+ get_layer,
659
+ prefix=f"{prefix}.layers",
660
+ )
661
+ # The active slice is fixed after construction; cache it so forward
662
+ # doesn't rebuild the slice (a fresh list) every step.
663
+ self._active_layers = self.layers[self.start_layer : self.end_layer]
664
+
665
+ if get_pp_group().is_last_rank:
666
+ self.norm = RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
667
+ else:
668
+ self.norm = PPMissingLayer()
669
+
670
+ self.is_sequence_parallel = (
671
+ vllm_config.parallel_config.use_sequence_parallel_moe
672
+ )
673
+
674
+ world_size = get_tensor_model_parallel_world_size()
675
+ assert config.num_attention_heads % world_size == 0, (
676
+ "num_attention_heads must be divisible by world_size"
677
+ )
678
+
679
+ def embed_input_ids(self, input_ids: torch.Tensor) -> torch.Tensor:
680
+ return self.embed_tokens(input_ids)
681
+
682
+ def forward(
683
+ self,
684
+ input_ids: torch.Tensor | None,
685
+ positions: torch.Tensor,
686
+ intermediate_tensors: IntermediateTensors | None,
687
+ inputs_embeds: torch.Tensor | None = None,
688
+ **kwargs,
689
+ ) -> torch.Tensor:
690
+ if get_pp_group().is_first_rank:
691
+ if inputs_embeds is not None:
692
+ hidden_states = inputs_embeds
693
+ else:
694
+ hidden_states = self.embed_input_ids(input_ids)
695
+ residual = None
696
+ post = None
697
+ comb = None
698
+ else:
699
+ assert intermediate_tensors is not None
700
+ hidden_states = intermediate_tensors["hidden_states"]
701
+ residual = intermediate_tensors["residual"]
702
+ # post/comb (deferred mHC hc_post state) are not propagated across
703
+ # PP ranks; the receiving rank's first mHC layer uses standalone pre.
704
+ post = None
705
+ comb = None
706
+
707
+ full_num_tokens = positions.shape[0]
708
+ if self.is_sequence_parallel:
709
+ hidden_states = sp_shard(hidden_states)
710
+
711
+ for layer in self._active_layers:
712
+ hidden_states, residual, post, comb = layer(
713
+ positions, hidden_states, residual, post, comb
714
+ )
715
+
716
+ if not get_pp_group().is_last_rank:
717
+ # PP is gated off for GLM5Next (no make_empty_intermediate_tensors),
718
+ # so this branch is not exercised. post/comb are the deferred
719
+ # hc_post state of this rank's last mHC layer; a future PP path
720
+ # would need to propagate them, but for now they are dropped (the
721
+ # receiving rank's first layer would fall back to standalone pre).
722
+ return IntermediateTensors(
723
+ {"hidden_states": hidden_states, "residual": residual}
724
+ )
725
+
726
+ if self.is_sequence_parallel:
727
+ hidden_states = sp_all_gather(hidden_states)[:full_num_tokens]
728
+
729
+ hidden_states = self.norm(hidden_states)
730
+ return hidden_states
731
+
732
+ def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
733
+ stacked_params_mapping = [
734
+ # (param_name, shard_name, shard_id)
735
+ (".gate_up_proj", ".gate_proj", 0),
736
+ (".gate_up_proj", ".up_proj", 1),
737
+ # MLA: fuse q_a_proj and kv_a_proj_with_mqa
738
+ (".fused_qkv_a_proj", ".q_a_proj", 0),
739
+ (".fused_qkv_a_proj", ".kv_a_proj_with_mqa", 1),
740
+ # Indexer: fuse wk and weights_proj
741
+ (".wk_weights_proj", ".wk", 0),
742
+ (".wk_weights_proj", ".weights_proj", 1),
743
+ # KDA: merge q, k, v, b, f_a, g_a projections into one GEMM
744
+ (".in_proj_qkvbfg_a", ".q_proj", 0),
745
+ (".in_proj_qkvbfg_a", ".k_proj", 1),
746
+ (".in_proj_qkvbfg_a", ".v_proj", 2),
747
+ (".in_proj_qkvbfg_a", ".b_proj", 3),
748
+ (".in_proj_qkvbfg_a", ".f_a_proj", 4),
749
+ (".in_proj_qkvbfg_a", ".g_a_proj", 5),
750
+ ]
751
+ if self.config.is_moe:
752
+ # Params for weights, fp8 weight scales, fp8 activation scales
753
+ # (param_name, weight_name, expert_id, shard_id)
754
+ expert_params_mapping = fused_moe_make_expert_params_mapping(
755
+ self,
756
+ ckpt_gate_proj_name="gate_proj",
757
+ ckpt_down_proj_name="down_proj",
758
+ ckpt_up_proj_name="up_proj",
759
+ num_experts=self.config.n_routed_experts,
760
+ )
761
+ else:
762
+ expert_params_mapping = []
763
+ params_dict = dict(self.named_parameters())
764
+ loaded_params: set[str] = set()
765
+
766
+ # GLM5-Next NoPE: checkpoint's kv_a_proj_with_mqa has only kv_lora_rank
767
+ # rows, but the model expects kv_lora_rank + qk_rope_head_dim rows.
768
+ # Pad the missing rope portion with zeros.
769
+ kv_a_pad_size = 0
770
+ if self.config.mla_nope and self.config.qk_rope_head_dim > 0:
771
+ kv_a_pad_size = self.config.qk_rope_head_dim
772
+
773
+ _pending_wk_fp8: dict = {}
774
+
775
+ for args in weights:
776
+ name, loaded_weight = args[:2]
777
+ kwargs: dict = args[2] if len(args) > 2 else {}
778
+ if "rotary_emb.inv_freq" in name:
779
+ continue
780
+
781
+ spec_layer = get_spec_layer_idx_from_weight_name(self.config, name)
782
+ if spec_layer is not None:
783
+ continue # skip spec decode layers for main model
784
+ if "rotary_emb.cos_cached" in name or "rotary_emb.sin_cached" in name:
785
+ # Models trained using ColossalAI may include these tensors in
786
+ # the checkpoint. Skip them.
787
+ continue
788
+
789
+ # Handle FP8 indexer WK: dequantize to BF16 for fusion with
790
+ # weights_proj into wk_weights_proj.
791
+ if _try_load_fp8_indexer_wk(
792
+ name,
793
+ loaded_weight,
794
+ _pending_wk_fp8,
795
+ params_dict,
796
+ loaded_params,
797
+ ):
798
+ continue
799
+
800
+ # FP8 checkpoint: dequantize BF16-kept MLA projections
801
+ # (q_a_proj / kv_a_proj_with_mqa / o_proj) to BF16.
802
+ if _try_load_fp8_attn_proj(
803
+ name,
804
+ loaded_weight,
805
+ _pending_wk_fp8,
806
+ params_dict,
807
+ loaded_params,
808
+ kv_a_pad_size,
809
+ ):
810
+ continue
811
+
812
+ # Pad kv_a_proj_with_mqa for NoPE models
813
+ if kv_a_pad_size > 0 and ".kv_a_proj_with_mqa." in name:
814
+ pad = torch.zeros(
815
+ kv_a_pad_size,
816
+ *loaded_weight.shape[1:],
817
+ dtype=loaded_weight.dtype,
818
+ device=loaded_weight.device,
819
+ )
820
+ loaded_weight = torch.cat([loaded_weight, pad], dim=0)
821
+
822
+ for param_name, weight_name, shard_id in stacked_params_mapping:
823
+ if weight_name not in name:
824
+ continue
825
+ # We have mlp.experts[0].gate_proj in the checkpoint.
826
+ # Since we handle the experts below in expert_params_mapping,
827
+ # we need to skip here BEFORE we update the name, otherwise
828
+ # name will be updated to mlp.experts[0].gate_up_proj, which
829
+ # will then be updated below in expert_params_mapping
830
+ # for mlp.experts[0].gate_gate_up_proj, which breaks load.
831
+ if ("mlp.experts." in name) and name not in params_dict:
832
+ continue
833
+ name_mapped = name.replace(weight_name, param_name)
834
+ # QKV fusion: skip if fused module doesn't exist in model
835
+ if param_name == ".fused_qkv_a_proj" and name_mapped not in params_dict:
836
+ continue
837
+ name = name_mapped
838
+ # Skip loading extra bias for GPTQ models.
839
+ if name.endswith(".bias") and name not in params_dict:
840
+ continue
841
+ if is_pp_missing_parameter(name, self):
842
+ continue
843
+ param = params_dict[name]
844
+ weight_loader = param.weight_loader
845
+ weight_loader(param, loaded_weight, shard_id)
846
+ break
847
+ else:
848
+ for idx, (
849
+ param_name,
850
+ weight_name,
851
+ expert_id,
852
+ expert_shard_id,
853
+ ) in enumerate(expert_params_mapping):
854
+ if weight_name not in name:
855
+ continue
856
+ name = name.replace(weight_name, param_name)
857
+ if is_pp_missing_parameter(name, self):
858
+ continue
859
+ param = params_dict[name]
860
+ weight_loader = param.weight_loader
861
+ weight_loader(
862
+ param,
863
+ loaded_weight,
864
+ name,
865
+ expert_id=expert_id,
866
+ shard_id=expert_shard_id,
867
+ )
868
+ break
869
+ else:
870
+ # Skip loading extra bias for GPTQ models.
871
+ if (
872
+ name.endswith(".bias")
873
+ and name not in params_dict
874
+ and not self.config.is_linear_attn
875
+ ): # noqa: E501
876
+ continue
877
+ # Remapping the name of FP8 kv-scale.
878
+ remapped_name = maybe_remap_kv_scale_name(name, params_dict)
879
+ if remapped_name is None:
880
+ continue
881
+ name = remapped_name
882
+ if is_pp_missing_parameter(name, self):
883
+ continue
884
+
885
+ param = params_dict[name]
886
+ weight_loader = getattr(
887
+ param, "weight_loader", default_weight_loader
888
+ )
889
+ weight_loader(param, loaded_weight, **kwargs)
890
+ loaded_params.add(name)
891
+ return loaded_params
892
+
893
+
894
+ class Glm5NextForCausalLM(
895
+ nn.Module, HasInnerState, SupportsPP, MixtureOfExperts, IsHybrid
896
+ ):
897
+ def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):
898
+ super().__init__()
899
+ self.model_config = vllm_config.model_config
900
+ self.vllm_config = vllm_config
901
+ self.config = self.model_config.hf_config
902
+ quant_config = vllm_config.quant_config
903
+ self.quant_config = quant_config
904
+ self.model = Glm5NextModel(
905
+ vllm_config=vllm_config, prefix=maybe_prefix(prefix, "model")
906
+ )
907
+ if get_pp_group().is_last_rank:
908
+ self.lm_head = ParallelLMHead(
909
+ self.config.vocab_size,
910
+ self.config.hidden_size,
911
+ quant_config=quant_config,
912
+ prefix=maybe_prefix(prefix, "lm_head"),
913
+ )
914
+ else:
915
+ self.lm_head = PPMissingLayer()
916
+ logit_scale = getattr(self.config, "logit_scale", 1.0)
917
+ self.logits_processor = LogitsProcessor(
918
+ self.config.vocab_size, scale=logit_scale
919
+ )
920
+
921
+ def embed_input_ids(self, input_ids: torch.Tensor) -> torch.Tensor:
922
+ return self.model.embed_input_ids(input_ids)
923
+
924
+ def forward(
925
+ self,
926
+ input_ids: torch.Tensor | None,
927
+ positions: torch.Tensor,
928
+ intermediate_tensors: IntermediateTensors | None = None,
929
+ inputs_embeds: torch.Tensor | None = None,
930
+ **kwargs,
931
+ ) -> torch.Tensor | IntermediateTensors:
932
+ hidden_states = self.model(
933
+ input_ids, positions, intermediate_tensors, inputs_embeds, **kwargs
934
+ )
935
+ return hidden_states
936
+
937
+ @classmethod
938
+ def get_mamba_state_dtype_from_config(
939
+ cls,
940
+ vllm_config: "VllmConfig",
941
+ ) -> tuple[torch.dtype, torch.dtype]:
942
+ return MambaStateDtypeCalculator.kda_state_dtype(
943
+ vllm_config.model_config.dtype, vllm_config.cache_config.mamba_cache_dtype
944
+ )
945
+
946
+ @classmethod
947
+ def get_mamba_state_shape_from_config(
948
+ cls, vllm_config: "VllmConfig"
949
+ ) -> tuple[tuple[int, int], tuple[int, int, int]]:
950
+ parallel_config = vllm_config.parallel_config
951
+ hf_config = vllm_config.model_config.hf_config
952
+ tp_size = parallel_config.tensor_parallel_size
953
+ num_spec = (
954
+ vllm_config.speculative_config.num_speculative_tokens
955
+ if vllm_config.speculative_config
956
+ else 0
957
+ )
958
+ return MambaStateShapeCalculator.kda_state_shape(
959
+ tp_size,
960
+ hf_config.linear_num_heads,
961
+ hf_config.linear_head_dim,
962
+ conv_kernel_size=hf_config.linear_conv_kernel_dim,
963
+ num_spec=num_spec,
964
+ )
965
+
966
+ @classmethod
967
+ def get_mamba_state_copy_func(
968
+ cls,
969
+ ) -> tuple[
970
+ MambaStateCopyFunc, MambaStateCopyFunc, MambaStateCopyFunc, MambaStateCopyFunc
971
+ ]:
972
+ return MambaStateCopyFuncCalculator.kda_state_copy_func()
973
+
974
+ def compute_logits(
975
+ self,
976
+ hidden_states: torch.Tensor,
977
+ ) -> torch.Tensor | None:
978
+ logits = self.logits_processor(self.lm_head, hidden_states)
979
+ return logits
980
+
981
+ def load_weights(self, weights: Iterable[tuple[str, torch.Tensor]]) -> set[str]:
982
+ loader = AutoWeightsLoader(
983
+ self,
984
+ skip_prefixes=(["lm_head."] if self.config.tie_word_embeddings else None),
985
+ )
986
+ return loader.load_weights(weights)
987
+
988
+
989
+ @MULTIMODAL_REGISTRY.register_processor(
990
+ Glm5NextMultiModalProcessor,
991
+ info=Glm5NextProcessingInfo,
992
+ dummy_inputs=Glm4vDummyInputsBuilder,
993
+ )
994
+ class Glm5NextForConditionalGeneration(
995
+ Glm4vForConditionalGeneration, HasInnerState, IsHybrid
996
+ ):
997
+ # The text model (KDA + dense-MLA + MoE) is a hybrid mamba model. The
998
+ # multimodal wrapper must declare the same interfaces so vLLM treats it as
999
+ # hybrid (auto-aligns mamba/attention block sizes, sizes the mamba state
1000
+ # cache); the mamba-state classmethods delegate to the text model.
1001
+ has_inner_state: ClassVar[Literal[True]] = True
1002
+ is_hybrid: ClassVar[Literal[True]] = True
1003
+
1004
+ # NOTE: weight-prefix mapping is inherited from Glm4vForConditionalGeneration
1005
+ # (``model.visual.`` -> ``visual.``, ``model.language_model.`` ->
1006
+ # ``language_model.model.``, ``lm_head.`` -> ``language_model.lm_head.``),
1007
+ # matching the GLM-OCR / GLM-4V serialization convention. If the real
1008
+ # checkpoint's safetensors keys differ (e.g. ``language_model.model.`` with
1009
+ # no outer ``model.``), override ``hf_to_vllm_mapper`` accordingly.
1010
+
1011
+ @classmethod
1012
+ def get_mamba_state_dtype_from_config(cls, vllm_config: VllmConfig):
1013
+ from .model import Glm5NextForCausalLM
1014
+
1015
+ return Glm5NextForCausalLM.get_mamba_state_dtype_from_config(vllm_config)
1016
+
1017
+ @classmethod
1018
+ def get_mamba_state_shape_from_config(cls, vllm_config: VllmConfig):
1019
+ from .model import Glm5NextForCausalLM
1020
+
1021
+ return Glm5NextForCausalLM.get_mamba_state_shape_from_config(vllm_config)
1022
+
1023
+ @classmethod
1024
+ def get_mamba_state_copy_func(cls):
1025
+ from .model import Glm5NextForCausalLM
1026
+
1027
+ return Glm5NextForCausalLM.get_mamba_state_copy_func()
1028
+
1029
+ def __init__(self, *, vllm_config: VllmConfig, prefix: str = ""):
1030
+ super(Glm4vForConditionalGeneration, self).__init__()
1031
+ config = vllm_config.model_config.hf_config
1032
+ multimodal_config = vllm_config.model_config.multimodal_config
1033
+ assert multimodal_config is not None
1034
+
1035
+ self.config = config
1036
+ self.model_config = vllm_config.model_config
1037
+ self.multimodal_config = multimodal_config
1038
+ self.use_data_parallel = multimodal_config.mm_encoder_tp_mode == "data"
1039
+ self.is_multimodal_pruning_enabled = (
1040
+ multimodal_config.is_multimodal_pruning_enabled()
1041
+ )
1042
+
1043
+ with self._mark_tower_model(vllm_config, {"image", "video"}):
1044
+ self.visual = Glm5NextVisionTransformer(
1045
+ config.text_config,
1046
+ config.vision_config,
1047
+ # Read eps from the VISION sub-config, not the top-level
1048
+ # `config.rms_norm_eps`: Glm5NextConfig.__getattribute__ mirrors
1049
+ # the latter onto text_config (1e-5), silently ignoring the
1050
+ # vision tower's own (1e-6) rms_norm_eps.
1051
+ norm_eps=config.vision_config.rms_norm_eps,
1052
+ # Vision tower ships BF16 weights in this fp8 checkpoint (no
1053
+ # weight_scale_inv for visual.*), so it must NOT inherit the
1054
+ # global fp8 quant_config -- doing so incorrectly quantizes
1055
+ # the tower
1056
+ # and yields NaN image features. Mirrors the MLA/KDA proj
1057
+ # pattern (quant_config=None for BF16 submodules).
1058
+ quant_config=None,
1059
+ prefix=maybe_prefix(prefix, "visual"),
1060
+ )
1061
+
1062
+ with self._mark_language_model(vllm_config):
1063
+ self.language_model = init_vllm_registered_model(
1064
+ vllm_config=vllm_config,
1065
+ hf_config=config.text_config,
1066
+ prefix=maybe_prefix(prefix, "language_model"),
1067
+ architectures=["Glm5NextForCausalLM"],
1068
+ )
1069
+
1070
+ # Glm5NextForCausalLM does not implement make_empty_intermediate_tensors,
1071
+ # so pipeline parallelism is gated off (consistent with the text-only
1072
+ # model) and we intentionally do not alias it here.
1073
+
1074
+ def get_encoder_cudagraph_config(self):
1075
+ # The forked vision tower (multimodal.py) has no abs-pos embeddings, so its
1076
+ # prepare_encoder_metadata does not produce "pos_embeds". Drop it from the
1077
+ # buffer_keys inherited from Glm4vForConditionalGeneration so encoder
1078
+ # CUDA-graph capture/replay does not expect a buffer that is never filled.
1079
+ config = super().get_encoder_cudagraph_config()
1080
+ config.buffer_keys = [k for k in config.buffer_keys if k != "pos_embeds"]
1081
+ return config
1082
+
1083
+
1084
+ def get_spec_layer_idx_from_weight_name(
1085
+ config: Glm5NextConfig, weight_name: str
1086
+ ) -> int | None:
1087
+ if hasattr(config, "num_nextn_predict_layers") and (
1088
+ config.num_nextn_predict_layers > 0
1089
+ ):
1090
+ layer_idx = config.num_hidden_layers
1091
+ for i in range(config.num_nextn_predict_layers):
1092
+ if weight_name.startswith(
1093
+ f"model.layers.{layer_idx + i}."
1094
+ ) or weight_name.startswith(f"layers.{layer_idx + i}."):
1095
+ return layer_idx + i
1096
+ return None
1097
+
1098
+
1099
+ def _try_load_fp8_indexer_wk(name, tensor, buf, params_dict, loaded_params):
1100
+ if "indexer.wk." not in name or "wk_weights" in name:
1101
+ return False
1102
+ is_weight = name.endswith(".weight") and tensor.dtype == torch.float8_e4m3fn
1103
+ is_scale = "weight_scale_inv" in name
1104
+ if not is_weight and not is_scale:
1105
+ return False
1106
+ layer_prefix = name.rsplit(".wk.", 1)[0]
1107
+ entry = buf.setdefault(layer_prefix, {})
1108
+ entry["weight" if is_weight else "scale"] = tensor
1109
+ if "weight" not in entry or "scale" not in entry:
1110
+ return True
1111
+
1112
+ weight_fp8, scale_inv = entry["weight"], entry["scale"]
1113
+ del buf[layer_prefix]
1114
+ block_size = weight_fp8.shape[1] // scale_inv.shape[1]
1115
+ weight_bf16 = scaled_dequantize(
1116
+ weight_fp8,
1117
+ scale_inv,
1118
+ group_shape=GroupShape(block_size, block_size),
1119
+ out_dtype=torch.bfloat16,
1120
+ )
1121
+
1122
+ fused_name = f"{layer_prefix}.wk_weights_proj.weight"
1123
+ param = params_dict[fused_name]
1124
+ param.weight_loader(param, weight_bf16, 0)
1125
+ loaded_params.add(fused_name)
1126
+ return True
1127
+
1128
+
1129
+ def _dequant_fp8_block(
1130
+ weight_fp8: torch.Tensor,
1131
+ scale_inv: torch.Tensor,
1132
+ block_size: int = 128,
1133
+ ) -> torch.Tensor:
1134
+ """Dequantize a block-FP8 (e4m3) weight with per-block scale to BF16.
1135
+
1136
+ Unlike ``scaled_dequantize`` this tolerates a non-divisible (partial last
1137
+ block) shape by zero-padding to a multiple of ``block_size`` before the
1138
+ scale broadcast and trimming back afterwards (e.g. kv_a_proj_with_mqa is
1139
+ 576 rows = 4*128 + 64).
1140
+ """
1141
+ out_dim, in_dim = weight_fp8.shape
1142
+ pad_out = (-out_dim) % block_size
1143
+ pad_in = (-in_dim) % block_size
1144
+ w = weight_fp8
1145
+ if pad_out or pad_in:
1146
+ w = torch.nn.functional.pad(w, (0, pad_in, 0, pad_out))
1147
+ # scale_inv is (ceil(out/block), ceil(in/block)); broadcast to (out, in).
1148
+ s = scale_inv.to(torch.float32)
1149
+ s_full = s.repeat_interleave(block_size, dim=0).repeat_interleave(block_size, dim=1)
1150
+ out = (w.to(torch.float32) * s_full).to(torch.bfloat16)
1151
+ return out[:out_dim, :in_dim].contiguous()
1152
+
1153
+
1154
+ # FP8 checkpoint projections that the MODEL keeps in BF16, so the block-FP8
1155
+ # (weight + weight_scale_inv) must be dequantized to BF16 on load.
1156
+ # Maps checkpoint proj-suffix -> (buffer key, model target base, fused shard id
1157
+ # or None for a direct projection, whether NoPE rope-padding applies).
1158
+ _FP8_ATTN_PROJS = {
1159
+ ".q_a_proj.": ("q_a", "fused_qkv_a_proj", 0, False),
1160
+ ".kv_a_proj_with_mqa.": ("kv_a", "fused_qkv_a_proj", 1, True),
1161
+ ".q_b_proj.": ("q_b", "q_b_proj", None, False),
1162
+ ".o_proj.": ("o_proj", "o_proj", None, False),
1163
+ }
1164
+
1165
+
1166
+ def _try_load_fp8_attn_proj(
1167
+ name,
1168
+ tensor,
1169
+ buf,
1170
+ params_dict,
1171
+ loaded_params,
1172
+ kv_a_pad_size: int,
1173
+ ) -> bool:
1174
+ """Dequantize FP8 q_a_proj / kv_a_proj_with_mqa / o_proj to BF16 on load.
1175
+
1176
+ The FP8 checkpoint stores these as block-FP8 (weight + weight_scale_inv),
1177
+ but the model holds them in BF16 (``fused_qkv_a_proj`` is always BF16 via
1178
+ DeepSeekV2FusedQkvAProjLinear; ``o_proj`` is excluded by
1179
+ modules_to_not_convert). When the model target is BF16 (no
1180
+ ``weight_scale_inv`` param) we dequantize; otherwise we return False so the
1181
+ normal stacked/direct path loads the FP8 tensor as-is.
1182
+ """
1183
+ matched = None
1184
+ for suffix, info in _FP8_ATTN_PROJS.items():
1185
+ if suffix in name:
1186
+ matched = (suffix, info)
1187
+ break
1188
+ if matched is None:
1189
+ return False
1190
+ suffix, (key, target_base, shard_id, is_kva) = matched
1191
+ is_weight = name.endswith(".weight") and tensor.dtype == torch.float8_e4m3fn
1192
+ is_scale = "weight_scale_inv" in name
1193
+ if not is_weight and not is_scale:
1194
+ return False
1195
+
1196
+ layer_prefix = name.rsplit(suffix, 1)[0]
1197
+ target_w = f"{layer_prefix}.{target_base}.weight"
1198
+ target_s = f"{layer_prefix}.{target_base}.weight_scale_inv"
1199
+ # If the model actually kept this projection in FP8, let the normal path
1200
+ # handle it (it has a weight_scale_inv param).
1201
+ if target_s in params_dict:
1202
+ return False
1203
+
1204
+ entry = buf.setdefault(layer_prefix, {}).setdefault(key, {})
1205
+ entry["weight" if is_weight else "scale"] = tensor
1206
+ if "weight" not in entry or "scale" not in entry:
1207
+ return True
1208
+
1209
+ weight_fp8, scale_inv = entry["weight"], entry["scale"]
1210
+ buf[layer_prefix].pop(key, None)
1211
+ block_size = weight_fp8.shape[1] // scale_inv.shape[1]
1212
+ weight_bf16 = _dequant_fp8_block(weight_fp8, scale_inv, block_size)
1213
+ # NoPE: pad kv_a rope portion (kv_lora_rank -> kv_lora_rank + qk_rope_head_dim).
1214
+ if is_kva and kv_a_pad_size > 0:
1215
+ pad = torch.zeros(
1216
+ kv_a_pad_size,
1217
+ weight_bf16.shape[1],
1218
+ dtype=weight_bf16.dtype,
1219
+ device=weight_bf16.device,
1220
+ )
1221
+ weight_bf16 = torch.cat([weight_bf16, pad], dim=0)
1222
+
1223
+ param = params_dict[target_w]
1224
+ if shard_id is None:
1225
+ param.weight_loader(param, weight_bf16)
1226
+ else:
1227
+ param.weight_loader(param, weight_bf16, shard_id)
1228
+ loaded_params.add(target_w)
1229
+ return True
serving/modelopt.py ADDED
The diff for this file is too large to render. See raw diff