Skip to content
Closed
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
18 changes: 18 additions & 0 deletions docs/split-prefill-wavefront.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,24 @@ WCPB is opt-in through `SchedulerConfig.wavefront_chunked_prefill` or the
chunk size. The option works with refill or mixed scheduling. The native
Inkling async token pipeline can also share recurrent work with prompt chunks.

### Adaptive sizing

Add `--adaptive-wavefront-prefill` to `--wavefront-chunked-prefill` to size the
chunks and the per-submission prefill budget at runtime. `--prefill-chunk-size`
and `--max-num-batched-tokens` provide upper bounds for the preallocated ring,
execution buffers, and graph sizes.

Each admitted prompt picks its chunk size from the uncached suffix, active
prompt count, and free KV pages. Its size is stable for the lifetime of its ring.
The scheduler uses the full row budget when compatible work is ready and there
is no outstanding decode pressure. After giving each ready request/depth a turn,
it uses spare rows for adjacent chunks already staged at those depths. Queued
decode requests can reduce the prefill share when decode is due. With incremental
KV allocation, staging also
accounts for growth in the next queued decode visit. KV storage depth and page
size come from the active cache manager. CUDA's automatic KV pool uses the
device memory probe when no cache size override is supplied.

## Progress and dependencies

WCPB relies on the depth-specific KV planes of `LAST_EXITED` layout. For
Expand Down
2 changes: 2 additions & 0 deletions tests/test_backend_selection.py
Original file line number Diff line number Diff line change
Expand Up @@ -378,8 +378,10 @@ def plan_cache(
speculative=None,
staged_prefill=None,
fp8_scale=None,
attention=None,
):
assert selected == "triton" # FA2 cannot use the configured 16-token pages.
assert attention.info["selected_backend"] == selected
assert staged_prefill is False
raise ProfileReached

Expand Down
151 changes: 151 additions & 0 deletions tests/test_split_prefill.py
Original file line number Diff line number Diff line change
Expand Up @@ -865,6 +865,46 @@ def test_wavefront_prefill_batches_ready_depths_and_reuses_retired_ring_slots():
e.close()


def test_adaptive_wavefront_fills_spare_rows_with_staged_chunks_at_the_same_depth():
config = SchedulerConfig(
mode="mixed",
max_num_seqs=1,
max_num_batched_tokens=7,
prefill_chunk_size=2,
wavefront_chunked_prefill=True,
adaptive_wavefront_prefill=True,
)
reference = make_prefill_engine(atomic=True)
engine = make_prefill_engine(scheduler_config=config)
prompt = list(range(1, 12))
try:
expected = run_request(reference, prompt)
params = SamplingParams(max_tokens=3, max_loops=2, ignore_eos=True)
engine.add_request("run", prompt, params)
assert not engine.step()
request = engine.scheduler.requests["run"]
assert request.phase is RequestPhase.PREFILLING_PRELUDE
assert not engine.step()

core = engine.scheduler.schedule()
assert core.phase is RequestPhase.PREFILLING_RECURRENT
assert [(item.token_start, item.token_count, item.depth) for item in core.requests] == [
(0, 2, 0),
(2, 2, 0),
(4, 2, 0),
(6, 1, 0),
]
# Release the selection and exercise the runner's normal submit/update path.
engine.scheduler.enqueue(request, core.phase)
actual = drain_request(engine)
assert actual.token_ids == expected.token_ids
assert actual.exit_depths == expected.exit_depths
assert engine.cache_manager.num_used_blocks == 0
finally:
engine.close()
reference.close()


def test_wavefront_prefill_matches_atomic_tokens_and_keeps_full_depth_first_output():
wavefront = SchedulerConfig(
max_num_seqs=2,
Expand All @@ -891,6 +931,117 @@ def test_wavefront_prefill_matches_atomic_tokens_and_keeps_full_depth_first_outp
actual.close()


@pytest.mark.parametrize(("kv_blocks", "long_chunk"), [(28, 6), (64, 12)])
def test_adaptive_wavefront_sizes_follow_live_kv_and_preserve_ring_progress(kv_blocks, long_chunk):
config = SchedulerConfig(
mode="mixed",
max_num_seqs=2,
max_num_batched_tokens=24,
prefill_chunk_size=16,
wavefront_chunked_prefill=True,
adaptive_wavefront_prefill=True,
)
engine = make_prefill_engine(
scheduler_config=config, cache_config=CacheConfig(kv_blocks, 2, incremental_allocation=True)
)
reference = make_prefill_engine(atomic=True)
try:
prompts = {"short": [2, 3], "long": list(range(1, 13))}
params = SamplingParams(max_tokens=1)
expected = {}
for request_id, prompt in prompts.items():
reference.add_request(request_id, prompt, params)
expected[request_id] = drain_request(reference).token_ids
engine.add_request(request_id, prompt, params)
finished = set()
for _ in range(60):
for output in engine.step():
if output.finished:
assert output.token_ids == expected[output.request_id]
finished.add(output.request_id)
if len(finished) == 2:
break
short = engine.scheduler.requests.get("short")
long = engine.scheduler.requests.get("long")
if short is not None:
assert short.prefill_chunk_size == 2
if long is not None:
assert long.prefill_chunk_size == long_chunk
assert finished == {"short", "long"}
assert engine.cache_manager.num_used_blocks == 0
finally:
engine.close()
reference.close()


def test_adaptive_wavefront_reduces_budget_and_accounts_for_decode_page_growth():
config = SchedulerConfig(
mode="mixed",
max_num_seqs=4,
max_num_batched_tokens=12,
prefill_chunk_size=4,
wavefront_chunked_prefill=True,
adaptive_wavefront_prefill=True,
)
engine = make_prefill_engine(
scheduler_config=config, cache_config=CacheConfig(32, 2, incremental_allocation=True)
)
try:
scheduler = engine.scheduler
cache = engine.cache_manager
for index in range(3):
request = Request(str(index), [2, 3], SamplingParams(max_tokens=2))
request.generated_token_ids.append(4)
assert cache.allocate(request.request_id, 3, initial_tokens=2)
scheduler.requests[request.request_id] = request
scheduler.enqueue(request, RequestPhase.RECURRENT)
phase = RequestPhase.PREFILLING_PRELUDE
assert scheduler._wavefront_limits(phase, 12, None) == (12, 8)
scheduler.policy.record_batch(phase)
assert scheduler._wavefront_limits(phase, 12, None) == (4, 8)
finally:
engine.close()


def test_adaptive_wavefront_runs_decode_when_prefill_must_leave_its_next_kv_page_free():
config = SchedulerConfig(
mode="mixed",
max_num_seqs=2,
max_num_batched_tokens=4,
prefill_chunk_size=4,
wavefront_chunked_prefill=True,
adaptive_wavefront_prefill=True,
)
engine = make_prefill_engine(
scheduler_config=config, cache_config=CacheConfig(12, 2, incremental_allocation=True)
)
try:
scheduler = engine.scheduler
cache = engine.cache_manager
decode = Request("d", [2, 3], SamplingParams(max_tokens=2), generated_token_ids=[4])
prompt = Request(
"p",
[5, 6, 7, 8],
SamplingParams(max_tokens=1),
num_preluded_tokens=2,
prefill_depth_ranges=Request.prefill_boundaries(4, TOTAL_DEPTHS),
)
for request, capacity, phase in (
(decode, 3, RequestPhase.RECURRENT),
(prompt, 4, RequestPhase.PREFILLING_PRELUDE),
):
assert cache.allocate(request.request_id, capacity, initial_tokens=2)
scheduler.requests[request.request_id] = request
scheduler.enqueue(request, phase)

batch = scheduler.schedule()
assert batch.phase is RequestPhase.RECURRENT
assert batch.requests[0].request is decode
assert list(scheduler.queues[RequestPhase.PREFILLING_PRELUDE]) == ["p"]
finally:
engine.close()


@pytest.mark.parametrize("budget", [1, 5, 17])
def test_wavefront_prefill_preserves_hidden_and_all_depth_kv(budget):
snapshots = []
Expand Down
5 changes: 5 additions & 0 deletions vllm_rlt/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class SchedulerConfig:
policy: str = "fcfs"
enable_preemption: bool = False
wavefront_chunked_prefill: bool = False
adaptive_wavefront_prefill: bool = False

def __post_init__(self):
for name in (
Expand All @@ -82,6 +83,10 @@ def __post_init__(self):
raise ValueError("enable_preemption must be a boolean")
if type(self.wavefront_chunked_prefill) is not bool:
raise ValueError("wavefront_chunked_prefill must be a boolean")
if type(self.adaptive_wavefront_prefill) is not bool:
raise ValueError("adaptive_wavefront_prefill must be a boolean")
if self.adaptive_wavefront_prefill and not self.wavefront_chunked_prefill:
raise ValueError("adaptive_wavefront_prefill requires wavefront_chunked_prefill")
if self.policy not in ("fcfs", "priority"):
raise ValueError("policy must be fcfs or priority")
if self.mode not in ("refill", "no_refill", "mixed"):
Expand Down
2 changes: 2 additions & 0 deletions vllm_rlt/core/memory.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def plan_cache(
speculative=None,
staged_prefill=None,
fp8_scale=None,
attention=None,
):
parameter = next(model.parameters())
config, device = model.config, parameter.device
Expand Down Expand Up @@ -202,6 +203,7 @@ def plan_cache(
device=device,
dtype=parameter.dtype,
backend=backend,
attention=attention,
recurrent_layers=getattr(model, "recurrent_kv_layers", None),
kv_cache_dtype=cache.kv_cache_dtype,
fp8_scale=fp8_scale,
Expand Down
Loading
Loading