diff --git a/docs/split-prefill-wavefront.md b/docs/split-prefill-wavefront.md index 1e62c577..49fabe3c 100644 --- a/docs/split-prefill-wavefront.md +++ b/docs/split-prefill-wavefront.md @@ -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 diff --git a/tests/test_backend_selection.py b/tests/test_backend_selection.py index cc90cf90..90df5655 100644 --- a/tests/test_backend_selection.py +++ b/tests/test_backend_selection.py @@ -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 diff --git a/tests/test_split_prefill.py b/tests/test_split_prefill.py index bf3d921e..9898ab27 100644 --- a/tests/test_split_prefill.py +++ b/tests/test_split_prefill.py @@ -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, @@ -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 = [] diff --git a/vllm_rlt/config.py b/vllm_rlt/config.py index befeb6b2..810bc236 100644 --- a/vllm_rlt/config.py +++ b/vllm_rlt/config.py @@ -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 ( @@ -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"): diff --git a/vllm_rlt/core/memory.py b/vllm_rlt/core/memory.py index 40f88f7c..26d8430b 100644 --- a/vllm_rlt/core/memory.py +++ b/vllm_rlt/core/memory.py @@ -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 @@ -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, diff --git a/vllm_rlt/core/scheduler.py b/vllm_rlt/core/scheduler.py index ea704070..83ecc112 100644 --- a/vllm_rlt/core/scheduler.py +++ b/vllm_rlt/core/scheduler.py @@ -118,6 +118,7 @@ class AdmissionPlan: reserved_growth_blocks: int admission_headroom_blocks: int cached_claim_blocks: int + prefill_chunk_size: int | None = None @property def total_budget_blocks(self) -> int: @@ -408,8 +409,14 @@ def _plan_admission(self, request: Request, active_count: int) -> AdmissionPlan: capacity = len(request.prompt_token_ids) + request.sampling_params.max_tokens - 1 prefix = cache.lookup_prefix(request.prompt_token_ids) cached_tokens = len(prefix) * cache.block_size + chunk_size = None + if self.config.adaptive_wavefront_prefill: + chunk_size = request.prefill_chunk_size or self._choose_wavefront_chunk( + len(request.prompt_token_ids) - cached_tokens + ) initial_tokens = min( - len(request.prompt_token_ids), cached_tokens + self.config.prefill_chunk_size + len(request.prompt_token_ids), + cached_tokens + (chunk_size or self.config.prefill_chunk_size), ) if not cache.incremental_allocation: initial_tokens = capacity @@ -437,6 +444,7 @@ def _plan_admission(self, request: Request, active_count: int) -> AdmissionPlan: reserved_growth_blocks=reserved, admission_headroom_blocks=admission_headroom_blocks, cached_claim_blocks=cached_claim, + prefill_chunk_size=chunk_size, ) def reserve_transfer(self, request: Request) -> AdmissionPlan | None: @@ -470,6 +478,7 @@ def _commit_admission(self, request: Request, plan: AdmissionPlan) -> bool: """Allocate pages and enter PREFILL only when the whole budget fits.""" if not self._allocate(request, plan): return False + request.prefill_chunk_size = plan.prefill_chunk_size request.num_prefilled_tokens = plan.cached_tokens # A reused prompt prefix is already prefilled at every depth, so the # staged window starts closed at that frontier and opens for the rest. @@ -486,11 +495,34 @@ def _commit_admission(self, request: Request, plan: AdmissionPlan) -> bool: return True def _enter_prefill(self, request): + if self.config.adaptive_wavefront_prefill and request.prefill_chunk_size is None: + # An outgoing transfer may already own its entire prompt allocation. + remaining = len(request.prompt_token_ids) - request.prefill_window_origin + request.prefill_chunk_size = self._choose_wavefront_chunk( + remaining, resident_rows=remaining + ) if self.staged_prefill: self.enqueue(request, RequestPhase.PREFILLING_PRELUDE) else: self.enqueue(request, RequestPhase.PREFILL) + def _choose_wavefront_chunk(self, remaining: int, *, resident_rows: int = 0) -> int: + """Set a bounded ring stride from the prompt suffix and available pages.""" + cache = self.cache_manager + upper = min(self.config.prefill_chunk_size, self.config.max_num_batched_tokens) + prompt_owners = 1 + sum( + len(self.queues[phase]) + for phase in (RequestPhase.PREFILLING_PRELUDE, RequestPhase.PREFILLING_RECURRENT) + ) + batch_share = self.config.max_num_batched_tokens // min(self.total_ut_steps, prompt_owners) + pages = cache.num_free_blocks // (cache.storage_depths * prompt_owners) + kv_rows = resident_rows + pages * cache.block_size + limit = min(batch_share, kv_rows) + if limit < upper: + # Keep chunk boundaries page-aligned when a smaller stride is needed. + upper = min(upper, max(1, limit // cache.block_size) * cache.block_size) + return max(1, min(upper, remaining)) + def _admit(self): """Admit waiting requests: order -> slot -> restore/allocate -> defer/enter. @@ -637,7 +669,7 @@ def _make_wavefront_task( self, request, phase, token_budget, *, start, depth=None ) -> ScheduledRequest | None: """Snapshot one chunk within the bounded per-request wavefront ring.""" - chunk_size = self.config.prefill_chunk_size + chunk_size = request.prefill_chunk_size or self.config.prefill_chunk_size origin = request.prefill_window_origin if start < origin: raise RuntimeError("wavefront work precedes its cached-prefix origin") @@ -658,8 +690,9 @@ def _make_wavefront_task( if depth is None: raise ValueError("wavefront recurrent work requires an explicit depth") left, right = request.prefill_depth_ranges[depth] - if left != start: - raise RuntimeError("wavefront recurrent task is not at its depth frontier") + # Additional spans may follow an earlier span in the same batch. + if start < left: + raise RuntimeError("wavefront recurrent task precedes its depth frontier") end = min(chunk_end, right, request.num_preluded_tokens) count = min(token_budget, end - start) @@ -703,10 +736,10 @@ def _prelude_window_open(self, request: Request) -> bool: and retires one ring slot after each contiguous final-depth chunk. """ if self.wavefront_chunked_prefill: + chunk_size = request.prefill_chunk_size or self.config.prefill_chunk_size window_end = min( len(request.prompt_token_ids), - request.prefill_reclaimable_tokens - + self.config.prefill_chunk_size * len(request.prefill_depth_ranges), + request.prefill_reclaimable_tokens + chunk_size * len(request.prefill_depth_ranges), ) return request.num_preluded_tokens < window_end return request.num_preluded_tokens == request.num_prefilled_tokens @@ -721,6 +754,47 @@ def has_ready(self, phase): def _take(self, phase: RequestPhase) -> SchedulerOutput | None: return self.take_phases((phase,)) + def _wavefront_limits(self, phase, available, eligible): + """Bound prefill rows and leave pages for the next queued decode visit.""" + cache = self.cache_manager + protect_growth = phase == RequestPhase.PREFILLING_PRELUDE and cache.incremental_allocation + shrink_budget = self.policy.decode_due and available > self.config.prefill_chunk_size + if not (protect_growth or shrink_budget): + return available, None + decode_count = 0 + decode_blocks = 0 + for decode_phase in ( + RequestPhase.PRELUDE, + RequestPhase.RECURRENT, + RequestPhase.CODA, + RequestPhase.SPECULATIVE, + ): + for request_id in self.queues[decode_phase]: + request = self.requests[request_id] + if eligible is not None and not eligible(request): + continue + decode_count += 1 + if protect_growth: + rows = ( + self.speculative_config.num_speculative_tokens + 1 + if decode_phase == RequestPhase.SPECULATIVE + else 1 + ) + end = min( + request.position + rows, + len(request.prompt_token_ids) + request.sampling_params.max_tokens - 1, + ) + decode_blocks += max( + 0, cache.required_blocks(end) - cache.allocated_blocks(request_id) + ) + if decode_count and shrink_budget: + hard = self.config.max_num_batched_tokens + chunk = self.config.prefill_chunk_size + target = hard - hard * decode_count // self.config.max_num_seqs + available = min(available, max(chunk, ((target + chunk - 1) // chunk) * chunk)) + growth = max(0, cache.num_free_blocks - decode_blocks) if decode_blocks else None + return available, growth + def take_phases(self, phases, *, eligible=None, reserve_for_later=0): """Select compatible requests across queues under one budget/reservation set.""" eligible = eligible if eligible is not None else self.execution_ready @@ -735,14 +809,21 @@ def take_phases(self, phases, *, eligible=None, reserve_for_later=0): RequestPhase.PREFILLING_PRELUDE, RequestPhase.PREFILLING_RECURRENT, ): - token_budget = reserved + self._take_wavefront_phase( + budget, growth = ( + self._wavefront_limits(phase, available, eligible) + if self.config.adaptive_wavefront_prefill and available + else (available, None) + ) + remaining = self._take_wavefront_phase( phase, queue, - available, + budget, scheduled_requests, selected, eligible, + growth_blocks=growth, ) + token_budget -= budget - remaining continue remaining = len(queue) while queue and available and len(selected) < self.config.max_num_seqs and remaining: @@ -889,7 +970,7 @@ def _scheduled_prefill_completes(self, scheduled_request, loop_count): ) def _take_wavefront_phase( - self, phase, queue, token_budget, scheduled_requests, selected, eligible + self, phase, queue, token_budget, scheduled_requests, selected, eligible, *, growth_blocks ): """Round-robin each request's chunks/depths into the shared token budget.""" remaining = len(queue) @@ -921,12 +1002,23 @@ def _take_wavefront_phase( def accept_task(request: Request, scheduled_request: ScheduledRequest) -> bool: """Reserve capacity and commit one wavefront task to this batch.""" - nonlocal token_budget + nonlocal token_budget, growth_blocks request_id = request.request_id frontier = scheduled_request.token_start + scheduled_request.token_count + extra = ( + max( + 0, + self.cache_manager.required_blocks(frontier) + - self.cache_manager.allocated_blocks(request_id), + ) + if growth_blocks is not None + else 0 + ) if not self._ensure_execution_capacity(request, frontier, selected=selected): blocked.add(request_id) return False + if growth_blocks is not None: + growth_blocks -= extra selected.add(request_id) added.add(request_id) token_budget -= scheduled_request.token_count @@ -953,10 +1045,16 @@ def accept_task(request: Request, scheduled_request: ScheduledRequest) -> bool: end = min(end, request.num_preluded_tokens) if start >= end: continue + available = token_budget + if growth_blocks is not None: + cache = self.cache_manager + blocks = cache.allocated_blocks(request_id) + growth_blocks + frontier = blocks // cache.storage_depths * cache.block_size + available = min(available, frontier - start) scheduled_request = self._make_wavefront_task( request, phase, - token_budget, + available, depth=(None if phase == RequestPhase.PREFILLING_PRELUDE else depth), start=start, ) @@ -966,6 +1064,26 @@ def accept_task(request: Request, scheduled_request: ScheduledRequest) -> bool: assert prelude_cursors is not None prelude_cursors[request_id] += scheduled_request.token_count tasks.append((owner_index, scheduled_request)) + if ( + token_budget + and self.config.adaptive_wavefront_prefill + and phase == RequestPhase.PREFILLING_RECURRENT + ): + # Every ready depth has had its first turn. Fill the remaining rows + # with staged chunks at those same depths, without advancing their + # frontiers or borrowing work that this submission has yet to produce. + for owner_index, first in tuple(tasks): + request, depth = first.request, first.depth + start = first.token_start + first.token_count + ready_end = min(request.prefill_depth_ranges[depth][1], request.num_preluded_tokens) + while token_budget and start < ready_end: + task = self._make_wavefront_task( + request, phase, token_budget, start=start, depth=depth + ) + if task is None or not accept_task(request, task): + break + tasks.append((owner_index, task)) + start += task.token_count tasks.sort(key=lambda item: (item[0], item[1].token_start)) scheduled_requests.extend( replace(scheduled_request, phase=phase) for _, scheduled_request in tasks @@ -1144,6 +1262,7 @@ def _apply_wavefront_prefill_batch_progress( ) else: chunk_complete = False + chunk_size = request.prefill_chunk_size or self.config.prefill_chunk_size representative = scheduled_requests[0] for item in scheduled_requests: depth = item.depth @@ -1160,7 +1279,7 @@ def _apply_wavefront_prefill_batch_progress( chunk_end = min( len(request.prompt_token_ids), - item.chunk_start + self.config.prefill_chunk_size, + item.chunk_start + chunk_size, ) if end == chunk_end: if item.chunk_start != request.prefill_reclaimable_tokens: diff --git a/vllm_rlt/core/scheduling_policy.py b/vllm_rlt/core/scheduling_policy.py index 561acf12..d17a96f7 100644 --- a/vllm_rlt/core/scheduling_policy.py +++ b/vllm_rlt/core/scheduling_policy.py @@ -75,7 +75,9 @@ def schedule( scheduler._admit() for phase in self.PREFILL_PHASES: if scheduler.has_ready(phase): - return scheduler._take(phase) + batch = scheduler._take(phase) + if batch is not None or not self.config.adaptive_wavefront_prefill: + return batch # Admission can restore a snapshot directly to a boundary phase. if scheduler.has_ready(RequestPhase.PRELUDE): return scheduler._take(RequestPhase.PRELUDE) @@ -147,7 +149,9 @@ def schedule(self, scheduler, *, prefer_recurrent=False): return scheduler._take(RequestPhase.CODA) for phase in self.PREFILL_PHASES: if scheduler.has_ready(phase): - return scheduler._take(phase) + batch = scheduler._take(phase) + if batch is not None or not self.config.adaptive_wavefront_prefill: + return batch if scheduler.has_ready(RequestPhase.SPECULATIVE): return scheduler._take(RequestPhase.SPECULATIVE) return None diff --git a/vllm_rlt/engine/stage_engine.py b/vllm_rlt/engine/stage_engine.py index 7453612d..3bf247da 100644 --- a/vllm_rlt/engine/stage_engine.py +++ b/vllm_rlt/engine/stage_engine.py @@ -323,6 +323,7 @@ def __init__( speculative=speculative_config, staged_prefill=staged_prefill, fp8_scale=fp8_scale, + attention=attention, ) self.cache_manager = KVCacheManager( num_layers=kv_layers, diff --git a/vllm_rlt/entrypoints/cli.py b/vllm_rlt/entrypoints/cli.py index e34f832b..fbd1a6c1 100644 --- a/vllm_rlt/entrypoints/cli.py +++ b/vllm_rlt/entrypoints/cli.py @@ -138,6 +138,7 @@ def main(): mode=args.mode, prefill_chunk_size=getattr(args, "prefill_chunk_size", 128), wavefront_chunked_prefill=getattr(args, "wavefront_chunked_prefill", False), + adaptive_wavefront_prefill=getattr(args, "adaptive_wavefront_prefill", False), max_prefill_batches_before_decode=getattr(args, "max_prefill_batches_before_decode", 1), admission_scan_limit=getattr(args, "admission_scan_limit", 64), max_admission_bypasses=getattr(args, "max_admission_bypasses", 8), diff --git a/vllm_rlt/entrypoints/pd_serve.py b/vllm_rlt/entrypoints/pd_serve.py index 6283fe5e..77a64220 100644 --- a/vllm_rlt/entrypoints/pd_serve.py +++ b/vllm_rlt/entrypoints/pd_serve.py @@ -63,6 +63,7 @@ def load_engine(args): max_num_batched_tokens=args.prefill_max_num_batched_tokens, prefill_chunk_size=args.prefill_chunk_size, wavefront_chunked_prefill=getattr(args, "wavefront_chunked_prefill", False), + adaptive_wavefront_prefill=getattr(args, "adaptive_wavefront_prefill", False), ), decode_scheduler_config=SchedulerConfig( policy=getattr(args, "scheduling_policy", "fcfs"), diff --git a/vllm_rlt/entrypoints/runtime_args.py b/vllm_rlt/entrypoints/runtime_args.py index c02db413..f8feefce 100644 --- a/vllm_rlt/entrypoints/runtime_args.py +++ b/vllm_rlt/entrypoints/runtime_args.py @@ -110,6 +110,11 @@ def add_runtime_args(parser): action="store_true", help="Batch ready prompt chunks across recurrence depths", ) + parser.add_argument( + "--adaptive-wavefront-prefill", + action="store_true", + help="Adapt wavefront chunk and batch sizes within the configured upper limits", + ) parser.add_argument("--max-prefill-batches-before-decode", type=int, default=1) parser.add_argument("--admission-scan-limit", type=int, default=64) parser.add_argument("--max-admission-bypasses", type=int, default=8) diff --git a/vllm_rlt/entrypoints/serve.py b/vllm_rlt/entrypoints/serve.py index 1a68f520..3581f4c7 100644 --- a/vllm_rlt/entrypoints/serve.py +++ b/vllm_rlt/entrypoints/serve.py @@ -61,6 +61,7 @@ def load_engine(args): mode=args.mode, prefill_chunk_size=getattr(args, "prefill_chunk_size", 128), wavefront_chunked_prefill=getattr(args, "wavefront_chunked_prefill", False), + adaptive_wavefront_prefill=getattr(args, "adaptive_wavefront_prefill", False), max_prefill_batches_before_decode=getattr(args, "max_prefill_batches_before_decode", 1), admission_scan_limit=getattr(args, "admission_scan_limit", 64), max_admission_bypasses=getattr(args, "max_admission_bypasses", 8), diff --git a/vllm_rlt/request.py b/vllm_rlt/request.py index 66322808..2d8bd4e6 100644 --- a/vllm_rlt/request.py +++ b/vllm_rlt/request.py @@ -68,6 +68,8 @@ class Request: finish_reason: FinishReason | None = None exit_trace: tuple[int, ...] = field(default=(), repr=False) _target_loops: int | None = field(default=None, repr=False) + # Fixed at wavefront admission so in-flight ring offsets keep their meaning. + prefill_chunk_size: int | None = None def __post_init__(self): if self._target_loops is not None and (