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
5 changes: 4 additions & 1 deletion opt_prime/opt_prime/accel/platforms/atom/batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def __init__(self, model, lanes, *, prefix_cache=True, host_bytes=0, medium_devi
self.blocks = rc.kvcache_num_blocks
if self.blocks < lanes + 1:
raise ValueError("own block tables need kv_blocks >= lanes + 1 (a scratch block for idle lanes)")
if prefix_cache and self.blocks < lanes + 2: # else a prefix hit may find only its own source to evict
raise ValueError("prefix caching needs kv_blocks >= lanes + 2 (a scratch block and an evictable entry)")
self.scratch = self.blocks - 1
self.free = list(range(self.blocks - 1))
self.lane_block = [None] * lanes
Expand Down Expand Up @@ -249,7 +251,8 @@ class AtomBatcher(ContinuousBatcher):

def __init__(self, model, *, pad_token_id=None, prefix_cache=False, host_kv_gib=0.0, kv_events=None,
prefill_worker=None, remote_inflight=None, local_prefill=True):
"""prefix_cache / host_kv_gib need a model compiled with kv_blocks > batch_size (own block tables).
"""prefix_cache / host_kv_gib need a model compiled with kv_blocks > batch_size (own block tables;
prefix_cache needs kv_blocks >= batch_size + 2).
prefill_worker (PD, #120): prompts are prefilled elsewhere (`pd.pd_batching.PrefillWorker` and engines) and their
KV imported into the lane's block; ATOM only decodes, so the batch never stalls on a prefill.
remote_inflight (PD): at most this many prompts wait on the prefill worker(s) (default: 2 per worker).
Expand Down
13 changes: 13 additions & 0 deletions opt_prime/tests/test_atom_batching.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,19 @@ def test_prefix_cache_needs_extra_blocks(fake_rebel):
AtomBatcher(FakeRbln(_llama(), 2), prefix_cache=True)


def test_prefix_cache_needs_an_evictable_block(fake_rebel):
"""#172: with kv_blocks == lanes + 1 the only cache entry is also the copy source, so a prefix hit with every
other lane busy found no block and poisoned the batcher; the configuration is rejected at construction"""
model = _llama()
with pytest.raises(ValueError, match="kv_blocks"):
AtomBatcher(_blocks_model(fake_rebel, model, batch=1, blocks=2), prefix_cache=True)
b = AtomBatcher(_blocks_model(fake_rebel, model, batch=1, blocks=2)) # no prefix cache: one block is enough
p = _prompts(1, 40, 41, seed=7)[0]
for rid in ("p", "p2"):
f = b.submit(PDRequest(rid, p, 4)); b.run_until_idle()
assert f.result() == _greedy(model, p, 4)


def test_pd_mode_imports_prefilled_kv(fake_rebel):
"""ATOM decodes only: prompts are prefilled by a torch worker and their KV imported into the lanes' blocks"""
import copy
Expand Down
Loading