quantuminfer 0.0.0-stage → 0.1.0
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 +10 -4
- package/results/ANALYSIS.md +156 -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_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/engine/API.txt
ADDED
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
gpu/engine/ -- THE ENGINE CORE (owner: lane S27). API v0.1, published 2026-11-28 ~09:05 UTC. Stable names are marked
|
|
2
|
+
[STABLE]; anything else may still move (changes are logged at the end of this file). Never fork these files: plug in
|
|
3
|
+
from your own lane directory through the registries below. Requests to S27: write them in your STATUS.txt under
|
|
4
|
+
"REQUESTS TO CORE" (P27 already does) -- S27 reads them.
|
|
5
|
+
|
|
6
|
+
FILES
|
|
7
|
+
adapter.py HF config.json + safetensors index -> spec (dict). FAMILY table = facts not in config.json (data only).
|
|
8
|
+
blocks.py block registry (REGISTRY, @register(name)) + generic blocks: "attn", "gdn", "dense_glu"; rms(); Rope.
|
|
9
|
+
ctx.py TreeShape (static token tree), RowCtx (what a block sees for one call), chain(n).
|
|
10
|
+
model.py Model (decoder assembled from spec + registry), MTPHead.
|
|
11
|
+
kernels.py gdn_paths (gated delta rule along token paths: tree verify / commit / decode), tree_attn_merge.
|
|
12
|
+
record.py 23-bit measurement-record sampler (copy of exp_x1/record.py; gumbel_argmax, gumbel_ref).
|
|
13
|
+
spec.py SpecEngine: exact speculative decoding (MTP chain + whole-context suffix chain, tree verify, one CUDA
|
|
14
|
+
graph per pass), Suffix index.
|
|
15
|
+
__init__.py Engine(model_path, **features): the one entry point; FEATURES registry.
|
|
16
|
+
Import convention: put gpu/engine on sys.path (the Modal images mount it at /root/engine) and `import model, blocks`.
|
|
17
|
+
|
|
18
|
+
1. ENTRY POINT [STABLE]
|
|
19
|
+
from __init__ import Engine (or: sys.path.insert(0, ".../gpu/engine"); import engine as E)
|
|
20
|
+
eng = Engine(model_path, B=1, smax=8192, spec=True | {...}, precision="bf16" | "f32a", mask_ids=(), **features)
|
|
21
|
+
eng.generate(prompt_ids, n_out, T=0.0) -> {"out": [...], "decode_tok_s", "tok_per_pass", ...}
|
|
22
|
+
features: keyword -> options dict (or True). Each key must be registered in FEATURES (see 5). Built-in keys:
|
|
23
|
+
spec={"D": mtp_depth, "C": suffix_chain_len} (default rule: D=3 if the model has an MTP head, C=8)
|
|
24
|
+
The model is ALWAYS built by the adapter; nothing anywhere may branch on a model name.
|
|
25
|
+
|
|
26
|
+
2. SPEC (adapter.build_spec(path) -> (spec, WeightIndex)) [STABLE keys]
|
|
27
|
+
spec = {"d", "vocab", "eps", "norm_offset", "rope": {"theta", "rot", "hd"}, "prefix", "embed", "head",
|
|
28
|
+
"final_norm", "model_type", "max_pos",
|
|
29
|
+
"layers": [{"prefix", "norm1", "norm2", "mixer": {"type": <block name>, ...}, "mlp": {"type": ..., ...}}],
|
|
30
|
+
"mtp": {"fc", "norm_emb", "norm_hid", "norm", "layers": [same layer dicts]} (only if the model has one)}
|
|
31
|
+
Layer mixer type is inferred from the weight names (linear_attn.* -> "gdn", self_attn.* -> "attn"); MLP from
|
|
32
|
+
mlp.gate_proj (dense) -- MoE raises NotImplementedError until P27 registers a "moe" block and extends
|
|
33
|
+
adapter._mlp_spec (P27: add your inference rule in YOUR file and call adapter.register_rule(fn) -- see 6).
|
|
34
|
+
WeightIndex.get(name, device="cuda") -> tensor; .has(name); .map (name -> shard file).
|
|
35
|
+
Sharded load [STABLE signature, implemented]: WeightIndex.get(name, shard=(dim, rank, world)) returns the rank's
|
|
36
|
+
contiguous slice along dim (safetensors get_slice: only that slice is read).
|
|
37
|
+
|
|
38
|
+
3. BLOCK INTERFACE [STABLE]
|
|
39
|
+
A block = one reusable layer type, written once:
|
|
40
|
+
@blocks.register("myblock")
|
|
41
|
+
class MyBlock:
|
|
42
|
+
def __init__(self, s, W, g): # s = its spec dict, W = WeightIndex, g = {"eps", "norm_offset", "tp": ...}
|
|
43
|
+
def alloc(self, B, smax): # allocate ALL per-user state (KV, recurrent, conv...); B users, smax pos.
|
|
44
|
+
def reset(self, b=None): # zero user b's (or all) recurrent state in place (never reallocate:
|
|
45
|
+
# CUDA graphs hold pointers)
|
|
46
|
+
def state_bytes(self) -> int
|
|
47
|
+
def weights(self) -> dict # ATTRIBUTE NAME -> weight (tensor or coded weight); weight-code
|
|
48
|
+
# features replace them with setattr(blk, name, coded)
|
|
49
|
+
def prefill(self, x, ctx) -> y # x (T, d) contiguous rows of ONE user ctx.b at positions ctx.pos0..;
|
|
50
|
+
# updates committed state
|
|
51
|
+
def tree(self, x, ctx) -> y # x (B*N, d) token-tree rows; must NOT change committed state (stash what
|
|
52
|
+
# commit needs on self; tensors allocated here live in the graph pool)
|
|
53
|
+
def commit(self, ctx) # commit the accepted root path of the LAST tree() call
|
|
54
|
+
# row ops (B27 R2/R4):
|
|
55
|
+
def copy_rows(self, src, dst, n=None) # fork users/worlds src -> dst (index tensors or ints)
|
|
56
|
+
def reset_rows(self, rows)
|
|
57
|
+
def fixed_bytes(self) -> int # per-user state independent of context (recurrent + conv state)
|
|
58
|
+
def kv_bytes_per_token(self) -> int
|
|
59
|
+
Multi-row decode (B27 R1): tree() already takes B users x N rows; one CUDA graph per (B, TreeShape) bucket.
|
|
60
|
+
Shared-prefix attention (B27 R3): register your cascade attention as its own block (e.g. "attn_cascade") with
|
|
61
|
+
@blocks.register and route layers to it with adapter.register_rule -- no core edit; the RowCtx can carry extra
|
|
62
|
+
fields (ctx.__dict__ is open) such as a prefix-cache handle.
|
|
63
|
+
MLP blocks are plain callables y = blk(x) (row-wise, stateless) with .weights().
|
|
64
|
+
Residual structure (generic, model.Layer): x += mixer(rms(x, norm1)); x += mlp(rms(x, norm2)).
|
|
65
|
+
Rules: no host syncs and no data-dependent shapes inside tree()/commit() (they run inside one CUDA graph);
|
|
66
|
+
positions come from ctx.pos; the committed length lives in ctx.lens (owned by the caller, not the block).
|
|
67
|
+
|
|
68
|
+
4. RowCtx FIELDS [STABLE]
|
|
69
|
+
prefill: ctx.mode="prefill", ctx.b, ctx.pos0
|
|
70
|
+
tree: ctx.mode="tree", B, N, lens (B,) int32 committed length (= position of row 0), shape (TreeShape),
|
|
71
|
+
par (B,N) int32 parent row (-1 root), pos (B,N) long absolute positions (= lens + depth), maxd,
|
|
72
|
+
paths (B,N,MAXL) int32 root..node row indices (padded with the node), plen (B,N) int32 path lengths,
|
|
73
|
+
orow (B,N) int32, cidx_for(K) -> (N,K) conv-window indices into [conv_state (K-1) | tree rows (N)].
|
|
74
|
+
after acceptance (set by the caller via ctx.set_accept(leaf)):
|
|
75
|
+
leaf (B,) long deepest accepted row, acc_path (B,MAXL) int32 rows root..leaf (padded with leaf),
|
|
76
|
+
acc_len (B,) int32 = number of accepted rows (root included).
|
|
77
|
+
Attention commit writes KV of acc_path[j] at position lens+j for ALL j < MAXL (rows j >= acc_len are don't-care
|
|
78
|
+
slots beyond the committed length) -> keep smax >= max context + MAXL.
|
|
79
|
+
A plain decode step is a tree with N=1; an "append k rows" (chain verify, draft catch-up) is chain(k) + commit.
|
|
80
|
+
|
|
81
|
+
RECURRENT STATE ACROSS TREES (the open design problem; how the core solves it): gdn tree() never materialises
|
|
82
|
+
per-node states: kernels.gdn_paths runs one program per (user, node, value head, value block), loads the committed
|
|
83
|
+
fp32 state block into registers and walks the node's root path (<= MAXL rows) -- every branch forks the state for
|
|
84
|
+
free in registers. kernels.gdn_paths also takes a per-key-channel decay g (rows, HV, DK) -- the Kimi Delta
|
|
85
|
+
Attention form -- so a KDA block reuses it unchanged. commit() re-walks the accepted path with STORE (one more state read+write, ~0.3 ms for
|
|
86
|
+
151 MB at 27B). Conv state: windows gathered along the path (cidx). Any recurrent block (Mamba etc.) can follow
|
|
87
|
+
the same pattern: tree = path walk from the committed state, commit = re-walk with store.
|
|
88
|
+
|
|
89
|
+
5. FEATURES / PLUG-INS [STABLE registry, hooks may grow]
|
|
90
|
+
__init__.py: FEATURES = {}; @register_feature("name") def make(engine, **opts) -> object
|
|
91
|
+
Engine(..., name=opts) calls make(engine, **opts) after the model is built, in keyword order; the object may set:
|
|
92
|
+
.proposer (for spec): callable(engine) -> list of (parent_row, token) extra rows [planned v0.2]
|
|
93
|
+
.generate replaces engine.generate for a workload (batched, shared prompt, worlds, branch and bound ...)
|
|
94
|
+
.serve_* extra HTTP routes for server.py
|
|
95
|
+
Lanes register features from their own directories: Engine(path, extra_paths=[".../exp_b27_batch"],
|
|
96
|
+
plugins=["b27plug"], batched={...}) imports b27plug (which calls register_feature) before building.
|
|
97
|
+
WEIGHT CODES [implemented v0.2]: every block GEMM calls blocks.LINEAR(x, w). w is a bf16 tensor (cuBLAS) or any
|
|
98
|
+
object with .lin(x) -> y and .nbytes() (a coded weight). wcode.convert(model) swaps every eligible matrix
|
|
99
|
+
(block .weights() + LM head) for wcode.C12Weight (lossless 12-bit, O3's c12cu kernel), bit-exact decode verified
|
|
100
|
+
per matrix. An fp8 / MXFP4 dequant-exact weight (P27) is the same: an object with .lin(x). Blocks must call
|
|
101
|
+
LINEAR, never F.linear, for weights.
|
|
102
|
+
|
|
103
|
+
6. PARALLELISM HOOKS (for P27) [STABLE names, single-GPU defaults]
|
|
104
|
+
g["tp"] = {"rank": 0, "world": 1, "group": None} is passed to every block constructor. A sharded block loads its
|
|
105
|
+
slice with W.get(name, shard=(dim, rank, world)) and returns a PARTIAL output; model.Layer calls
|
|
106
|
+
blocks.ALLREDUCE(y, g) on mixer and MLP outputs (identity when world == 1). Pipeline parallel: Model(...,
|
|
107
|
+
layers=range(a, b)) builds a stage [planned]. Expert parallel / MoE / MLA / fp8 blocks: P27 registers them with
|
|
108
|
+
@blocks.register and adds an adapter rule with adapter.register_rule(fn(tc, W, layer_prefix) -> mixer/mlp spec or
|
|
109
|
+
None) so a new family needs no core edit.
|
|
110
|
+
|
|
111
|
+
7. SAMPLER [STABLE]
|
|
112
|
+
record.gumbel_argmax(z, rid, T): token = argmax(z/T + G(rid, v)), rid = seq*65536 + absolute position of the
|
|
113
|
+
token being sampled (23-bit uniform). T=0 -> greedy argmax. spec.measure(z, rid, T) wraps it.
|
|
114
|
+
|
|
115
|
+
9. SERVER [implemented]
|
|
116
|
+
python gpu/engine/server.py --model <snapshot dir> --port 8000 --spec '{"D":3,"C":8}'
|
|
117
|
+
OpenAI-compatible /v1/models, /v1/completions, /v1/chat/completions (stream SSE or not), temperature (exact T via
|
|
118
|
+
the record; seed = record sequence id), max_tokens, stop, ignore_eos, chat_template_kwargs. top_p != 1 / top_k
|
|
119
|
+
refused (400). One request at a time; batched serving = a feature setting .serve_batch (B27).
|
|
120
|
+
|
|
121
|
+
10. SPEED SWITCHES (all exact up to bf16 rounding order; reference paths kept for tests)
|
|
122
|
+
model.FUSED (default True): residual add + RMSNorm fused (kernels.rms_fused). blocks.FUSED_GLUE (True): Triton
|
|
123
|
+
glue for tree rows (GDN conv window + SiLU, gates, gated norm; attention qk-norm + RoPE). spec.COMPILE: torch.compile
|
|
124
|
+
mode for captured passes (None = eager kernels in the graph: RECOMMENDED; with the fused glue it is as fast
|
|
125
|
+
(27B plain 49.4 vs 49.8 tok/s) and bitwise reproducible, while "default" gave run-to-run different greedy
|
|
126
|
+
streams on 27B plain decode). SpecEngine(dvocab=n): MTP
|
|
127
|
+
drafts from ids [0, n) only (proposer-side; verification always uses the full vocabulary). SpecEngine(W=k): k-1
|
|
128
|
+
sibling rows per MTP depth (next-best record candidates) -- a TREE over the hybrid recurrent model.
|
|
129
|
+
ctx.lpaths / ctx.lplen: root->leaf branches; gdn tree = one program per branch emitting every node (EMIT).
|
|
130
|
+
blocks.PREFILL_GDN: "fla" (chunked WY, bf16 tensor-core products, fast) or "recurrent" (fp32 sequential walk of
|
|
131
|
+
kernels.gdn_paths over the prompt; slower, closer to the fp32 reference).
|
|
132
|
+
|
|
133
|
+
10b. PRECISION [implemented v0.5]
|
|
134
|
+
blocks.set_precision("bf16" | "f32a") before Model(...). "f32a" = fp32 activations everywhere with the published
|
|
135
|
+
bf16 weights: GEMMs split x = hi + lo (two bf16 rows) with fp32 accumulation and fp32 OUTPUT (torch >= 2.8
|
|
136
|
+
torch.mm(out_dtype=float32), else kernels.mm_f32out), fp32 KV cache (head-major), fp32 conv state, fp32 attention
|
|
137
|
+
(torch, TF32 off), recurrent fp32 prefill. Purpose: match the fp32 reference where every bf16 engine flips
|
|
138
|
+
(certificate failures are intrinsic bf16 sensitivity, see S27 FINDINGS). Coded weights (C12) are bf16-only.
|
|
139
|
+
|
|
140
|
+
11. SPECULATION (spec.py) [STABLE names]
|
|
141
|
+
SpecEngine(model, D, W, C, J, T, uid, dvocab, draft=Model, Dd, Wobs): ONE static tree per instance:
|
|
142
|
+
root | MTP chain depth D (+ W-1 next-best record candidates per depth) | suffix chain C | Jacobi chain J |
|
|
143
|
+
draft-model chain Dd (any same-tokenizer model built by the engine, recurrent or not; drafting never mutates its
|
|
144
|
+
committed state). .prepare(prompt) captures the graph; .generate(prompt, n, on_tokens, stop_ids).
|
|
145
|
+
OnlineTree(model, Ds, Ws, Cs, T, dvocab): THE GENERIC SHAPE RULE. One graph per (D, W, C), each timed once at
|
|
146
|
+
capture (hardware calibration); per pass it learns p_d (MTP depth acceptance) and s_{d,k} (rank-k candidate
|
|
147
|
+
hits, observed counterfactually every pass) from the exact emitted tokens, and the suffix chain's gain; suffix
|
|
148
|
+
rows only when the lookup has a match; next shape = argmax E/t. Engine(path, spec={"online": True, ...}).
|
|
149
|
+
Exactness never depends on any of this: every emitted token is the target's own record measurement.
|
|
150
|
+
|
|
151
|
+
11b. AMPLITUDE ECHO (I1, spec option E / EW) [implemented]
|
|
152
|
+
SpecEngine(m, ..., E=depth, EW=width): an extra draft chain whose guesses cost NO model eval and NO training.
|
|
153
|
+
Between passes, the logits the verify pass just computed at every tree row (a graph-pool buffer on CUDA) are
|
|
154
|
+
re-measured under the UPCOMING positions' record field: the draft at echo depth d for absolute position
|
|
155
|
+
lens + d is argmax(z_hat/T + G(rid_{lens+d})), where z_hat is the logits row the last pass produced at position
|
|
156
|
+
lens + d - 1 (earliest row at that tree depth; it may sit past the accepted leaf, conditioned on a rejected
|
|
157
|
+
prefix -- still the best free estimate, the Jacobi premise). Because the Gumbel field is deterministic, the
|
|
158
|
+
record noise is a known oracle: re-measuring z_hat under the future rid is the proposal that maximises
|
|
159
|
+
P(acceptance) under a point-estimate posterior on the target logits -- amplitude-amplification-style
|
|
160
|
+
reweighting of the record field. EW-1 siblings per depth take the next-best scores (Grover-style
|
|
161
|
+
multi-candidate verification). Beyond a covered position (first passes / shallow trees) the T>0 guess falls
|
|
162
|
+
back to the pure-field maximum and T=0 to token 0 -- always harmless: verification is unchanged, every
|
|
163
|
+
emitted token is the target's own record measurement, so the stream is token-identical to E=0 (up to the
|
|
164
|
+
documented bf16 near-tie sensitivity of the larger row batch).
|
|
165
|
+
Use: Engine(path, spec={"D": 3, "C": 8, "E": 8, "EW": 3}); also composes through OnlineTree (spec={"online":
|
|
166
|
+
True, "E": ..., "EW": ...}) -- every shape carries its own echo chain.
|
|
167
|
+
CPU measurements (tiny zoo, f32a, gpu/exp_i1_echo/test_echo.py, mean over 3 seeds x {random, repeated} prompts
|
|
168
|
+
x {T=0, T=0.7}, spec {"D":3,"C":8} vs +"E":8,"EW":3):
|
|
169
|
+
llama tok_per_pass 1.112 -> 1.185 (+6.5%), all 12 streams token-identical under f32a
|
|
170
|
+
qwen3_5 tok_per_pass 1.000 -> 1.003 (+0.3%), all 12 streams token-identical under f32a
|
|
171
|
+
Caveat: on CPU the extra tree rows cost serial compute (decode tok/s falls); the feature targets the
|
|
172
|
+
weight-pass metric (tok_per_pass), which is the GPU regime where tree rows ride the same pass. The estimate
|
|
173
|
+
is free and model-agnostic; on real weights, where logits drift slowly across adjacent positions,
|
|
174
|
+
acceptance is expected to be far higher than on the random-weight zoo.
|
|
175
|
+
|
|
176
|
+
CHANGELOG
|
|
177
|
+
v0.11 ... I1 amplitude echo: SpecEngine/OnlineTree E (depth) + EW (width) spec options; lagged target logits
|
|
178
|
+
re-measured under the upcoming record field (see 11b). rows_for + suf_rows index fixes.
|
|
179
|
+
v0.1 09:05 first publication.
|
|
180
|
+
v0.10 10:40 P27 "REQUESTS TO CORE": R1 W.get() default device = cuda:{current_device()} (per rank); R2
|
|
181
|
+
Model.logits_hook = fn(h, head) (vocab-sharded head + all-gather) and Model.stack_hook =
|
|
182
|
+
fn(model, x, ctx, fn) -> (pre-norm x, final-normed h) (residual schemes); R3 blocks.CAT_ROWS(list) for
|
|
183
|
+
every fused projection (tensors -> torch.cat; coded weights -> type(w).cat_rows(list), replaceable);
|
|
184
|
+
R4 RowCtx.scratch = {} per forward for cross-layer plug-in state; R5 blocks.ALLREDUCE (since v0.2).
|
|
185
|
+
v0.9 10:20 OnlineTree times every shape at several committed lengths (t(c, L), interpolated; no long prefill
|
|
186
|
+
needed) so long contexts pick cheaper trees; PLUGINS.txt (lane_dir:module lines imported by every
|
|
187
|
+
Engine -> plug-in blocks/rules reachable from THE entry point, T27 BUG-015); NoPE layers
|
|
188
|
+
(no_rope_layers / no_rope_layer_interval, T27 BUG-016); fp32 attention query blocks of 16/32 rows.
|
|
189
|
+
v0.8 10:05 CPU PATH: dev.py (DEV/CUDA/sync); every Triton kernel has a torch reference fallback on CPU tensors
|
|
190
|
+
(gdn_paths, gated_rms, record sampler via gumbel_ref), attention uses the torch path, no CUDA graphs,
|
|
191
|
+
triton import optional. exp_s27_single/cpu_test.py: tiny random qwen3_5 / qwen3 / llama / qwen2 /
|
|
192
|
+
mistral(sliding window) -> engine prefill vs HF fp32, tree vs prefill, plain + suffix-spec streams vs HF
|
|
193
|
+
teacher-forced (greedy and T=1 record): all PASS on CPU. Engine(precision=, mask_ids=), server
|
|
194
|
+
--precision.
|
|
195
|
+
v0.7 09:50 adapter: weight-COVERAGE check (any checkpoint weight of the text stack that no block reads ->
|
|
196
|
+
NotImplementedError, never silent), config guards (softcapping, multipliers, unknown activations),
|
|
197
|
+
q/k/v/o biases, HF RoPE variants via transformers' ROPE_INIT_FUNCTIONS (llama3/yarn/linear/...),
|
|
198
|
+
GeLU-tanh GLU; plug-in blocks may declare spec["names"] for the coverage check. SpecEngine/OnlineTree
|
|
199
|
+
mask_ids= (banned ids, e.g. stop tokens under min_tokens; target AND proposers). wcode refuses
|
|
200
|
+
non-sm_90 GPUs (NotImplementedError).
|
|
201
|
+
v0.6 09:45 kernels.split_hilo (one-kernel hi/lo split for f32a GEMMs); OnlineTree: Ds up to 8, suffix value per
|
|
202
|
+
(C, match length) with exploration; T27 BUG-001/002/003 fixes (uid_t, sliding window, spec=True).
|
|
203
|
+
v0.5 09:38 precision modes (set_precision), ROUND-generic glue kernels, TreeShape.anc, wcode decode_rows.
|
|
204
|
+
v0.4 09:28 OnlineTree, draft-model chain (draft=, Dd=), PREFILL_GDN, Engine/Server prepare(); server default
|
|
205
|
+
spec = online rule. C12 decode_frag fix (wcode verify now passes).
|
|
206
|
+
v0.3 09:20 FUSED / FUSED_GLUE / COMPILE switches, W siblings, dvocab, AdaptiveSpec (online depth rule), lpaths.
|
|
207
|
+
v0.2 09:20 weights() keys are attribute names; blocks.LINEAR hook + wcode.py (C12) implemented; gdn_paths takes
|
|
208
|
+
vector (KDA) decay; adapter.register_rule; W.get(shard=...); blocks.ALLREDUCE; server.py; reset().
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
# Plug-in modules imported by every Engine(...) (gpu/engine/__init__.py). Format: lane_dir:module (relative to gpu/).
|
|
2
|
+
# A plug-in registers blocks (@blocks.register) and adapter rules (adapter.register_rule) at import time.
|
|
3
|
+
# Lanes: add your line here via your STATUS "REQUESTS TO CORE" (S27 merges them).
|
|
4
|
+
exp_p27_scale:p27rules
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
"""The one entry point: Engine(model_path, **features). See API.txt."""
|
|
2
|
+
import importlib
|
|
3
|
+
import sys
|
|
4
|
+
|
|
5
|
+
FEATURES = {}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def register_feature(name):
|
|
9
|
+
def deco(fn):
|
|
10
|
+
FEATURES[name] = fn
|
|
11
|
+
return fn
|
|
12
|
+
return deco
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def _registered_plugins():
|
|
16
|
+
"""gpu/engine/PLUGINS.txt: one "lane_dir:module" per line (relative to gpu/), imported by every Engine so that
|
|
17
|
+
blocks and adapter rules registered there (MoE, MLA, KDA, ...) are reachable from THE entry point. Missing
|
|
18
|
+
directories are skipped (a lane's image may not ship them)."""
|
|
19
|
+
import os
|
|
20
|
+
here = os.path.dirname(os.path.abspath(__file__))
|
|
21
|
+
f = os.path.join(here, "PLUGINS.txt")
|
|
22
|
+
out = []
|
|
23
|
+
if os.path.exists(f):
|
|
24
|
+
for ln in open(f):
|
|
25
|
+
ln = ln.split("#")[0].strip()
|
|
26
|
+
if ":" in ln:
|
|
27
|
+
d, m = ln.split(":", 1)
|
|
28
|
+
d = d.strip()
|
|
29
|
+
p = os.environ.get("QLLM_LANE_" + d.upper()) or os.path.normpath(os.path.join(here, "..", d))
|
|
30
|
+
if os.path.isdir(p):
|
|
31
|
+
out.append((p, m.strip()))
|
|
32
|
+
return out
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Engine:
|
|
36
|
+
def __init__(self, model_path, B=1, smax=8192, extra_paths=(), plugins=(), spec=None, precision="bf16",
|
|
37
|
+
mask_ids=(), **features):
|
|
38
|
+
for p in list(extra_paths) + [d for d, _ in _registered_plugins()]:
|
|
39
|
+
if p not in sys.path:
|
|
40
|
+
sys.path.insert(0, p)
|
|
41
|
+
for p in list(plugins) + [m for _, m in _registered_plugins()]:
|
|
42
|
+
importlib.import_module(p)
|
|
43
|
+
import blocks
|
|
44
|
+
from model import Model
|
|
45
|
+
blocks.set_precision(precision) # "bf16" (fast) or "f32a" (fp32-faithful activations, certified exact)
|
|
46
|
+
self.precision = precision
|
|
47
|
+
self.model = Model(model_path, B=B, smax=smax)
|
|
48
|
+
self.B, self.smax = B, smax
|
|
49
|
+
# spec=True -> the generic default rule (OnlineTree; T27 BUG-003); None/False -> plain decoding
|
|
50
|
+
if spec is True:
|
|
51
|
+
spec = {"online": True, "C": 8, "dvocab": 65536}
|
|
52
|
+
self.spec_opts = dict(spec) if isinstance(spec, dict) else None
|
|
53
|
+
self.mask_ids = tuple(mask_ids)
|
|
54
|
+
self._spec = {}
|
|
55
|
+
self.features = {}
|
|
56
|
+
for k, o in features.items():
|
|
57
|
+
if k not in FEATURES:
|
|
58
|
+
raise KeyError(f"feature {k!r} not registered (have {sorted(FEATURES)})")
|
|
59
|
+
self.features[k] = FEATURES[k](self, **(o if isinstance(o, dict) else {}))
|
|
60
|
+
|
|
61
|
+
def decoder(self, T=0.0):
|
|
62
|
+
"""spec={"online": True, ...} -> OnlineTree (the generic shape rule); else a fixed SpecEngine shape."""
|
|
63
|
+
from spec import OnlineTree, SpecEngine
|
|
64
|
+
key = float(T)
|
|
65
|
+
if key not in self._spec:
|
|
66
|
+
o = dict(self.spec_opts or {"D": 0, "C": 0})
|
|
67
|
+
if self.mask_ids:
|
|
68
|
+
o.setdefault("mask_ids", self.mask_ids)
|
|
69
|
+
if o.pop("online", False):
|
|
70
|
+
E = OnlineTree(self.model, T=T, **o)
|
|
71
|
+
else:
|
|
72
|
+
E = SpecEngine(self.model, T=T, **o)
|
|
73
|
+
self._spec[key] = E
|
|
74
|
+
return self._spec[key]
|
|
75
|
+
|
|
76
|
+
def generate(self, prompt_ids, n_out, T=0.0):
|
|
77
|
+
for f in self.features.values():
|
|
78
|
+
if hasattr(f, "generate"):
|
|
79
|
+
return f.generate(prompt_ids, n_out, T)
|
|
80
|
+
E = self.decoder(T)
|
|
81
|
+
E.prepare(prompt_ids)
|
|
82
|
+
return E.generate(prompt_ids, n_out)
|