Skip to content
Open
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
3 changes: 3 additions & 0 deletions terminal/serve/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -2127,6 +2127,9 @@ def generate_batched(self, ids, max_new, sampling, cancel, embeddings=None):
born = self.gen # the engine process this request is sent to
hold = (sampling or {}).get(HOLD_KEY) # the thinking budget's hold (P2b): the reasoning tokens left when this pass starts, and </think>'s id
keys0 = self.sampling_keys({k: v for k, v in (sampling or {}).items() if k != HOLD_KEY}, hy4=getattr(self, "hy4_engine", False)) # (the hold's key goes on per leg: leg_keys below)
# turn_at as the one-request path sends it: the engine reads a prompt in calls that stop at that checkpoint,
# and Inkling 2's greedy answer depends on how a prompt's rows are grouped into calls
keys0 += "" if getattr(self, "hy4_engine", False) else self.turn_key(ids)
# logprobs: only an admission's token can have an LP line here (the slot's "BT" lines carry none), so the
# server refuses these requests unless max_tokens is 1. The lines go to the request itself, through its
# cancel Event: several requests read control lines at once, and the engine's lp_lines is one attribute.
Expand Down
36 changes: 36 additions & 0 deletions terminal/serve/test_parallel.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def window(): # one batch window: every active slot one token
if "--fake-stage-sample" in args and processed and not active:
print("PSTAT 4 20000 16000 14000 12000 10000", flush=True)
log = open(args[args.index("--log") + 1], "a") if "--log" in args else None
# --rawlog PATH: every GEN / BGEN line as the server sent it (its keys, e.g. turn_at)
rawlog = open(args[args.index("--rawlog") + 1], "a") if "--rawlog" in args else None
PPK = int(args[args.index("--pp-every") + 1]) if "--pp-every" in args else 1
READF = "--readfield" in args # DONE's 15th field: the prompt tokens the engine read (a continued prompt: the 1 it copies)
REUSE = "--reuse" in args # DONE's reused field as the engine gives it: a continued prompt is all held but its last
Expand All @@ -127,6 +129,8 @@ def reused(ids): # token (the request's own output included), a fre
stopped.add(b)
continue
if line.startswith(("GEN ", "BGEN ")):
if rawlog:
rawlog.write(line + "\n"); rawlog.flush()
f = line.split()
slot = int(f[1]) if f[0] == "BGEN" else None
max_new = int(f[2] if f[0] == "BGEN" else f[1])
Expand Down Expand Up @@ -1293,5 +1297,37 @@ def test_explicit_values_reach_the_engine(self):
self.assertEqual(env["STRATA_CKPT_POOL"], "0")


class SlotTurnAt(FakeEngineCase):
"""With batch slots every GEN and BGEN names the prompt's last turn (turn_at), as one request's GEN does: the
engine reads a prompt in calls that stop there, and Inkling 2's greedy answer depends on that grouping."""

def raw(self):
return [line.split() for line in self.rawlog.read_text().splitlines()]

def start_raw(self, slots):
self.rawlog = Path(tempfile.mkdtemp()) / "raw.log"
self.addCleanup(lambda: self.rawlog.parent.exists() and __import__("shutil").rmtree(self.rawlog.parent))
self.start(slots, more=("--rawlog", str(self.rawlog)))

def expected(self, f):
return self.engine.turn_key([int(x) for x in f[-1].split(",")]).strip()

def test_a_request_alone_carries_turn_at(self):
self.start_raw(2)
self.chat("hello there", max_tokens=8)
(f,) = self.raw()
self.assertEqual(f[0], "GEN", f)
self.assertTrue(self.expected(f).startswith("turn_at="), "the template's turn opener is in the prompt")
self.assertIn(self.expected(f), f)

def test_admissions_carry_turn_at(self):
self.start_raw(2)
BatchLegAccounting.queued_chats(self) # two requests waiting at once: both go to slots
bgen = [f for f in self.raw() if f[0] == "BGEN"]
self.assertGreaterEqual(len(bgen), 2, self.raw())
for f in bgen:
self.assertIn(self.expected(f), f)


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