Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ jobs:
run: |
# tests/native_v4/test_serve.py needs the serving stack (httpx, fastapi)
PYTHONPATH=src python -m pytest -q tests/test_devices.py tests/native_v4 \
tests/test_continuous_backlog.py tests/test_solo_openai.py \
tests/test_continuous_backlog.py tests/test_solo_openai.py tests/test_admission.py \
--ignore=tests/native_v4/test_serve.py $(ls -d tests/swap 2>/dev/null)
14 changes: 14 additions & 0 deletions bench/greedy_furiosa_llm_together.jsonl

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions bench/greedy_rngd_pd_block_S1024.jsonl

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions bench/greedy_rngd_pd_together_S1024.jsonl

Large diffs are not rendered by default.

10 changes: 10 additions & 0 deletions bench/harness_rngd_pd_block_S1024.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{"engine": "rngd-pd", "max_tokens": 64, "tag": "", "started": "2026-10-22T11:50:04", "P": 128, "concurrency": 1, "requests": 2, "errors": 0, "ttft_ms": 43.16, "ttft_p90_ms": 46.14, "tpot_ms": 42.36, "tpot_p90_ms": 42.74, "itl_p99_ms": 54.92, "tokens_s": 23.6, "out_tokens": 64.0, "stream_events": 64.0, "prompt_tokens": 128, "power_w": 96.8, "util_pct": 73.6, "first_error": null}
{"engine": "rngd-pd", "max_tokens": 64, "tag": "", "started": "2026-10-22T11:50:04", "P": 128, "concurrency": 2, "requests": 4, "errors": 0, "ttft_ms": 87.59, "ttft_p90_ms": 130.56, "tpot_ms": 41.38, "tpot_p90_ms": 41.84, "itl_p99_ms": 44.83, "tokens_s": 47.13, "out_tokens": 64.0, "stream_events": 64.0, "prompt_tokens": 128, "power_w": 107.6, "util_pct": 71.0, "first_error": null}
{"engine": "rngd-pd", "max_tokens": 64, "tag": "", "started": "2026-10-22T11:50:04", "P": 128, "concurrency": 4, "requests": 8, "errors": 0, "ttft_ms": 125.61, "ttft_p90_ms": 202.78, "tpot_ms": 42.28, "tpot_p90_ms": 43.21, "itl_p99_ms": 80.87, "tokens_s": 91.06, "out_tokens": 64.0, "stream_events": 64.0, "prompt_tokens": 128, "power_w": 111.7, "util_pct": 73.7, "first_error": null}
{"engine": "rngd-pd", "max_tokens": 64, "tag": "", "started": "2026-10-22T11:50:04", "P": 128, "concurrency": 8, "requests": 16, "errors": 0, "ttft_ms": 234.0, "ttft_p90_ms": 351.08, "tpot_ms": 43.53, "tpot_p90_ms": 45.43, "itl_p99_ms": 115.29, "tokens_s": 171.72, "out_tokens": 64.0, "stream_events": 64.0, "prompt_tokens": 128, "power_w": 116.4, "util_pct": 70.5, "first_error": null}
{"engine": "rngd-pd", "max_tokens": 64, "tag": "", "started": "2026-10-22T11:50:04", "P": 128, "concurrency": 16, "requests": 32, "errors": 0, "ttft_ms": 361.06, "ttft_p90_ms": 596.51, "tpot_ms": 47.23, "tpot_p90_ms": 50.9, "itl_p99_ms": 228.42, "tokens_s": 305.95, "out_tokens": 64.0, "stream_events": 64.0, "prompt_tokens": 128, "power_w": 120.4, "util_pct": 69.0, "first_error": null}
{"engine": "rngd-pd", "max_tokens": 64, "tag": "", "started": "2026-10-22T11:50:04", "P": 512, "concurrency": 1, "requests": 2, "errors": 0, "ttft_ms": 77.51, "ttft_p90_ms": 78.36, "tpot_ms": 41.31, "tpot_p90_ms": 41.5, "itl_p99_ms": 46.84, "tokens_s": 23.87, "out_tokens": 64.0, "stream_events": 64.0, "prompt_tokens": 512, "power_w": 115.8, "util_pct": 71.6, "first_error": null}
{"engine": "rngd-pd", "max_tokens": 64, "tag": "", "started": "2026-10-22T11:50:04", "P": 512, "concurrency": 2, "requests": 4, "errors": 0, "ttft_ms": 114.88, "ttft_p90_ms": 183.82, "tpot_ms": 41.93, "tpot_p90_ms": 42.74, "itl_p99_ms": 46.19, "tokens_s": 46.04, "out_tokens": 64.0, "stream_events": 64.0, "prompt_tokens": 512, "power_w": 113.7, "util_pct": 65.0, "first_error": null}
{"engine": "rngd-pd", "max_tokens": 64, "tag": "", "started": "2026-10-22T11:50:04", "P": 512, "concurrency": 4, "requests": 8, "errors": 0, "ttft_ms": 219.87, "ttft_p90_ms": 322.22, "tpot_ms": 43.1, "tpot_p90_ms": 44.75, "itl_p99_ms": 107.11, "tokens_s": 87.04, "out_tokens": 64.0, "stream_events": 64.0, "prompt_tokens": 512, "power_w": 119.8, "util_pct": 72.9, "first_error": null}
{"engine": "rngd-pd", "max_tokens": 64, "tag": "", "started": "2026-10-22T11:50:04", "P": 512, "concurrency": 8, "requests": 16, "errors": 0, "ttft_ms": 359.18, "ttft_p90_ms": 567.54, "tpot_ms": 45.94, "tpot_p90_ms": 49.28, "itl_p99_ms": 181.19, "tokens_s": 157.1, "out_tokens": 64.0, "stream_events": 64.0, "prompt_tokens": 512, "power_w": 130.9, "util_pct": 71.2, "first_error": null}
{"engine": "rngd-pd", "max_tokens": 64, "tag": "", "started": "2026-10-22T11:50:04", "P": 512, "concurrency": 16, "requests": 32, "errors": 0, "ttft_ms": 634.27, "ttft_p90_ms": 1059.62, "tpot_ms": 52.12, "tpot_p90_ms": 59.0, "itl_p99_ms": 398.3, "tokens_s": 260.49, "out_tokens": 64.0, "stream_events": 64.0, "prompt_tokens": 512, "power_w": 138.5, "util_pct": 67.6, "first_error": null}
2 changes: 1 addition & 1 deletion bench/serve_sweep_job.sh
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ echo "[job] server ready after $((i * 5)) s"
if [ "${GREEDY:-0}" != 0 ]; then
hpy "$HERE/vendor_sweep.py" --engine "$ENGINE" --url http://127.0.0.1:$PORT \
--model llama8b --contexts "$CONTEXTS" --max-tokens "${MAX_TOKENS:-64}" \
--greedy "$GREEDY" --out "$OUT"
--greedy "$GREEDY" ${GREEDY_TOGETHER:+--greedy-together} --out "$OUT"
else
hpy "$HERE/vendor_sweep.py" --engine "$ENGINE" --url http://127.0.0.1:$PORT \
--model llama8b --npu "${NPU:-auto}" --contexts "$CONTEXTS" --concurrency "$CONC" \
Expand Down
22 changes: 19 additions & 3 deletions bench/vendor_sweep.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,8 @@ def main():
ap.add_argument("--max-tokens", type=int, default=64)
ap.add_argument("--reps", type=int, default=2)
ap.add_argument("--seed", type=int, default=0)
ap.add_argument("--greedy-together", action="store_true",
help="--greedy: send all prompts at once instead of one at a time")
ap.add_argument("--greedy", type=int, default=0,
help="instead of the sweep: N fixed prompts per P, outputs recorded")
ap.add_argument("--tag", default="", help="free text written to every row")
Expand Down Expand Up @@ -196,10 +198,24 @@ def prompt_ids(P, r=rng):
(bos + tk.encode(t, add_special_tokens=False) for t in GREEDY_PROMPTS)]
cases += [(P, "sweep", prompt_ids(P, fixed)) for P in ctxs for _ in range(a.greedy)]
with open(a.out, "w") as fh:
results = [None] * len(cases)
if a.greedy_together:
# all at once: the batch composition a loaded server sees
def put(i, ids):
res = []
stream_once(a.url, a.model, ids, a.max_tokens, res)
results[i] = res[0]
ths = [threading.Thread(target=put, args=(i, c[2])) for i, c in enumerate(cases)]
for th in ths:
th.start()
for th in ths:
th.join()
for i, (P, kind, ids) in enumerate(cases):
res = []
stream_once(a.url, a.model, ids, a.max_tokens, res)
r = res[0]
if results[i] is None:
res = []
stream_once(a.url, a.model, ids, a.max_tokens, res)
results[i] = res[0]
r = results[i]
row = dict(meta, P=P, idx=i, kind=kind, prompt_ids=ids, out_ids=r["ids"],
text=r["text"], err=r["err"])
fh.write(json.dumps(row) + "\n"); fh.flush()
Expand Down
1 change: 1 addition & 0 deletions deploy/k8s/serve-sweep-job.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ spec:
- {name: RNGD_BUCKETS, value: "128,256,512"}
- {name: B, value: "16"}
- {name: RNGD_MAX_SHAPES, value: "8"}
- {name: RNGD_ADMIT, value: "block"} # admit a burst back to back (#14)
- {name: RNGD_ARTIFACT_CACHE, value: "/cache"}
- {name: HARNESS_PY, value: "${RNGD_PD_HOME}/venvs/furiosa-2026.4/bin/python"}
# rngd-pd's graphs were baked with the torch in ~/.local (bench/prebake.py);
Expand Down
15 changes: 13 additions & 2 deletions src/rngd_pd/engines/decode_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,18 @@ def forward(self, x, nw, eps, nh, wlm):



def greedy_tokens(logits, Vp, V, B):
"""Argmax per stream of the on-card lm_head output [NG, Vp/NG, B].

It used to widen all Vp x B logits to float32 numpy and argmax column by
column: 3.4-4.1 ms of every B=16 step on the host (#14 phase 2). torch's
argmax on the bf16 tensor gives the same index -- the widening is exact
and both return the first maximum -- in a fraction of that.
"""
lg = logits.detach().cpu().reshape(Vp, B)[:V]
return torch.argmax(lg, dim=0).tolist()


class BatchDecodeEngine:
def __init__(self, cfg, sd, B=2, S=256, group=2, chip=2, cache_dir=None):
group = resolve_group(B, S, group, cache_dir)
Expand Down Expand Up @@ -399,8 +411,7 @@ def step(self, toks, positions, Kd, Vd):
Kd[g], Vd[g] = Kf, Vf
out = self.lmh(x, self.norm_d, self.eps_d, self.nh_d, self.wlm_d)
logits = out[0] if isinstance(out, (tuple, list)) else out
lg = logits.detach().cpu().float().numpy().reshape(self.Vp, B)[:self.V]
return [int(np.argmax(lg[:, b])) for b in range(B)], Kd, Vd
return greedy_tokens(logits, self.Vp, self.V, B), Kd, Vd


def main():
Expand Down
23 changes: 15 additions & 8 deletions src/rngd_pd/serving/cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,12 @@ def __init__(self, B, engine, produce, admit_min=1, produce_owner=None,
# inside one step's worth and still finishes a 32-layer pass in four
# iterations instead of sixteen.
self.stage_groups = int(os.environ.get("PD_STAGE_GROUPS", "4"))
# RNGD_ADMIT=block admits every waiting prompt back to back before the
# next step instead of staging one prompt a few groups at a time
# between steps. Staging protects the TPOT of streams already running;
# blocking gets a burst to its first tokens several times sooner
# (#14: 16 prompts at once waited ~4 decode steps each).
self.stage_admission = os.environ.get("RNGD_ADMIT", "stage") != "block"
threading.Thread(target=self._loop, daemon=True).start()

def submit(self, item):
Expand Down Expand Up @@ -940,22 +946,23 @@ def _admit(self, taking, Kd, Vd):
is what made iteration-level scheduling lose to the static batcher.
Writing just the lane keeps the other streams on the card untouched.
"""
loaded = []
# One stream at a time: produce, write its lane, seat it. Seating each
# as soon as its cache is in lets its first token go out while the
# rest of the admission is still prefilling, and holds one stream's
# cache in flight instead of all of them.
ms = 0.0
for idx, item in taking:
K, V, first, pos, aux_ms = item.pop("_produced", None) or self.produce(item)
item["first"], item["pos"] = first, pos
loaded.append((idx, item, K, V, aux_ms))
t0 = time.perf_counter() # the write only, not the source
for idx, _item, K, V, _ in loaded:
t0 = time.perf_counter() # the write only, not the source
Kd, Vd = self.eng.write_slot_kv(Kd, Vd, idx, K, V)
ms = (time.perf_counter() - t0) * 1e3
ms += (time.perf_counter() - t0) * 1e3
self._seat(idx, item, aux_ms)
self.admit_ms += ms
self.admits += 1
# Admission runs under the device lock, so every millisecond here is a
# millisecond no stream advanced -- distinct from an idle lane.
self.admit_stall_ms += ms
for idx, item, _K, _V, load_ms in loaded:
self._seat(idx, item, load_ms)
return Kd, Vd

def _seat(self, idx, item, load_ms):
Expand Down Expand Up @@ -1044,7 +1051,7 @@ def _loop(self):
Kd, Vd = self.eng.write_slot_kv(Kd, Vd, idx, K, V)
self._seat(idx, item, aux)
self._staging = None
elif (taking and self._active()
elif (taking and self._active() and self.stage_admission
and hasattr(self.produce_owner, "begin_produce")):
# Stage only while there is something to protect. With
# an empty batch there is no decode to interrupt, and
Expand Down
88 changes: 88 additions & 0 deletions tests/test_admission.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
"""Block admission (RNGD_ADMIT=block, #14): a burst is prefilled back to back,
each stream seated as soon as its own cache is in, and none is staged.

PYTHONPATH=src python -m pytest -q tests/test_admission.py
"""
import os
import sys
import threading
import time
import unittest

sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(os.path.abspath(__file__))), "src"))

from rngd_pd.serving import cluster # noqa: E402


class FakeEngine:
def __init__(self, B):
self.B = B

def blank_kv(self):
return object(), object()

def write_slot_kv(self, Kd, Vd, idx, K, V):
return Kd, Vd

def step(self, cur, pos, Kd, Vd):
time.sleep(0.02)
return [c + 1 for c in cur], Kd, Vd


class Owner:
def __init__(self):
self.staged = 0

def begin_produce(self, item):
self.staged += 1
raise AssertionError("block admission must not stage")


def run(block):
os.environ["RNGD_ADMIT"] = "block" if block else "stage"
owner = Owner()
produced = []

def produce(item):
time.sleep(0.005)
produced.append(time.perf_counter())
return None, None, item["seed"], 3, 5.0
sched = cluster._ContinuousScheduler(8, FakeEngine(8), produce, produce_owner=owner)
firsts, out, ths = {}, {}, []

def one(i):
t = []
out[i] = sched.submit({"tokens": [0, 1, 2], "max_new": 6, "seed": 10 * i,
"on_token": lambda tok: t.append(time.perf_counter())})
firsts[i] = t[0]
first = threading.Thread(target=one, args=(0,), daemon=True)
first.start()
time.sleep(0.03) # one stream decoding, then a burst
for i in range(1, 6):
th = threading.Thread(target=one, args=(i,), daemon=True)
th.start(); ths.append(th)
for th in [first] + ths:
th.join(10)
return owner, out, produced, firsts


class BlockAdmission(unittest.TestCase):
def tearDown(self):
os.environ.pop("RNGD_ADMIT", None)

def test_burst_is_not_staged_and_all_finish(self):
owner, out, produced, firsts = run(block=True)
self.assertEqual(owner.staged, 0)
self.assertEqual(len(out), 6)
for i, o in out.items():
self.assertEqual(o["tokens"], [10 * i + k for k in range(6)])

def test_each_stream_starts_when_its_own_cache_is_in(self):
_owner, _out, produced, firsts = run(block=True)
# the first token of a burst member goes out before the last prefill
# of that burst ends, not after all of them
self.assertLess(min(firsts[i] for i in range(1, 6)), max(produced))


if __name__ == "__main__":
unittest.main()
Loading