quantuminfer 0.0.0-stage → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -0
- package/README.md +96 -2
- package/bin/quantuminfer.js +61 -0
- package/c27/adapters.py +161 -0
- package/c27/harness27.py +349 -0
- package/data/input.txt +40000 -0
- package/data/wikitext/test.txt +7249 -0
- package/engine/API.txt +208 -0
- package/engine/PLUGINS.txt +4 -0
- package/engine/__init__.py +82 -0
- package/engine/adapter.py +505 -0
- package/engine/blocks.py +1180 -0
- package/engine/c12.py +324 -0
- package/engine/c12cu.py +1074 -0
- package/engine/ctx.py +87 -0
- package/engine/dev.py +11 -0
- package/engine/ds4.py +389 -0
- package/engine/kernels.py +833 -0
- package/engine/model.py +281 -0
- package/engine/record.py +140 -0
- package/engine/server.py +183 -0
- package/engine/spec.py +1030 -0
- package/engine/wcode.py +122 -0
- package/p27/SPEC.txt +66 -0
- package/p27/STATUS.txt +91 -0
- package/p27/bench_glm.py +354 -0
- package/p27/bench_multi.py +76 -0
- package/p27/mkfinal.py +98 -0
- package/p27/modal_comp.py +173 -0
- package/p27/modal_dl.py +63 -0
- package/p27/modal_p27.py +168 -0
- package/p27/modal_probe.py +49 -0
- package/p27/p27rules.py +29 -0
- package/p27/pblocks.py +1242 -0
- package/p27/pmodel.py +402 -0
- package/p27/pref.py +151 -0
- package/p27/prof_glm.py +34 -0
- package/p27/quant.py +850 -0
- package/p27/recipes/vllm_b300_single_node_tep_b300_agentx_ep.md +353 -0
- package/p27/recipes/vllm_b300_single_node_tp_b300_agentx.md +351 -0
- package/p27/recipes/vllm_b300_single_node_tp_baseline.md +250 -0
- package/p27/recipes/vllm_default_gb300.md +281 -0
- package/p27/recipes/vllm_glm53_h200.md +301 -0
- package/p27/run_window1.sh +21 -0
- package/p27/run_window2.sh +13 -0
- package/p27/sweep_glm.py +64 -0
- package/p27/t_align.py +42 -0
- package/p27/t_combine.py +28 -0
- package/p27/t_echo.py +31 -0
- package/p27/t_fp8dense.py +59 -0
- package/p27/t_fp8speed.py +48 -0
- package/p27/t_glm.py +340 -0
- package/p27/t_glu.py +30 -0
- package/p27/t_gsuf.py +23 -0
- package/p27/t_jac.py +22 -0
- package/p27/t_moebm.py +30 -0
- package/p27/t_nccl.py +36 -0
- package/p27/t_online_jac.py +31 -0
- package/p27/t_probe.py +4 -0
- package/p27/t_router.py +28 -0
- package/p27/t_symm.py +50 -0
- package/p27/t_tiny.py +116 -0
- package/package.json +34 -4
- package/results/ANALYSIS.md +160 -0
- package/results/comp_vllm_mtp_k5_b300mtp.json +235 -0
- package/results/glm53_b300x8_opt4.json +624 -0
- package/results/res_glm_c32w3_b300.json +638 -0
- package/results/res_glm_final_c32_b300.json +652 -0
- package/results/res_glm_multi_final_b300.json +1821 -0
- package/results/res_glm_online_b300.json +638 -0
- package/results/res_glm_online_fixed_b300.json +638 -0
- package/results/res_glm_opt4_b300.json +624 -0
- package/results/res_glm_t1_j8_b300.json +340 -0
- package/results/res_glm_text_plain_batch_b300.json +5792 -0
- package/results/res_glm_text_w1_b300.json +1635 -0
- package/results/res_glm_text_w3_b300.json +1639 -0
- package/results/res_sweep_echo_b300.json +129 -0
- package/results/res_sweep_final_b300.json +153 -0
- package/results/res_sweep_glm_b300.json +153 -0
- package/results/res_techo.json +29 -0
- package/results/res_tgsuf.json +21 -0
- package/results/res_tjac.json +17 -0
- package/results/res_tonline_jac.json +13 -0
package/p27/t_jac.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Jacobi fixed-point chain exactness smoke test on tiny-random GLM."""
|
|
2
|
+
import torch
|
|
3
|
+
|
|
4
|
+
def main(n_gen=40, seed=0):
|
|
5
|
+
import t_glm
|
|
6
|
+
import pmodel
|
|
7
|
+
import spec as SP
|
|
8
|
+
path = t_glm.snap("tiny-random/glm-5.3")
|
|
9
|
+
m = pmodel.PModel(path, B=1, smax=256, verbose=False)
|
|
10
|
+
ids = torch.randint(100, m.V - 100, (36,), generator=torch.Generator().manual_seed(seed)).cuda().tolist()
|
|
11
|
+
R = {}
|
|
12
|
+
for T in (0.0, 1.0):
|
|
13
|
+
outs = {}
|
|
14
|
+
for J in (0, 6):
|
|
15
|
+
eng = SP.SpecEngine(m, D=2 if m.mtp else 0, C=4, J=J, T=T, uid=911 + int(T), SN=3)
|
|
16
|
+
eng.capture(use_graph=True)
|
|
17
|
+
m.reset()
|
|
18
|
+
outs[J] = eng.generate(ids, n_gen)
|
|
19
|
+
R[f"T{T}_J{J}_tok_per_pass"] = outs[J]["tok_per_pass"]
|
|
20
|
+
R[f"T{T}_exact"] = outs[0]["out"] == outs[6]["out"]
|
|
21
|
+
R["summary"] = dict(R)
|
|
22
|
+
return R
|
package/p27/t_moebm.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"""Expert padding-block-size sweep for grouped fp8 MoE GEMM."""
|
|
2
|
+
import torch
|
|
3
|
+
import quant as Q
|
|
4
|
+
|
|
5
|
+
def bench(fn,n=100):
|
|
6
|
+
for _ in range(5): fn()
|
|
7
|
+
torch.cuda.synchronize(); a=torch.cuda.Event(True); b=torch.cuda.Event(True); a.record()
|
|
8
|
+
for _ in range(n): fn()
|
|
9
|
+
b.record(); torch.cuda.synchronize(); return a.elapsed_time(b)/n
|
|
10
|
+
|
|
11
|
+
def one(R,N,K,BM):
|
|
12
|
+
torch.manual_seed(0); E=256; k=8; qn=qk=128
|
|
13
|
+
a=torch.randn(R,K,device='cuda',dtype=torch.bfloat16)
|
|
14
|
+
w=(torch.randn(E,N,K,device='cuda')*.02).to(torch.float8_e4m3fn)
|
|
15
|
+
s=torch.rand(E,N//qn,K//qk,device='cuda')*.01+.001
|
|
16
|
+
g=torch.Generator().manual_seed(R)
|
|
17
|
+
idx=torch.stack([torch.randperm(E,generator=g)[:k] for _ in range(R)]).cuda()
|
|
18
|
+
pr,be,po=Q.moe_align_torch(idx,E,0,BM)
|
|
19
|
+
fn=lambda: Q.moe_fp8_gemm(a,w,s,qn,qk,pr,be,BM)
|
|
20
|
+
try:
|
|
21
|
+
y=fn(); return {'ms':bench(fn),'p':len(pr),'err':None}
|
|
22
|
+
except Exception as e: return {'ms':None,'p':len(pr),'err':repr(e)[:200]}
|
|
23
|
+
|
|
24
|
+
def main():
|
|
25
|
+
rows=[]
|
|
26
|
+
for R in (1,12,64):
|
|
27
|
+
for N,K in ((512,6144),(6144,256)):
|
|
28
|
+
for BM in (1,2,4,8,16,32):
|
|
29
|
+
r=one(R,N,K,BM); r.update(R=R,N=N,K=K,BM=BM); rows.append(r)
|
|
30
|
+
return {'rows':rows}
|
package/p27/t_nccl.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
"""NCCL all-reduce microbenchmark inside CUDA graphs, matching P27 decode shapes."""
|
|
2
|
+
import time
|
|
3
|
+
import torch
|
|
4
|
+
import torch.distributed as dist
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def one(shape, dtype, n=200, graph=True):
|
|
8
|
+
x = torch.randn(*shape, device='cuda', dtype=dtype)
|
|
9
|
+
def body():
|
|
10
|
+
dist.all_reduce(x)
|
|
11
|
+
for _ in range(5): body()
|
|
12
|
+
torch.cuda.synchronize()
|
|
13
|
+
if graph:
|
|
14
|
+
g = torch.cuda.CUDAGraph()
|
|
15
|
+
s = torch.cuda.Stream(); s.wait_stream(torch.cuda.current_stream())
|
|
16
|
+
with torch.cuda.stream(s):
|
|
17
|
+
for _ in range(3): body()
|
|
18
|
+
torch.cuda.current_stream().wait_stream(s)
|
|
19
|
+
with torch.cuda.graph(g):
|
|
20
|
+
body()
|
|
21
|
+
fn = g.replay
|
|
22
|
+
else:
|
|
23
|
+
fn = body
|
|
24
|
+
dist.barrier(); torch.cuda.synchronize()
|
|
25
|
+
t0 = time.perf_counter()
|
|
26
|
+
for _ in range(n): fn()
|
|
27
|
+
torch.cuda.synchronize(); dist.barrier()
|
|
28
|
+
return (time.perf_counter() - t0) / n * 1000
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def main(rank=0, world=1):
|
|
32
|
+
rows = []
|
|
33
|
+
for R in (1, 12, 64):
|
|
34
|
+
for dt in (torch.bfloat16, torch.float32):
|
|
35
|
+
rows.append({'R': R, 'dtype': str(dt).split('.')[-1], 'ms_graph': one((R, 6144), dt), 'ms_eager': one((R, 6144), dt, graph=False)})
|
|
36
|
+
return {'rows': rows}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"""Online-tree Jacobi/suffix shape-switch smoke test on tiny-random GLM."""
|
|
2
|
+
import torch
|
|
3
|
+
|
|
4
|
+
def main(n_gen=32, seed=1):
|
|
5
|
+
import t_glm
|
|
6
|
+
import pmodel
|
|
7
|
+
import spec as SP
|
|
8
|
+
path = t_glm.snap("tiny-random/glm-5.3")
|
|
9
|
+
m = pmodel.PModel(path, B=1, smax=256, verbose=False)
|
|
10
|
+
ids = torch.randint(100, m.V - 100, (28,), generator=torch.Generator().manual_seed(seed)).cuda().tolist()
|
|
11
|
+
R = {}
|
|
12
|
+
for T in (0.0, 1.0):
|
|
13
|
+
fixed = SP.SpecEngine(m, D=2 if m.mtp else 0, C=4, J=3, T=T, uid=1200 + int(T), SN=3,
|
|
14
|
+
in_graph_suffix=True)
|
|
15
|
+
fixed.capture(use_graph=True)
|
|
16
|
+
m.reset()
|
|
17
|
+
ref = fixed.generate(ids, n_gen)["out"]
|
|
18
|
+
same = SP.OnlineTree(m, Ds=(2,), Ws=(1,), C=4, Cs=(4,), J=3, T=T, uid=1200 + int(T), SN=3,
|
|
19
|
+
in_graph_suffix=True, start=(2, 1))
|
|
20
|
+
same.prepare(ids)
|
|
21
|
+
m.reset()
|
|
22
|
+
out_same = same.generate(ids, n_gen)["out"]
|
|
23
|
+
multi = SP.OnlineTree(m, Ds=(1, 2), Ws=(1,), C=4, Cs=(0, 4), J=3, T=T, uid=1200 + int(T), SN=3,
|
|
24
|
+
in_graph_suffix=True, start=(1, 1))
|
|
25
|
+
multi.prepare(ids)
|
|
26
|
+
m.reset()
|
|
27
|
+
out_multi = multi.generate(ids, n_gen)
|
|
28
|
+
R[f"T{T}_same_shape_exact"] = out_same == ref
|
|
29
|
+
R[f"T{T}_multi_shape_completed"] = len(out_multi["out"]) == n_gen and out_multi["passes"] > 0
|
|
30
|
+
R["summary"] = dict(R)
|
|
31
|
+
return R
|
package/p27/t_probe.py
ADDED
package/p27/t_router.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import torch, torch.nn.functional as F
|
|
2
|
+
|
|
3
|
+
def gb(fn,n=200):
|
|
4
|
+
for _ in range(3): fn()
|
|
5
|
+
torch.cuda.synchronize(); g=torch.cuda.CUDAGraph()
|
|
6
|
+
with torch.cuda.graph(g): fn()
|
|
7
|
+
torch.cuda.synchronize(); a=torch.cuda.Event(True); b=torch.cuda.Event(True); a.record()
|
|
8
|
+
for _ in range(n): g.replay()
|
|
9
|
+
b.record(); torch.cuda.synchronize(); return a.elapsed_time(b)/n
|
|
10
|
+
|
|
11
|
+
def main():
|
|
12
|
+
import quant as Q
|
|
13
|
+
rows=[]
|
|
14
|
+
for R in (1,12,64):
|
|
15
|
+
torch.manual_seed(R); E,K,k=256,6144,8
|
|
16
|
+
x=torch.randn(R,K,device='cuda',dtype=torch.bfloat16)
|
|
17
|
+
wr=(torch.randn(E,K,device='cuda')*.02).bfloat16()
|
|
18
|
+
bias=torch.randn(E,device='cuda')
|
|
19
|
+
def ref():
|
|
20
|
+
z=F.linear(x.float(),wr.float()); sc=torch.sigmoid(z); ch=sc+bias[None]
|
|
21
|
+
ix=ch.topk(k,-1,sorted=False)[1]; w=sc.gather(1,ix); w=w/(w.sum(-1,keepdim=True)+1e-20); return ix,w*2.5
|
|
22
|
+
try:
|
|
23
|
+
ri,rw=ref(); ii,iw=Q.router8(x,wr,bias,k,2.5)
|
|
24
|
+
agree=(ri.sort(1)[0]==ii.sort(1)[0]).float().mean().item()
|
|
25
|
+
rows.append({'R':R,'agree':agree,'wdiff':(rw.gather(1,ri.argsort(1)).float()-iw.gather(1,ii.argsort(1)).float()).abs().max().item(),
|
|
26
|
+
'ref_ms':gb(ref),'fused_ms':gb(lambda:Q.router8(x,wr,bias,k,2.5))})
|
|
27
|
+
except Exception as e: rows.append({'R':R,'err':repr(e)})
|
|
28
|
+
return {'rows':rows}
|
package/p27/t_symm.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"""Symmetric-memory one-shot all-reduce microbenchmark vs NCCL."""
|
|
2
|
+
import time
|
|
3
|
+
import torch
|
|
4
|
+
import torch.distributed as dist
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def timeit(fn,n=200):
|
|
8
|
+
for _ in range(5): fn()
|
|
9
|
+
torch.cuda.synchronize(); dist.barrier()
|
|
10
|
+
t0=time.perf_counter()
|
|
11
|
+
for _ in range(n): fn()
|
|
12
|
+
torch.cuda.synchronize(); dist.barrier()
|
|
13
|
+
return (time.perf_counter()-t0)/n*1000
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def main(rank=0,world=1):
|
|
17
|
+
import torch.distributed._symmetric_memory as sm
|
|
18
|
+
gn=dist.group.WORLD.group_name
|
|
19
|
+
rows=[]
|
|
20
|
+
for R in (1,12,64):
|
|
21
|
+
for dt in (torch.bfloat16,torch.float32):
|
|
22
|
+
row={'R':R,'dtype':str(dt).split('.')[-1]}
|
|
23
|
+
x=torch.randn(R,6144,device='cuda',dtype=dt)
|
|
24
|
+
row['nccl_ms']=timeit(lambda: dist.all_reduce(x))
|
|
25
|
+
try:
|
|
26
|
+
pool=sm.get_mem_pool(f'cuda:{rank}')
|
|
27
|
+
with torch.cuda.use_mem_pool(pool):
|
|
28
|
+
y=torch.randn(R,6144,device='cuda',dtype=dt)
|
|
29
|
+
x2=torch.randn(R,6144,device='cuda',dtype=dt)
|
|
30
|
+
def osa():
|
|
31
|
+
torch.ops.symm_mem.one_shot_all_reduce_copy(y,x2,'sum',gn)
|
|
32
|
+
row['symm_ms']=timeit(osa)
|
|
33
|
+
torch.manual_seed(1000+rank)
|
|
34
|
+
x2.copy_(torch.randn(R,6144,device='cuda',dtype=dt))
|
|
35
|
+
z=torch.ops.symm_mem.one_shot_all_reduce_copy(y,x2,'sum',gn)
|
|
36
|
+
row['out_shape']=list(z.shape)
|
|
37
|
+
ref=x2.clone(); dist.all_reduce(ref)
|
|
38
|
+
row['maxdiff']=(z.float()-ref.float()).abs().max().item()
|
|
39
|
+
try:
|
|
40
|
+
for _ in range(2): osa()
|
|
41
|
+
torch.cuda.synchronize(); dist.barrier()
|
|
42
|
+
gg=torch.cuda.CUDAGraph()
|
|
43
|
+
with torch.cuda.graph(gg): osa()
|
|
44
|
+
def rg(): gg.replay()
|
|
45
|
+
row['symm_graph_ms']=timeit(rg)
|
|
46
|
+
except Exception as e: row['graph_error']=repr(e)[:240]
|
|
47
|
+
except Exception as e:
|
|
48
|
+
row['symm_error']=repr(e)
|
|
49
|
+
rows.append(row)
|
|
50
|
+
return {'rows':rows,'nvshmem':__import__('torch.distributed._symmetric_memory').distributed._symmetric_memory.is_nvshmem_available()}
|
package/p27/t_tiny.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"""Dev test on tiny-random/kimi-k3.1-pro (one GPU): our blocks vs the HF reference modeling in fp32.
|
|
2
|
+
1 mxfp4 decode == compressed-tensors decode (bit exact)
|
|
3
|
+
2 fp32 HF logits vs our bf16 engine: prefill, plain decode (tree N=1), chain verify (tree N=5), SpecEngine greedy
|
|
4
|
+
3 fla chunk_kda prefill == path-walk prefill (state layout check)
|
|
5
|
+
"""
|
|
6
|
+
import glob
|
|
7
|
+
import os
|
|
8
|
+
import time
|
|
9
|
+
|
|
10
|
+
import torch
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def snap(repo):
|
|
14
|
+
d = glob.glob(f"/vol/hf/hub/models--{repo.replace('/', '--')}/snapshots/*")
|
|
15
|
+
return sorted(d)[0]
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def main(repo="tiny-random/kimi-k3.1-pro", T=40, n_gen=24, seed=0, modeling_src=None):
|
|
19
|
+
import pmodel
|
|
20
|
+
import pblocks as PB
|
|
21
|
+
import pref
|
|
22
|
+
import quant as Q
|
|
23
|
+
from ctx import RowCtx, chain
|
|
24
|
+
import spec as SP
|
|
25
|
+
path = snap(repo)
|
|
26
|
+
R = {"path": path, "device": torch.cuda.get_device_name()}
|
|
27
|
+
from adapter import WeightIndex
|
|
28
|
+
W = WeightIndex(path)
|
|
29
|
+
# 1. mxfp4 decode
|
|
30
|
+
k = [x for x in W.map if x.endswith("experts.0.w1.weight_packed")][0]
|
|
31
|
+
p, s = W.get(k), W.get(k.replace("_packed", "_scale"))
|
|
32
|
+
mine = Q.mxfp4_dequant(p, s, torch.float32)
|
|
33
|
+
try:
|
|
34
|
+
from compressed_tensors.compressors.quantized_compressors.fp4_quantized import unpack_fp4_from_uint8
|
|
35
|
+
ref = unpack_fp4_from_uint8(p, p.shape[0], p.shape[1] * 2, dtype=torch.float32)
|
|
36
|
+
sc = Q.e8m0_to_f32(s).repeat_interleave(32, -1)
|
|
37
|
+
R["mxfp4_vs_ct_maxdiff"] = float((ref * sc - mine).abs().max())
|
|
38
|
+
except Exception as e:
|
|
39
|
+
R["mxfp4_vs_ct"] = repr(e)[:300]
|
|
40
|
+
R["mxfp4_bf16_exact"] = bool((mine.to(torch.bfloat16).float() == mine).all())
|
|
41
|
+
# 2. reference
|
|
42
|
+
ms = modeling_src or path
|
|
43
|
+
t0 = time.time()
|
|
44
|
+
ref, info = pref.full_ref(path, ms)
|
|
45
|
+
R["ref_load"] = info
|
|
46
|
+
g = torch.Generator().manual_seed(seed)
|
|
47
|
+
V = ref.config.vocab_size
|
|
48
|
+
ids = torch.randint(100, V - 100, (T + n_gen,), generator=g).cuda()
|
|
49
|
+
zr = pref.ref_logits(ref, ids) # (T+n, V) fp32
|
|
50
|
+
R["ref_s"] = time.time() - t0
|
|
51
|
+
# ours
|
|
52
|
+
m = pmodel.PModel(path, B=1, smax=256)
|
|
53
|
+
h = m.prefill(ids[:T], b=0)
|
|
54
|
+
z = m.logits(h).float()
|
|
55
|
+
d = (z - zr[:T]).abs()
|
|
56
|
+
R["prefill_maxdiff"] = float(d.max())
|
|
57
|
+
R["prefill_argmax_agree"] = float((z.argmax(-1) == zr[:T].argmax(-1)).float().mean())
|
|
58
|
+
R["prefill_gap_max"] = float(pref.gaps(zr[:T], z.argmax(-1)).max())
|
|
59
|
+
# plain decode: tree N=1 rows, teacher forced
|
|
60
|
+
one = chain(1)
|
|
61
|
+
lens = torch.full((1,), T, dtype=torch.int32, device="cuda")
|
|
62
|
+
zs = []
|
|
63
|
+
for i in range(n_gen):
|
|
64
|
+
ctx = RowCtx.tree(one, lens, 1)
|
|
65
|
+
hh = m.tree(ids[T + i:T + i + 1].view(1, 1), ctx)
|
|
66
|
+
zs.append(m.logits(hh).float())
|
|
67
|
+
ctx.set_accept(torch.zeros(1, dtype=torch.long, device="cuda"))
|
|
68
|
+
m.commit(ctx)
|
|
69
|
+
lens += 1
|
|
70
|
+
zd = torch.cat(zs)
|
|
71
|
+
R["decode_maxdiff"] = float((zd - zr[T:T + n_gen]).abs().max())
|
|
72
|
+
R["decode_argmax_agree"] = float((zd.argmax(-1) == zr[T:T + n_gen].argmax(-1)).float().mean())
|
|
73
|
+
# chain verify of 5 rows from a fresh prefill: rows = ids[T..T+4]
|
|
74
|
+
m.reset()
|
|
75
|
+
m.prefill(ids[:T], b=0)
|
|
76
|
+
c5 = chain(5)
|
|
77
|
+
lens = torch.full((1,), T, dtype=torch.int32, device="cuda")
|
|
78
|
+
ctx = RowCtx.tree(c5, lens, 1)
|
|
79
|
+
hh = m.tree(ids[T:T + 5].view(1, 5), ctx)
|
|
80
|
+
z5 = m.logits(hh).float()
|
|
81
|
+
R["chain5_maxdiff"] = float((z5 - zr[T:T + 5]).abs().max())
|
|
82
|
+
# accept 3 rows, then continue with N=1 and compare to the reference at T+3
|
|
83
|
+
ctx.set_accept(torch.tensor([2], device="cuda"))
|
|
84
|
+
m.commit(ctx)
|
|
85
|
+
lens += 3
|
|
86
|
+
ctx = RowCtx.tree(one, lens, 1)
|
|
87
|
+
hh = m.tree(ids[T + 3:T + 4].view(1, 1), ctx)
|
|
88
|
+
R["after_commit3_maxdiff"] = float((m.logits(hh).float() - zr[T + 3:T + 4]).abs().max())
|
|
89
|
+
# 3. fla vs path-walk prefill
|
|
90
|
+
try:
|
|
91
|
+
m.reset()
|
|
92
|
+
PB.PREFILL_FLA = True
|
|
93
|
+
h1 = m.prefill(ids[:T], b=0)
|
|
94
|
+
S1 = [L.mix.S.clone() for L in m.layers if hasattr(L.mix, "S")]
|
|
95
|
+
m.reset()
|
|
96
|
+
PB.PREFILL_FLA = False
|
|
97
|
+
h2 = m.prefill(ids[:T], b=0)
|
|
98
|
+
S2 = [L.mix.S.clone() for L in m.layers if hasattr(L.mix, "S")]
|
|
99
|
+
R["fla_vs_walk_hidden"] = float((h1.float() - h2.float()).abs().max())
|
|
100
|
+
R["fla_vs_walk_state"] = max(float((a - b).abs().max()) for a, b in zip(S1, S2))
|
|
101
|
+
R["fla_vs_walk_stateT"] = max(float((a - b.transpose(-1, -2)).abs().max()) for a, b in zip(S1, S2))
|
|
102
|
+
PB.PREFILL_FLA = True
|
|
103
|
+
except Exception as e:
|
|
104
|
+
R["fla_err"] = repr(e)[:400]
|
|
105
|
+
# 4. SpecEngine greedy (suffix chain only; no MTP head) vs reference greedy continuation
|
|
106
|
+
m.reset()
|
|
107
|
+
PB.PREFILL_FLA = False
|
|
108
|
+
eng = SP.SpecEngine(m, D=0, C=4, T=0.0)
|
|
109
|
+
out = eng.generate(ids[:T].tolist(), n_gen)
|
|
110
|
+
o = torch.tensor(out["out"], device="cuda")
|
|
111
|
+
full = torch.cat([ids[:T], o])
|
|
112
|
+
zr2 = pref.ref_logits(ref, full)
|
|
113
|
+
gp = pref.gaps(zr2[T - 1:T - 1 + n_gen], o)
|
|
114
|
+
R["spec_greedy"] = {"tok_per_pass": out["tok_per_pass"], "gap_max": float(gp.max()), "n": int(o.numel())}
|
|
115
|
+
R["summary"] = {k: v for k, v in R.items() if k not in ("ref_load",)}
|
|
116
|
+
return R
|
package/package.json
CHANGED
|
@@ -1,6 +1,36 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quantuminfer",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.1.1",
|
|
4
|
+
"description": "Installer and CLI bootstrap for quantumInfer, a quantum-inspired exact speculative LLM inference research engine",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"quantuminfer": "./bin/quantuminfer.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"bin",
|
|
11
|
+
"engine",
|
|
12
|
+
"p27",
|
|
13
|
+
"c27",
|
|
14
|
+
"data",
|
|
15
|
+
"results",
|
|
16
|
+
"README.md",
|
|
17
|
+
"LICENSE"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"llm",
|
|
21
|
+
"inference",
|
|
22
|
+
"speculative-decoding",
|
|
23
|
+
"moe",
|
|
24
|
+
"fp8",
|
|
25
|
+
"cuda",
|
|
26
|
+
"modal"
|
|
27
|
+
],
|
|
28
|
+
"repository": {
|
|
29
|
+
"type": "git",
|
|
30
|
+
"url": "https://github.com/Knihalani/quantumInfer.git"
|
|
31
|
+
},
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"engines": {
|
|
34
|
+
"node": ">=18"
|
|
35
|
+
}
|
|
36
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# quantumInfer GLM-5.3 benchmark notes
|
|
2
|
+
|
|
3
|
+
## Quantum-inspired execution model
|
|
4
|
+
|
|
5
|
+
This is a classical accelerator inspired by quantum measurement, not a quantum-hardware simulator. Target-model logits are treated as measurement amplitudes/scores; a deterministic Gumbel measurement record converts them into reproducible token outcomes. MTP heads, suffix chains, and echo only propose branches. The target model performs the authoritative measurement at every accepted prefix, so speculative execution changes latency but not the model distribution under a fixed numerical kernel configuration.
|
|
6
|
+
|
|
7
|
+
## Measured quantumInfer results
|
|
8
|
+
|
|
9
|
+
All quantumInfer numbers are target-measured decode results: proposals only affect speed, while every emitted token is measured by the target model at its own prefix. Measurements use the FP8 checkpoint on Modal, 8x NVIDIA B300, tensor parallelism plus expert relayout, CUDA graph replay, greedy decoding, and 128-256 generated tokens. They are single-user research-engine numbers, not continuous-batching serving numbers.
|
|
10
|
+
|
|
11
|
+
| configuration | code tok/s | code tokens/pass | chat tok/s | chat tokens/pass |
|
|
12
|
+
|---|---:|---:|---:|---:|
|
|
13
|
+
| initial integrated baseline, 8x B200, D3/C8 | 95.7 | 4.72 | 69.8 | 3.45 |
|
|
14
|
+
| first optimized, 8x B200, D3/C8 | 87.3 | 2.93 | 98.9 | 3.31 |
|
|
15
|
+
| optimized, 8x B300, D3/C8 | 113.4 | 3.40 | 108.4 | 3.27 |
|
|
16
|
+
| tuned/wide tree sweep, 8x B300, D3/C32 | 169.2 | 6.10 | 103.5 | 3.76 |
|
|
17
|
+
| tuned/echo sweep, 8x B300, D3/C16/E8/EW3 | 151.6 | 5.57 | 99.1 | 3.66 |
|
|
18
|
+
| bounded online tree before rank-consistency fix, 8x B300 | 78.9 | 2.93 | 88.6 | 3.31 |
|
|
19
|
+
| fixed bounded online tree, 8x B300, adaptive C8/C32 + echo/no-echo | 139.2 | 5.20 | 91.1 | 3.36 |
|
|
20
|
+
| final repeated, 8x B300, D3/C32, fused router | 144.6 | 5.20 | 94.2 | 3.40 |
|
|
21
|
+
| repeat-loop case, 8x B300, D3/C32/W3 | 265.4 | 9.81 | 95.9 | 3.59 |
|
|
22
|
+
|
|
23
|
+
The final authoritative repeated benchmark is `res_glm_final_c32_b300.json`: code 144.6 tok/s at 5.20 target-verified tokens/pass; chat 94.2 tok/s at 3.40 tokens/pass; zero runtime errors over three timed repetitions per case.
|
|
24
|
+
|
|
25
|
+
### Direct-decode control and shape search
|
|
26
|
+
|
|
27
|
+
A same-model control with no speculative rows ran at 53.9 tok/s code and 53.7 tok/s chat on 8x B300. In the final shape-search job, D3/C32 ran 93.2/104.8 tok/s, D3/C48 86.3/100.2, and hybrid echo variants were slower (78.9-88.6 code, 77.3-82.8 chat). These shape-search numbers are 128-token single-pass sweep measurements and are not directly comparable to the authoritative 256-token repeated benchmark above.
|
|
28
|
+
|
|
29
|
+
### Non-degenerate long-context text controls
|
|
30
|
+
|
|
31
|
+
512-token continuation prompts, 256 generated tokens, D3/C32/W1:
|
|
32
|
+
|
|
33
|
+
| prompt source | tok/s | target-verified tokens/pass | tail periodicity |
|
|
34
|
+
|---|---:|---:|---:|
|
|
35
|
+
| WikiText | 91.1 | 3.40 | 0.04 |
|
|
36
|
+
| Shakespeare | 68.1 | 2.52 | 0.04 |
|
|
37
|
+
| WikiText, W3 | 88.6 | 3.45 | n/a |
|
|
38
|
+
| Shakespeare, W3 | 73.5 | 2.83 | n/a |
|
|
39
|
+
|
|
40
|
+
### Repeat-loop caveat
|
|
41
|
+
|
|
42
|
+
The D3/C32/W3 code result is real target-model decode but not representative general throughput: the greedy output enters a perfect periodic token loop, which suffix/MTP branching is exceptionally good at verifying. Its chat result is non-degenerate. The benchmark harness now reports `tail_periodicity` for every saved stream so repeat-loop artefacts are explicit rather than hidden.
|
|
43
|
+
|
|
44
|
+
### Plain-decode and static-batch controls
|
|
45
|
+
|
|
46
|
+
The matched no-speculation single-user control is 50.3 tok/s on WikiText and 50.2 tok/s on Shakespeare, so D3/C32/W1 is 1.81x/1.36x faster on those non-degenerate controls; W3 is 1.76x/1.46x. Static exact-sampling batch decode (random 32-token prompts, 128 generated tokens, no continuous batching) reaches 175-176 aggregate tok/s at B4, 305-308 at B8, and 530-531 at B16 across the 8-GPU node.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
### Fused-candidate multi-shape comparison (2026-11-28 evening)
|
|
50
|
+
|
|
51
|
+
One checkpoint load, 8x B300, exact greedy decode, low tail periodicity in every stream:
|
|
52
|
+
|
|
53
|
+
| configuration | code tok/s | chat tok/s | interpretation |
|
|
54
|
+
|---|---:|---:|---|
|
|
55
|
+
| D3/C32/W1 | 148.3 (5.20 tok/pass) | 96.6 (3.40) | long suffix chain wins repetitive code |
|
|
56
|
+
| D4/C8/W3 + 65,536-token draft vocab | 106.3 (3.36) | 116.7 (3.70) | wider/deeper MTP wins chat and cuts pass cost |
|
|
57
|
+
| same + in-graph echo E2 | 103.9 (3.31) | 115.1 (3.70) | echo costs only ~0.4 ms/pass after graph capture, but adds no greedy acceptance here |
|
|
58
|
+
|
|
59
|
+
The important discovery is that no single fixed tree is globally best: code wants long suffix chains, chat wants wider/deeper MTP branching. This is exactly the regime the online tree rule is meant to exploit. In-graph echo reduced the marginal echo cost from host-visible enough to erase its acceptance gain (73.2 vs 77.7 tok/s T=1 chat) to roughly 0.4 ms/pass.
|
|
60
|
+
|
|
61
|
+
## Cross-round research discoveries
|
|
62
|
+
|
|
63
|
+
These are broader quantum-inspired inference findings that motivated the GLM design; they were measured primarily on Qwen3-0.6B/8B unless explicitly marked GLM-5.3:
|
|
64
|
+
|
|
65
|
+
- Deterministic Gumbel coupling through the measurement record came within 3-6% of the optimal coupling for tested proposers. In other words, rejection sampling or another exact verifier could not materially beat the record verifier using the same proposer.
|
|
66
|
+
- Exact T=1 speculation has a measured ceiling: on unpredictable text, no untrained proposer reached even 3.2x the weight-read roofline. Full-size quantized copies propose well but cost too much; small drafters are cheap but agree too little.
|
|
67
|
+
- Exact weights have an information floor: measured bf16 weight entropy was about 10.46-10.50 bits/weight, and exact low-rank or context coding did not break that floor. A separate engine nevertheless stored only a lossless ~12-bit form and decoded it directly into tensor-core fragments without materializing bf16 weights.
|
|
68
|
+
- Energy did not follow FLOPs. Speculative engines sometimes executed 1.7-4.8x more FLOPs per emitted token yet used fewer joules, because energy tracked weight reads and elapsed time more closely than arithmetic count.
|
|
69
|
+
- Exact KV state had a measured lossless floor around 66-69% of bf16 bytes; recompute and lossy-proposal routes did not yield a 10x exact-memory win for 128-token turns.
|
|
70
|
+
- A research cold-start engine for Qwen3-8B reached first token in 1.46s median from an empty container using a static CUDA binary and streamed lossless weights, versus 28.9s for the fastest measured vLLM cold-start configuration. That design is not yet ported to GLM-5.3.
|
|
71
|
+
- On the same Modal GLM-5.3 checkpoint volume, the custom parallel loader initialized the multi-shape quantumInfer benchmark in 128.7s, while vLLM 0.34.0 reported 873.0s just to load weights (before warmup): about 6.8x faster cold weight loading for quantumInfer.
|
|
72
|
+
- On GLM-5.3 itself, verify-pass cost is nearly flat for modest tree widths but not free at 32+ rows: workload-dependent tree shape selection matters more than simply maximizing speculative width.
|
|
73
|
+
|
|
74
|
+
## Direct vLLM competitor measurement
|
|
75
|
+
|
|
76
|
+
Same GLM-5.3 checkpoint, same Modal volume, same 8x NVIDIA B300 node shape, same code/chat single-user harness, vLLM 0.34.0 with TP8, MTP5 speculative decoding, and FP8 KV cache (the published vLLM recipe configuration; FP8 KV is lossy and favors vLLM):
|
|
77
|
+
|
|
78
|
+
| engine | code tok/s | chat tok/s | notes |
|
|
79
|
+
|---|---:|---:|---|
|
|
80
|
+
| quantumInfer best fixed/code shape | 148.3 | 96.6 | D3/C32, exact target-measured greedy |
|
|
81
|
+
| quantumInfer best chat shape | 106.3 | 116.7 | D4/C8/W3 + truncated draft vocab |
|
|
82
|
+
| vLLM 0.34.0 MTP5 FP8-KV | 525.5 | 344.1 | direct measurement, same harness |
|
|
83
|
+
|
|
84
|
+
Shape-specialized quantumInfer ratios against direct vLLM: 0.28x on code and 0.34x on chat. The fixed D3/C32 shape alone is 0.28x vLLM on code and 0.28x on chat. These are single-user research/decode numbers, not production continuous-batching throughput.
|
|
85
|
+
|
|
86
|
+
The decisive comparison is acceptance versus pass cost. quantumInfer matches or slightly exceeds vLLM's measured target-verified acceptance (5.20 versus 5.10 tokens/pass on code; 3.70 versus 3.47 on chat with the best chat shape), but vLLM executes a pass in roughly 9.7-10.1ms versus roughly 31.7-35.2ms for the research engine. In other words, acceptance is no longer the bottleneck; production kernel, collective, and runtime efficiency is. The highest-value follow-up is therefore to port the measurement-record tree proposers onto a vLLM-class optimized runtime rather than to widen the speculative tree blindly.
|
|
87
|
+
|
|
88
|
+
### Full-scale Jacobi T=1 result
|
|
89
|
+
|
|
90
|
+
D3/C16/W1 exact T=1 chat on 8x B300: J8 measured 87.7 tok/s at 2.87 tokens/pass versus the same-shape no-Jacobi control at 77.7 tok/s and 2.50 tokens/pass. Speed ratio 1.13x. Artifacts: `res_glm_t1_j8_b300.json` and `res_glm_t1_e0_b300.json`.
|
|
91
|
+
|
|
92
|
+
## External competitor reference points
|
|
93
|
+
|
|
94
|
+
These are published serving measurements, not controlled same-harness comparisons:
|
|
95
|
+
|
|
96
|
+
- [InferenceX/SemiAnalysis GLM-5.3 on B200](https://inferencex.semianalysis.com/run/glm-5-3-on-b200), real-hardware AgentX concurrency sweep, 2026-10-22 to 2026-11-06:
|
|
97
|
+
|
|
98
|
+
| per-user interactivity target | aggregate tokens/s/GPU | best engine/precision |
|
|
99
|
+
|---:|---:|---|
|
|
100
|
+
| 50 tok/s | 13,575 | SGLang FP8 |
|
|
101
|
+
| 75 tok/s | 18,177 | Dynamo SGLang FP4 |
|
|
102
|
+
| 100 tok/s | 17,724 | Dynamo SGLang FP4 |
|
|
103
|
+
| 150 tok/s | 13,021 | Dynamo SGLang FP4 |
|
|
104
|
+
| 200 tok/s | 9,876 | Dynamo SGLang FP4 |
|
|
105
|
+
|
|
106
|
+
Peak measured throughput across all their configurations is 19,950 tokens/s/GPU. These are aggregate high-concurrency serving totals, so they are not numerically comparable to quantumInfer's single-user tok/s; the useful comparison is that quantumInfer's single-user decode speed is already in the 100-150 tok/s interactivity range, while its aggregate batching throughput is far below production serving systems.
|
|
107
|
+
- NVIDIA Dynamo GLM-5.3-Flash synthetic speculative benchmark: simulated acceptance length 2.5657; SGLang aggregated B200 reports 579.1 system output tok/s/GPU and 50.7 user output tok/s P50 at concurrency 56; GB200 disaggregated reports 619.7 system output tok/s/GPU and 80.1 user output tok/s P50 at concurrency 128.
|
|
108
|
+
|
|
109
|
+
These competitor numbers are high-concurrency serving totals, often FP4 or simulated-acceptance configurations. quantumInfer's current numbers are exact FP8 single-user decode across an 8-GPU node. Therefore quantumInfer should not yet be claimed as a serving-throughput winner; its current advantage is speculative-tree depth/acceptance research and exactness, while vLLM/SGLang/Dynamo remain far ahead as production serving systems.
|
|
110
|
+
|
|
111
|
+
## Integration audit
|
|
112
|
+
|
|
113
|
+
Integrated into the active GLM-5.3 path:
|
|
114
|
+
|
|
115
|
+
1. Target-exact speculative verification and the deterministic 23-bit Gumbel measurement record, including the alias-free sequence/position record id.
|
|
116
|
+
2. CUDA-graph replay of the whole speculative tree pass, including target measurement, MTP draft propagation, and acceptance-dependent extraction.
|
|
117
|
+
3. GLM multi-token prediction heads, sibling branching, and vocabulary-truncated draft projection with the tensor-parallel row-order fix.
|
|
118
|
+
4. Whole-context suffix chains with loop extrapolation, plus the new in-graph tensor-history suffix scan.
|
|
119
|
+
5. Amplitude-echo proposals, fused Triton Gumbel top-k candidate generation, and the new in-graph echo path.
|
|
120
|
+
6. Adaptive online tree selection over depth, sibling width, suffix length, and echo width, with shape-switch state handoff.
|
|
121
|
+
7. FP8 block-dequantized tensor-core GEMM, split-K FP8 GEMM, and exact scale-per-block dequantization semantics.
|
|
122
|
+
8. Capacity-free grouped MoE dispatch/align, parallel expert GEMM, fused weighted expert combine, and fused scaled-sigmoid routing.
|
|
123
|
+
9. Mixed MLA attention fusion, TP/EP expert relayout, vocab-sharded LM head with gathered logits, and symmetric-memory one-shot allreduce.
|
|
124
|
+
10. Static exact-sampling batching measurements through the same measurement record.
|
|
125
|
+
|
|
126
|
+
Evaluated but not enabled by default:
|
|
127
|
+
|
|
128
|
+
- Echo is exact and now nearly free structurally, but full-scale measurements remain slightly negative in the current GLM shape: T=1 host echo 73.2 tok/s versus 77.7 without echo; in-graph greedy echo 103.9/115.1 versus 106.3/116.7 without echo. It stays optional rather than being hidden overhead.
|
|
129
|
+
- Wider MTP branching is workload-dependent: W3 is the best chat shape measured, while long suffix chains are better for repetitive code/text.
|
|
130
|
+
- The 265 tok/s repeat-loop result is a real target-model stream but is excluded from headline claims because GLM entered a perfect periodic loop.
|
|
131
|
+
|
|
132
|
+
Not yet ported to GLM-5.3:
|
|
133
|
+
|
|
134
|
+
- Jacobi fixed-point chains are present in the core engine and exposed in both fixed and online GLM benchmark harnesses. Tiny-random GLM exactness validation passes at greedy and T=1, including same-shape online-tree switching; in that smoke test J6 raised T=1 acceptance from 2.17 to 3.90 tokens/pass while preserving the exact output stream. Full-scale GLM T=1 measurement is the remaining validation step. Earlier 8B evidence showed roughly +10-12% at exact T=1 but little or no greedy gain. Trajectory n-gram pools remain a follow-up because whole-context suffix chains already cover much of the same greedy-text structure.
|
|
135
|
+
- Many-worlds shared-prompt batching and Collapse-style dynamic batch removal. They are serving/workload machinery rather than single-user decode innovations.
|
|
136
|
+
- Dedicated-stream symmetric-memory allreduce. The multi-stream warning remains unresolved, and the unvalidated experiment was deliberately reverted rather than integrated.
|
|
137
|
+
|
|
138
|
+
## Key innovations integrated
|
|
139
|
+
|
|
140
|
+
1. Target-exact tree verification: every emitted token is the target model measurement at its own prefix.
|
|
141
|
+
2. Multi-token prediction plus whole-context suffix chains in one CUDA-graph captured verification tree.
|
|
142
|
+
3. Wide 32+ row speculative trees enabled by replacing 32-bit ancestor masks with 64-bit masks.
|
|
143
|
+
4. Amplitude echo: target logits from the prior pass are re-measured under future deterministic record fields to create free proposals. Echo candidate extraction is now fused and captured in the CUDA graph instead of running as eager host-side full-vocab Gumbel arithmetic.
|
|
144
|
+
5. In-graph whole-context suffix drafting: the suffix n-gram lookup scans a compact token-history tensor inside the same CUDA graph. Tiny-model validation produces exactly the same greedy/T=1 streams and identical acceptance as the host-dictionary implementation.
|
|
145
|
+
6. Bounded OnlineTree adaptation over suffix/echo/MTP shapes, with measured per-shape graph cost and SPMD rank-consensus shape selection.
|
|
146
|
+
7. Parallel expert dispatch/align: exact CUDA-graph-safe expert sorting in about 8-12 us even for wide trees.
|
|
147
|
+
8. Split-K block-FP8 dense GEMMs with row-width-aware tile tuning and fused reduction.
|
|
148
|
+
9. Grouped block-FP8 MoE expert GEMMs plus fused routed-weight expert combine.
|
|
149
|
+
10. Mixed-format MLA projection fusion across FP8 row-concatenated q/kv/indexer projections.
|
|
150
|
+
11. NVSHMEM symmetric-memory one-shot tensor-parallel allreduce, about 10-11 us versus 23-40 us NCCL in decode-shaped microbenchmarks.
|
|
151
|
+
|
|
152
|
+
## Surprising discoveries
|
|
153
|
+
|
|
154
|
+
- Long suffix chains are extremely strong on repetitive code: D3/C32 reached 6.10 exact target-verified tokens/pass and 169 tok/s in the sweep.
|
|
155
|
+
- The same long suffix chain hurts chat because speculative row cost rises faster than acceptance; adaptivity is necessary in general.
|
|
156
|
+
- Echo helps code but is not universally positive once its extra rows and host fill cost are included.
|
|
157
|
+
- The first online rule was terrible because SPMD ranks could choose different shapes; after forcing rank-zero shape consensus it reached 139.2/91.1 tok/s, close to but still behind the best fixed shape. Distributed control-plane consistency was a hidden performance bug.
|
|
158
|
+
- CUDA-graph timing exposed operations that look cheap eagerly but dominate captured decode: dispatch alignment, reduction glue, and collective latency.
|
|
159
|
+
- Tiny reduction-order differences across tree widths can flip near-tie greedy tokens and lead to numerically valid but different token trajectories; speculative acceptance comparisons are therefore partly chaotic, not a clean scalar model property.
|
|
160
|
+
- The wide-tree blocker was a hidden 31-row ancestor bitmask limit, not a model-quality or speculative-decoding limit.
|