Skip to content

GLM-5.3-Flash EXL3 on 2x DGX Spark with TensorFold

Python

Patch 0088: a request that read nothing for its stored prompt (no room yet) is looked for again; test the case with a read handle

MiaAI-Labb04c173b331c
diff --git a/patches/0088-glm-spill-tier.patch b/patches/0088-glm-spill-tier.patch
index 42aa8cd..07e0457 100644
--- a/patches/0088-glm-spill-tier.patch
+++ b/patches/0088-glm-spill-tier.patch
@@ -2421,7 +2421,7 @@ index af9769e..ce427a1 100644
else:
try:
left = until - time.monotonic() if until is not None else 0.0
-@@ -1895,17 +2405,33 @@ class GlmScheduler(Scheduler):
+@@ -1895,17 +2405,34 @@ class GlmScheduler(Scheduler):
if self._cancel_item(item):
continue
stream, box = item
@@ -2442,6 +2442,7 @@ index af9769e..ce427a1 100644
+ if read is not None:
+ self.loading.append((read, item))
+ continue
++ self.staged.discard(id(stream)) # (nothing read, e.g. no room for it yet: looked for again if it waits)
self.boxes[id(stream)] = box
try:
self.decoder.admit(stream)
@@ -2455,7 +2456,7 @@ index af9769e..ce427a1 100644
self.boxes.pop(id(stream)).put(("error", exc))
continue
if stream.done:
-@@ -1912,10 +2439,20 @@ class GlmScheduler(Scheduler):
+@@ -1912,10 +2440,20 @@ class GlmScheduler(Scheduler):
done.append(stream)
return done
@@ -2477,7 +2478,7 @@ index af9769e..ce427a1 100644
return
live = list(self.decoder.streams.values())
stream = next((s for s in reversed(live) if s.background and not s.done and s.constraint is None
-@@ -1956,7 +2493,10 @@ class GlmScheduler(Scheduler):
+@@ -1956,7 +2494,10 @@ class GlmScheduler(Scheduler):
def _iteration(self) -> None:
self._cancel_waiting()
self._yield()
diff --git a/tools/test_queued_cancellation.py b/tools/test_queued_cancellation.py
index 5e5de23..59e6551 100644
--- a/tools/test_queued_cancellation.py
+++ b/tools/test_queued_cancellation.py
@@ -162,41 +162,55 @@ def main():
assert obj.held is None and not obj.decoder.admitted
checks.append("memory-held cancellation")
- # A request held by NoRoom must not repeat prestage on every retry round.
- # On stock code with discard before admit, each NoRoom re-runs prestage
- # (6 reads across 6 rounds); with deferred discard it runs exactly once.
- reads = []
+ # A request held by NoRoom must not start its stored prompt's read again on every retry round: admit's own room
+ # making evicts the loaded state before it raises NoRoom, so each prestage would read it from the disk anew
+ # (6 reads in 6 rounds on stock code, 1 with the discard after admit). A prestage that read nothing (no room for
+ # the read yet) is looked for again, so the prompt is read once there is room.
class SpillDecoder(Decoder):
- def __init__(self):
+ def __init__(self, no_room_for_read=0):
super().__init__()
- self.can_admit = False
+ self.can_admit, self.resident, self.reads, self.skip = False, False, 0, no_room_for_read
def prestage(self, stream):
- reads.append(stream)
- return None
+ if self.resident:
+ return None
+ if self.skip:
+ self.skip -= 1 # (no room for the read: nothing read, the request waits)
+ return None
+ self.reads += 1
+ return object()
+
+ def load_ready(self, handle):
+ return True
+
+ def complete_load(self, handle):
+ self.resident = True
def admit(self, stream):
if not self.can_admit:
+ self.resident = False # (its room making evicted the state just loaded)
raise ns["NoRoom"]("no room in KV cache")
super().admit(stream)
- obj = scheduler()
- obj.decoder = SpillDecoder()
- thread, reply = ask(obj, lambda: False)
- for _ in range(6):
+ for no_room_for_read, name in ((0, "repeated NoRoom does not re-read a held request's stored prompt"),
+ (1, "a prestage that read nothing is looked for again while the request waits")):
+ obj = scheduler()
+ obj.decoder = SpillDecoder(no_room_for_read)
+ thread, reply = ask(obj, lambda: False)
+ for _ in range(8):
+ obj._iteration()
+ assert obj.decoder.reads == 1 and obj.held is not None and not obj.decoder.admitted, obj.decoder.reads
+ obj.decoder.can_admit = True
obj._iteration()
- assert len(reads) == 1 and obj.held is not None and not obj.decoder.admitted
- obj.decoder.can_admit = True
- obj._iteration()
- assert len(reads) == 1 and obj.held is None
- stream = next(iter(obj.decoder.streams.values()))
- assert obj.decoder.admitted == [stream] and id(stream) not in obj.staged
- stream.take([2])
- stream.done = True
- obj._iteration()
- thread.join(2)
- assert not thread.is_alive() and reply.get("stats") is not None
- checks.append("repeated NoRoom does not re-prestage held request")
+ assert obj.decoder.reads == 1 and obj.held is None
+ stream = next(iter(obj.decoder.streams.values()))
+ assert obj.decoder.admitted == [stream] and id(stream) not in obj.staged
+ stream.take([2])
+ stream.done = True
+ obj._iteration()
+ thread.join(2)
+ assert not thread.is_alive() and reply.get("stats") is not None
+ checks.append(name)
obj = scheduler()
thread, reply = ask(obj, lambda: True)