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/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kaiav Nihalani
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
|
package/README.md
CHANGED
|
@@ -1,3 +1,97 @@
|
|
|
1
|
-
#
|
|
1
|
+
# quantumInfer
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Quantum-inspired exact speculative inference for large FP8 mixture-of-experts LLMs, with a GLM-5.3 Modal implementation.
|
|
4
|
+
|
|
5
|
+
The engine combines target-exact speculative verification, multi-token prediction, whole-context suffix chains, amplitude-echo proposals, adaptive online tree selection, CUDA graph replay, block-FP8 tensor-core kernels, grouped MoE expert GEMMs, fused expert combine, and symmetric-memory tensor-parallel allreduce.
|
|
6
|
+
|
|
7
|
+
## Layout
|
|
8
|
+
|
|
9
|
+
- `engine/` — model-agnostic speculative decoding engine and core kernels.
|
|
10
|
+
- `p27/` — GLM-5.3 model adapter, FP8/MoE kernels, Modal launcher, benchmarks, and microbenchmarks.
|
|
11
|
+
- `results/` — measured benchmark artifacts.
|
|
12
|
+
|
|
13
|
+
## What “quantum-inspired” means here
|
|
14
|
+
|
|
15
|
+
The engine is classical CUDA inference organized around measurement semantics. Target-model logits act as measurement scores, a deterministic Gumbel measurement record makes sampling reproducible token-by-token, and speculative branches are only proposals. Every emitted token is measured by the target model at its own accepted prefix, so speculation changes speed rather than the model distribution within a fixed kernel configuration.
|
|
16
|
+
|
|
17
|
+
## Headline GLM-5.3 measurements
|
|
18
|
+
|
|
19
|
+
8x NVIDIA B300 on Modal, exact target-measured greedy decode, FP8 checkpoint, single user, 256 generated tokens:
|
|
20
|
+
|
|
21
|
+
| configuration | code tok/s | chat tok/s | note |
|
|
22
|
+
|---|---:|---:|---|
|
|
23
|
+
| no speculation control | 53.9 | 53.7 | 128-token sweep control |
|
|
24
|
+
| D3/C32 fixed tree | 144.6 | 94.2 | authoritative repeated benchmark; 148.3/96.6 in the later one-load comparison |
|
|
25
|
+
| D4/C8/W3 + truncated draft vocab | 106.3 | 116.7 | best chat shape in the one-load comparison |
|
|
26
|
+
| D3/C32/W3 repeat-loop case | 265.4 | 95.9 | code output entered a perfect periodic loop; not representative |
|
|
27
|
+
| vLLM 0.34 MTP5 FP8-KV direct | 525.5 | 344.1 | same 8x B300/harness; FP8 KV favors vLLM |
|
|
28
|
+
|
|
29
|
+
See `results/ANALYSIS.md` for controls, competitor context, caveats, and the full artifact list.
|
|
30
|
+
|
|
31
|
+
## npm installer CLI
|
|
32
|
+
|
|
33
|
+
The npm package is a source installer/CLI wrapper, not a JavaScript reimplementation:
|
|
34
|
+
|
|
35
|
+
```bash
|
|
36
|
+
npx quantuminfer quickstart
|
|
37
|
+
npx quantuminfer install
|
|
38
|
+
cd quantumInfer/p27
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Run on Modal
|
|
42
|
+
|
|
43
|
+
Store the Hugging Face cache in a Modal volume named `qllm-big-vol` mounted at `/vol`, with GLM-5.3 present under HF's standard cache layout. Then:
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
cd p27
|
|
47
|
+
modal run modal_p27.py --job bench_glm --gpus b300x8 \
|
|
48
|
+
--out out/res_glm.json \
|
|
49
|
+
--arg '{"plan":{"single":["code","chat"],"single_t1":[],"batched":[],"shared":[],"ttft":[]},"reps":2,"D":3,"C":32,"E":0,"EW":1,"W":1,"align_triton":true,"ar32":true}'
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Validation jobs:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
modal run modal_p27.py --job t_align --gpus dev
|
|
56
|
+
modal run modal_p27.py --job t_fp8dense --gpus dev
|
|
57
|
+
modal run modal_p27.py --job t_symm --gpus h100x2
|
|
58
|
+
modal run modal_p27.py --job t_glm --gpus dev
|
|
59
|
+
modal run modal_p27.py --job t_echo --gpus dev
|
|
60
|
+
modal run modal_p27.py --job t_gsuf --gpus dev
|
|
61
|
+
modal run modal_p27.py --job t_jac --gpus dev
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Recommended GLM-5.3 shapes
|
|
65
|
+
|
|
66
|
+
Measured workload-dependent starting points:
|
|
67
|
+
|
|
68
|
+
- repetitive code / repetitive text: `D=3 C=32 W=1` — best code shape measured.
|
|
69
|
+
- chat / branching natural language: `D=4 C=8 W=3 dvocab=65536` — best chat shape measured.
|
|
70
|
+
- exact T=1 research: `D=3 C=16 J=8` — Jacobi fixed-point chain configuration currently under full-scale validation.
|
|
71
|
+
|
|
72
|
+
Example chat-shape benchmark argument fragment:
|
|
73
|
+
|
|
74
|
+
```bash
|
|
75
|
+
--arg '{"plan":{"single":["chat"],"single_t1":[],"batched":[],"shared":[],"ttft":[]},"reps":1,"D":4,"C":8,"W":3,"dvocab":65536,"align_triton":true,"ar32":true}'
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Competitor harness
|
|
79
|
+
|
|
80
|
+
The same code/chat decode harness can run vLLM or SGLang from their official images. Example direct comparison on 8x B300:
|
|
81
|
+
|
|
82
|
+
```bash
|
|
83
|
+
P27_GPU=B300:8 modal run modal_comp.py::main \
|
|
84
|
+
--engine vllm --mode mtp --k 5 --tag b300mtp \
|
|
85
|
+
--plan '{"single":["code","chat"],"reps":1}' \
|
|
86
|
+
--opts '{"max_len":4096,"max_seqs":8}'
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
The reported vLLM configuration uses TP8, MTP5, and FP8 KV cache, matching the published GLM-5.3 serving recipe. FP8 KV is lossy, so that configuration is a speed-favorable competitor reference rather than an exactness-matched configuration.
|
|
90
|
+
|
|
91
|
+
## Exactness
|
|
92
|
+
|
|
93
|
+
Speculative proposals only decide which tokens are tested. Every emitted token is produced by the target model's own measurement at its own prefix, so no draft model approximation enters the output distribution. This is exact within a fixed numerical kernel configuration; as with normal batched LLM serving, changing reduction shapes/order can alter low-order floating-point bits and therefore near-tie greedy continuations.
|
|
94
|
+
|
|
95
|
+
## Status
|
|
96
|
+
|
|
97
|
+
Research-grade inference engine, not yet a serving replacement for vLLM or SGLang. It currently emphasizes single-user/low-batch decode innovation and kernel-level measurement; continuous batching, OpenAI-compatible serving, broad model coverage, and production hardening are future work.
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { cpSync, existsSync, mkdirSync } from 'node:fs';
|
|
3
|
+
import { spawnSync } from 'node:child_process';
|
|
4
|
+
import { dirname, join, resolve } from 'node:path';
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
|
|
7
|
+
const root = resolve(dirname(fileURLToPath(import.meta.url)), '..');
|
|
8
|
+
const [, , cmd = 'help', ...rest] = process.argv;
|
|
9
|
+
|
|
10
|
+
function sh(cmd, args, opts = {}) {
|
|
11
|
+
const r = spawnSync(cmd, args, { stdio: 'inherit', ...opts });
|
|
12
|
+
return r.status === 0;
|
|
13
|
+
}
|
|
14
|
+
function usage() {
|
|
15
|
+
console.log(`quantuminfer — bootstrap the quantumInfer Python/CUDA research engine
|
|
16
|
+
|
|
17
|
+
Usage:
|
|
18
|
+
quantuminfer install [dir] copy the engine source tree (default: ./quantumInfer)
|
|
19
|
+
quantuminfer doctor check python3, modal, and git availability
|
|
20
|
+
quantuminfer bench [dir] run the GLM-5.3 B300x8 Modal benchmark from an installed tree
|
|
21
|
+
quantuminfer quickstart print the fastest path
|
|
22
|
+
|
|
23
|
+
The inference engine itself is Python/PyTorch/Triton and runs on NVIDIA GPUs.
|
|
24
|
+
This npm package is a distribution/install CLI, not a JavaScript reimplementation.`);
|
|
25
|
+
}
|
|
26
|
+
if (cmd === 'help' || cmd === '--help' || cmd === '-h') usage();
|
|
27
|
+
else if (cmd === 'quickstart') {
|
|
28
|
+
usage();
|
|
29
|
+
console.log('\nQuickstart:\n python3 -m pip install modal torch --user\n modal setup\n npx quantuminfer install\n cd quantumInfer/p27\n modal run modal_p27.py --job t_align --gpus dev');
|
|
30
|
+
} else if (cmd === 'install') {
|
|
31
|
+
const dest = resolve(rest[0] || 'quantumInfer');
|
|
32
|
+
if (existsSync(dest) && rest[0] !== '--force') {
|
|
33
|
+
console.error(`${dest} already exists; choose another directory or remove it first`);
|
|
34
|
+
process.exit(1);
|
|
35
|
+
}
|
|
36
|
+
mkdirSync(dest, { recursive: true });
|
|
37
|
+
for (const x of ['engine', 'p27', 'c27', 'data', 'results', 'README.md', 'LICENSE']) {
|
|
38
|
+
cpSync(join(root, x), join(dest, x), { recursive: true });
|
|
39
|
+
}
|
|
40
|
+
console.log(`Installed quantumInfer source to ${dest}`);
|
|
41
|
+
console.log('Next: python3 -m pip install modal torch --user && modal setup');
|
|
42
|
+
console.log(`Then: cd ${dest}/p27 && modal run modal_p27.py --job t_align --gpus dev`);
|
|
43
|
+
} else if (cmd === 'doctor') {
|
|
44
|
+
let ok = true;
|
|
45
|
+
for (const x of ['python3', 'modal', 'git']) ok = sh(x, ['--version'], { stdio: 'pipe' }) && ok;
|
|
46
|
+
console.log(ok ? 'doctor: required CLI tools are present' : 'doctor: missing python3, modal, or git; install with: python3 -m pip install modal --user && modal setup');
|
|
47
|
+
process.exit(ok ? 0 : 1);
|
|
48
|
+
} else if (cmd === 'bench') {
|
|
49
|
+
const dir = resolve(rest[0] || 'quantumInfer');
|
|
50
|
+
const p27 = join(dir, 'p27');
|
|
51
|
+
if (!existsSync(join(p27, 'modal_p27.py'))) {
|
|
52
|
+
console.error(`no installed p27 tree at ${p27}; run: quantuminfer install ${dir}`);
|
|
53
|
+
process.exit(1);
|
|
54
|
+
}
|
|
55
|
+
const arg = '{"plan":{"single":["code","chat"],"single_t1":[],"batched":[],"shared":[],"ttft":[]},"reps":2,"D":3,"C":32,"E":0,"EW":1,"W":1,"align_triton":true,"ar32":true}';
|
|
56
|
+
process.exit(sh('modal', ['run', 'modal_p27.py', '--job', 'bench_glm', '--gpus', 'b300x8', '--out', 'out/res_glm.json', '--arg', arg], { cwd: p27 }) ? 0 : 1);
|
|
57
|
+
} else {
|
|
58
|
+
console.error(`unknown command: ${cmd}`);
|
|
59
|
+
usage();
|
|
60
|
+
process.exit(1);
|
|
61
|
+
}
|
package/c27/adapters.py
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"""Lane C27 engine adapters (copied from exp_c1_engines/adapters.py; TRT-LLM dropped; seeds + text-only added)."""
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
class VLLM:
|
|
5
|
+
def __init__(self, path, mode, spec=None, max_num_seqs=512, max_model_len=40960, extra=None):
|
|
6
|
+
from vllm import LLM
|
|
7
|
+
self.mode, self.spec = mode, spec
|
|
8
|
+
kw = dict(model=path, dtype="bfloat16", max_model_len=max_model_len, max_num_seqs=max_num_seqs,
|
|
9
|
+
gpu_memory_utilization=0.90, seed=0, disable_log_stats=False, max_num_batched_tokens=16384)
|
|
10
|
+
if spec:
|
|
11
|
+
kw["speculative_config"] = spec
|
|
12
|
+
kw.update(extra or {})
|
|
13
|
+
self.config = {k: v for k, v in kw.items()}
|
|
14
|
+
self.llm = LLM(**kw)
|
|
15
|
+
try:
|
|
16
|
+
cc = self.llm.llm_engine.vllm_config.cache_config
|
|
17
|
+
self.config["_resolved"] = dict(enable_prefix_caching=cc.enable_prefix_caching,
|
|
18
|
+
num_gpu_blocks=cc.num_gpu_blocks, block_size=cc.block_size,
|
|
19
|
+
mamba_cache_mode=str(getattr(cc, "mamba_cache_mode", None)),
|
|
20
|
+
mamba_ssm_cache_dtype=str(getattr(cc, "mamba_ssm_cache_dtype", None)))
|
|
21
|
+
except Exception as e: # noqa
|
|
22
|
+
self.config["_resolved"] = repr(e)
|
|
23
|
+
|
|
24
|
+
def preemptions(self):
|
|
25
|
+
try:
|
|
26
|
+
return sum(m.value for m in self.llm.get_metrics() if m.name == "vllm:num_preemptions" and hasattr(m, "value"))
|
|
27
|
+
except Exception: # noqa
|
|
28
|
+
return None
|
|
29
|
+
|
|
30
|
+
def gen(self, prompts, n, T, seed=None):
|
|
31
|
+
from vllm import SamplingParams
|
|
32
|
+
from vllm.inputs import TokensPrompt
|
|
33
|
+
if seed is None:
|
|
34
|
+
sp = SamplingParams(temperature=T, top_p=1.0, top_k=-1, max_tokens=n, min_tokens=n, ignore_eos=True)
|
|
35
|
+
else: # one distinct per-request seed (seed + i)
|
|
36
|
+
sp = [SamplingParams(temperature=T, top_p=1.0, top_k=-1, max_tokens=n, min_tokens=n, ignore_eos=True,
|
|
37
|
+
seed=seed + i) for i in range(len(prompts))]
|
|
38
|
+
import threading
|
|
39
|
+
import time as _time
|
|
40
|
+
self.max_running, stop = 0, [False]
|
|
41
|
+
|
|
42
|
+
def poll(): # max of the vllm:num_requests_running gauge during this call (actual concurrency)
|
|
43
|
+
while not stop[0]:
|
|
44
|
+
try:
|
|
45
|
+
for m in self.llm.get_metrics():
|
|
46
|
+
if m.name == "vllm:num_requests_running" and hasattr(m, "value"):
|
|
47
|
+
self.max_running = max(self.max_running, int(m.value))
|
|
48
|
+
except Exception: # noqa
|
|
49
|
+
pass
|
|
50
|
+
_time.sleep(0.25)
|
|
51
|
+
th = None
|
|
52
|
+
if len(prompts) > 1:
|
|
53
|
+
th = threading.Thread(target=poll, daemon=True)
|
|
54
|
+
th.start()
|
|
55
|
+
outs = self.llm.generate([TokensPrompt(prompt_token_ids=p) for p in prompts], sp, use_tqdm=False)
|
|
56
|
+
stop[0] = True
|
|
57
|
+
if th:
|
|
58
|
+
th.join()
|
|
59
|
+
return [list(o.outputs[0].token_ids) for o in outs]
|
|
60
|
+
|
|
61
|
+
def reset_cache(self):
|
|
62
|
+
self.llm.reset_prefix_cache()
|
|
63
|
+
|
|
64
|
+
def spec_counters(self):
|
|
65
|
+
if not self.spec:
|
|
66
|
+
return None
|
|
67
|
+
try:
|
|
68
|
+
c = {}
|
|
69
|
+
for m in self.llm.get_metrics():
|
|
70
|
+
if m.name.startswith("vllm:spec_decode") and hasattr(m, "value"):
|
|
71
|
+
c[m.name] = c.get(m.name, 0) + m.value
|
|
72
|
+
return c
|
|
73
|
+
except Exception as e: # noqa
|
|
74
|
+
return None
|
|
75
|
+
|
|
76
|
+
@staticmethod
|
|
77
|
+
def tpp_from(c0, c1, n_new):
|
|
78
|
+
d = {k: c1.get(k, 0) - c0.get(k, 0) for k in c1}
|
|
79
|
+
drafts = d.get("vllm:spec_decode_num_drafts", 0)
|
|
80
|
+
acc = d.get("vllm:spec_decode_num_accepted_tokens", 0)
|
|
81
|
+
return (1 + acc / drafts) if drafts else None
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
class SGLang:
|
|
85
|
+
def __init__(self, path, mode, spec=None, max_running=512, ctx=40960, extra=None):
|
|
86
|
+
import sglang as sgl
|
|
87
|
+
self.mode, self.spec = mode, spec
|
|
88
|
+
kw = dict(model_path=path, dtype="bfloat16", context_length=ctx, max_running_requests=max_running,
|
|
89
|
+
mem_fraction_static=0.85, random_seed=0, log_level="error", cuda_graph_max_bs=max_running,
|
|
90
|
+
enable_metrics=False)
|
|
91
|
+
if spec:
|
|
92
|
+
kw.update(spec)
|
|
93
|
+
kw.update(extra or {})
|
|
94
|
+
if "cuda_graph_max_bs" in kw:
|
|
95
|
+
kw["cuda_graph_max_bs_decode"] = kw.pop("cuda_graph_max_bs")
|
|
96
|
+
import re as _re
|
|
97
|
+
dropped = []
|
|
98
|
+
for _ in range(10):
|
|
99
|
+
try:
|
|
100
|
+
self.eng = sgl.Engine(**kw)
|
|
101
|
+
break
|
|
102
|
+
except TypeError as e:
|
|
103
|
+
m = _re.search(r"unexpected keyword argument '([^']+)'", str(e))
|
|
104
|
+
if not m or m.group(1) not in kw:
|
|
105
|
+
raise
|
|
106
|
+
dropped.append(m.group(1))
|
|
107
|
+
kw.pop(m.group(1))
|
|
108
|
+
self.config = dict(kw, _dropped_unknown_args=dropped)
|
|
109
|
+
try:
|
|
110
|
+
info = self.eng.get_server_info()
|
|
111
|
+
keep = ("max_total_num_tokens", "max_running_requests", "max_mamba_cache_size", "mamba_full_memory_ratio",
|
|
112
|
+
"mamba_radix_cache_strategy", "mamba_ssm_dtype", "chunked_prefill_size", "max_prefill_tokens",
|
|
113
|
+
"attention_backend", "linear_attn_backend", "disable_radix_cache", "cuda_graph_max_bs_decode",
|
|
114
|
+
"page_size", "speculative_algorithm", "speculative_num_steps", "speculative_num_draft_tokens",
|
|
115
|
+
"mem_fraction_static", "language_model_only", "enable_multimodal")
|
|
116
|
+
res = {k: info.get(k) for k in keep if k in info}
|
|
117
|
+
for k, v in info.items():
|
|
118
|
+
if isinstance(v, (int, float, str, bool)) and "mamba" in k:
|
|
119
|
+
res.setdefault(k, v)
|
|
120
|
+
ii = info.get("internal_states") or [{}]
|
|
121
|
+
for k in ("effective_max_running_requests_per_dp", "decode_cuda_graph_memory_gb", "disable_overlap_schedule",
|
|
122
|
+
"uses_mamba_radix_cache"):
|
|
123
|
+
if k in ii[0]:
|
|
124
|
+
res[k] = ii[0][k]
|
|
125
|
+
self.config["_resolved"] = res
|
|
126
|
+
except Exception as e: # noqa
|
|
127
|
+
self.config["_resolved"] = repr(e)
|
|
128
|
+
self._ct = {"verify": 0, "tokens": 0}
|
|
129
|
+
# SGLang's NGRAM drafter keeps a corpus of all earlier requests/outputs (cleared by flush_cache)
|
|
130
|
+
self.cross_request_memory = bool(spec) and spec.get("speculative_algorithm") == "NGRAM"
|
|
131
|
+
|
|
132
|
+
max_running = None
|
|
133
|
+
|
|
134
|
+
def preemptions(self):
|
|
135
|
+
return None
|
|
136
|
+
|
|
137
|
+
def gen(self, prompts, n, T, seed=None):
|
|
138
|
+
sp = {"temperature": T, "top_p": 1.0, "top_k": -1, "max_new_tokens": n, "min_new_tokens": n,
|
|
139
|
+
"ignore_eos": True}
|
|
140
|
+
# per-request seeds are not passed to SGLang (engine random_seed=0 only); T=1 rows are still exact sampling
|
|
141
|
+
outs = self.eng.generate(input_ids=prompts, sampling_params=sp)
|
|
142
|
+
if isinstance(outs, dict):
|
|
143
|
+
outs = [outs]
|
|
144
|
+
for o in outs:
|
|
145
|
+
mi = o.get("meta_info", {})
|
|
146
|
+
self._ct["verify"] += mi.get("spec_verify_ct", 0) or 0
|
|
147
|
+
self._ct["tokens"] += mi.get("completion_tokens", 0) or 0
|
|
148
|
+
return [o.get("output_ids") or [0] * o["meta_info"]["completion_tokens"] for o in outs]
|
|
149
|
+
|
|
150
|
+
def reset_cache(self):
|
|
151
|
+
self.eng.flush_cache()
|
|
152
|
+
|
|
153
|
+
def spec_counters(self):
|
|
154
|
+
return dict(self._ct) if self.spec else None
|
|
155
|
+
|
|
156
|
+
@staticmethod
|
|
157
|
+
def tpp_from(c0, c1, n_new):
|
|
158
|
+
v = c1["verify"] - c0["verify"]
|
|
159
|
+
return (c1["tokens"] - c0["tokens"]) / v if v else None
|
|
160
|
+
|
|
161
|
+
|