vllm.v1.core.sched.interface
¶
Classes:
-
PauseState–Scheduler pause state.
-
SchedulerInterface–
PauseState
¶
Bases: IntEnum
Scheduler pause state.
- UNPAUSED: Normal operation
- PAUSE_NEW: No new requests are scheduled, requests already in running state or holding KV blocks are scheduled.
- PAUSE_ALL: No requests are scheduled
SchedulerInterface
¶
Bases: ABC
Methods:
-
add_request–Add a new request to the scheduler's internal queue.
-
finish_requests–Finish the requests in the scheduler's internal queue. If the request
-
get_kv_cache_usage–Returns the fraction of the KV cache currently in use (0.0-1.0).
-
get_num_unfinished_requests–Number of unfinished requests in the scheduler's internal queue.
-
get_request_counts–Returns (num_running_reqs, num_waiting_reqs).
-
has_finished_requests–Returns True if there are finished requests that need to be cleared.
-
has_request–Returns True if the scheduler holds the request, including an open
-
has_requests–Returns True if there are unfinished requests, or finished requests
-
has_unfinished_requests–Returns True if there are unfinished requests in the scheduler's
-
make_stats–Make a SchedulerStats object for logging.
-
reset_encoder_cache–Reset the encoder cache to invalidate all cached encoder outputs.
-
reset_prefix_cache–Reset the prefix cache for KV cache.
-
schedule–Schedule the requests to process in this scheduling step.
-
should_schedule–Whether the engine should schedule another step now, rather than wait
-
shutdown–Shutdown the scheduler.
-
update_draft_token_ids–Update requests with newly generated draft token ids, applying
-
update_draft_token_ids_in_output–Update scheduler output with newly generated draft token ids, applying
-
update_from_output–Update the scheduler state based on the model runner output.
Attributes:
-
pause_state(PauseState) –Current pause state of the scheduler.
pause_state
abstractmethod
property
¶
Current pause state of the scheduler.
add_request(request)
abstractmethod
¶
finish_requests(request_ids, finished_status)
abstractmethod
¶
Finish the requests in the scheduler's internal queue. If the request is not in the queue, this method will do nothing for that request.
This method is called in two cases: 1. When the request is aborted by the client. 2. When the frontend process detects a stop string of the request after de-tokenizing its generated tokens.
Parameters:
-
(request_ids¶str | Iterable[str] | None) –A single or a list of request IDs, or None to finish all.
-
(finished_status¶RequestStatus) –The finished status of the given requests.
Returns:
get_kv_cache_usage()
¶
Returns the fraction of the KV cache currently in use (0.0-1.0).
get_num_unfinished_requests()
abstractmethod
¶
Number of unfinished requests in the scheduler's internal queue.
get_request_counts()
abstractmethod
¶
Returns (num_running_reqs, num_waiting_reqs).
has_finished_requests()
abstractmethod
¶
Returns True if there are finished requests that need to be cleared.
NOTE: This is different from not self.has_unfinished_requests().
The scheduler maintains an internal list of the requests finished in the previous step. This list is returned from the next call to schedule(), to be sent to the model runner in the next step to clear cached states for these finished requests.
This method checks if this internal list of finished requests is non-empty. This information is useful for DP attention.
has_request(request_id)
abstractmethod
¶
Returns True if the scheduler holds the request, including an open streaming-input session waiting for its next input.
has_requests()
¶
Returns True if there are unfinished requests, or finished requests not yet returned in SchedulerOutputs.
has_unfinished_requests()
¶
Returns True if there are unfinished requests in the scheduler's internal queue.
make_stats()
abstractmethod
¶
Make a SchedulerStats object for logging.
The SchedulerStats object is created for every scheduling step.
reset_encoder_cache()
abstractmethod
¶
Reset the encoder cache to invalidate all cached encoder outputs.
This should be called when model weights are updated to ensure stale vision embeddings are not reused.
reset_prefix_cache(reset_running_requests=False, reset_connector=False)
abstractmethod
¶
Reset the prefix cache for KV cache.
This is particularly required when the model weights are live-updated.
Parameters:
-
(reset_running_requests¶bool, default:False) –If True, all the running requests will be preempted and moved to the waiting queue. Otherwise, this method will only reset the KV prefix cache when there is no running request taking KV cache.
-
(reset_connector¶bool, default:False) –If True, also reset any KV connector state.
schedule(throttle_prefills=False)
abstractmethod
¶
Schedule the requests to process in this scheduling step.
The scheduling decision is made at the iteration level. Each scheduling step corresponds to a single forward pass of the model. Therefore, this method is called repeatedly by a busy loop in the engine.
Essentially, the scheduler produces a dictionary of {req_id: num_tokens} that specifies how many tokens to process for each request in this scheduling step. For example, num_tokens can be as large as the number of prompt tokens for new requests, or it can be 1 for the requests that are auto-regressively generating new tokens one by one. Otherwise, it can be somewhere in between in case of chunked prefills, prefix caching, speculative decoding, etc.
Additionally, the scheduler also returns useful data about each request or the batch as a whole. The model runner will use this information in preparing inputs to the model.
Parameters:
-
(throttle_prefills¶bool, default:False) –When True (set by the engine core on steps between
prefill_schedule_intervalmultiples), new prefill compute is deferred to a later step; automatically overridden when the engine is saturated.
Returns:
-
SchedulerOutput–A SchedulerOutput object containing information about the scheduled
-
SchedulerOutput–requests.
should_schedule()
¶
Whether the engine should schedule another step now, rather than wait for an in-flight one.
shutdown()
abstractmethod
¶
Shutdown the scheduler.
update_draft_token_ids(draft_token_ids)
abstractmethod
¶
Update requests with newly generated draft token ids, applying structured output grammar validation if needed.
Parameters:
-
(draft_token_ids¶DraftTokenIds) –The input draft token ids for each request.
update_draft_token_ids_in_output(draft_token_ids, scheduler_output)
abstractmethod
¶
Update scheduler output with newly generated draft token ids, applying structured output grammar validation if needed.
Parameters:
-
(draft_token_ids¶DraftTokenIds) –The input draft token ids for each request.
-
(scheduler_output¶SchedulerOutput) –Update the given scheduler_output with the corresponding draft token ids.
update_from_output(scheduler_output, model_runner_output)
abstractmethod
¶
Update the scheduler state based on the model runner output.
This method is called after the model runner has processed the scheduled requests. The model runner output includes generated token ids, draft token ids for next step, etc. The scheduler uses this information to update its states, checks the finished requests, and returns the output for each request.
Returns: