guidellm.scheduler
AsyncConstantStrategy
Bases: ThroughputStrategy
A class representing an asynchronous constant scheduling strategy. This strategy schedules requests asynchronously at a constant request rate in requests per second. If initial_burst is set, it will send an initial burst of math.floor(rate) requests to reach the target rate. This is useful to ensure that the target rate is reached quickly and then maintained. It inherits from the SchedulingStrategy
base class and implements the request_times
method to provide the specific behavior for asynchronous constant scheduling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | The constant StrategyType to schedule requests asynchronously. | required | |
rate | The rate at which to schedule requests asynchronously in requests per second. This must be a positive float. | required | |
initial_burst | True to send an initial burst of requests (math.floor(self.rate)) to reach target rate. False to not send an initial burst. | required |
Source code in src/guidellm/scheduler/strategy.py
request_times()
A generator that yields timestamps for when requests should be sent. This method schedules requests asynchronously at a constant rate in requests per second. If burst_time is set, it will send an initial burst of requests to reach the target rate. This is useful to ensure that the target rate is reached quickly and then maintained.
Returns:
Type | Description |
---|---|
Generator[float, None, None] | A generator that yields timestamps for request scheduling. |
Source code in src/guidellm/scheduler/strategy.py
AsyncPoissonStrategy
Bases: ThroughputStrategy
A class representing an asynchronous Poisson scheduling strategy. This strategy schedules requests asynchronously at a Poisson request rate in requests per second. If initial_burst is set, it will send an initial burst of math.floor(rate) requests to reach the target rate. It inherits from the SchedulingStrategy
base class and implements the request_times
method to provide the specific behavior for asynchronous Poisson scheduling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | The Poisson StrategyType to schedule requests asynchronously. | required | |
rate | The rate at which to schedule requests asynchronously in requests per second. This must be a positive float. | required | |
initial_burst | True to send an initial burst of requests (math.floor(self.rate)) to reach target rate. False to not send an initial burst. | required |
Source code in src/guidellm/scheduler/strategy.py
request_times()
A generator that yields timestamps for when requests should be sent. This method schedules requests asynchronously at a Poisson rate in requests per second. The inter arrival time between requests is exponentially distributed based on the rate.
Returns:
Type | Description |
---|---|
Generator[float, None, None] | A generator that yields timestamps for request scheduling. |
Source code in src/guidellm/scheduler/strategy.py
ConcurrentStrategy
Bases: SchedulingStrategy
A class representing a concurrent scheduling strategy. This strategy schedules requests concurrently with the specified number of streams. It inherits from the SchedulingStrategy
base class and implements the request_times
method to provide the specific behavior for concurrent scheduling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | The concurrent StrategyType to schedule requests concurrently. | required | |
streams | The number of concurrent streams to use for scheduling requests. Each stream runs synchronously with the maximum rate possible. This must be a positive integer. | required |
Source code in src/guidellm/scheduler/strategy.py
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
processes_limit
property
The limit on the number of worker processes for the scheduling strategy. It determines how many worker processes are created for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
int | {self.streams} for the concurrent scheduling strategy to limit the worker processes to the number of streams. |
processing_mode
property
The processing mode for the scheduling strategy, either 'sync' or 'async'. This property determines how the worker processes are setup: either to run synchronously with one request at a time or asynchronously.
Returns:
Type | Description |
---|---|
Literal['sync'] | 'sync' for synchronous scheduling strategy for the multiple worker processes equal to streams. |
processing_requests_limit
property
The maximum number of processing requests for the scheduling strategy. It determines how many requests can be processed at one time for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
int | {self.streams} for the concurrent scheduling strategy to limit the processing requests to the number of streams that ready to be processed. |
queued_requests_limit
property
The maximum number of queued requests for the scheduling strategy. It determines how many requests can be queued at one time for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
int | {self.streams} for the concurrent scheduling strategy to limit the queued requests to the number of streams that are ready to be processed. |
request_times()
A generator that yields time.time() so requests are sent immediately, while scheduling them concurrently with the specified number of streams.
Returns:
Type | Description |
---|---|
Generator[float, None, None] | A generator that yields time.time() for immediate request scheduling. |
Source code in src/guidellm/scheduler/strategy.py
GenerativeRequestsWorker
Bases: RequestsWorker[GenerationRequest, ResponseSummary]
A class that handles the execution of requests using a backend. This class is responsible for sending requests to the backend, handling responses, and managing errors.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
backend | Backend | The backend to use for handling requests. This should be an instance of Backend such as an OpenAIHTTPBackend. | required |
Source code in src/guidellm/scheduler/worker.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 |
|
description
property
Get the description of the worker.
Returns:
Type | Description |
---|---|
GenerativeRequestsWorkerDescription | The description of the worker. |
prepare_multiprocessing()
async
Prepare the worker for multiprocessing. This is useful for workers that have instance state that can not be shared across processes and should be cleared out and re-initialized for each new process.
Source code in src/guidellm/scheduler/worker.py
resolve(request, timeout_time)
async
Resolve a request by sending it to the backend and handling the response. This method sends the request to the backend, waits for a response, and handles any errors that may occur during the process.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request | GenerationRequest | The request to resolve. | required |
timeout_time | float | The time to wait for a response before timing out. If timeout_time is math.inf, the request will not timeout. | required |
Returns:
Type | Description |
---|---|
tuple[ResolveStatus, ResponseSummary] | A ResponseSummary object containing the response from the backend. If an error occurs, the ResponseSummary will contain the error message. |
Source code in src/guidellm/scheduler/worker.py
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
|
RequestsWorker
Bases: ABC
, Generic[RequestT, ResponseT]
An abstract base class for a worker that processes requests. This class defines the interface for a worker that can resolve requests asynchronously or synchronously within the Scheduler class. Subclasses must implement the resolve
method, which takes a request directly given from the load generator, along with the desired start_time for the request and a timeout_time. The resolve
method should return the response from the backend.
Source code in src/guidellm/scheduler/worker.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 |
|
description
abstractmethod
property
An abstract property that must be implemented by subclasses. This property should return a Serializable class representing the information about the worker instance.
prepare_multiprocessing()
abstractmethod
async
An abstract method that must be implemented by subclasses. This is useful for workers that have instance state that can not be shared across processes and should be cleared out and re-initialized for each new process.
Source code in src/guidellm/scheduler/worker.py
resolve(request, timeout_time)
abstractmethod
async
An abstract method that must be implemented by subclasses. This method should handle the resolution of a request through asyncio, including any necessary backend processing and response handling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
request | RequestT | The request to be resolved generated by the load generator. | required |
timeout_time | float | The timeout time for the request, if there is no timeout given, then this will be math.inf. | required |
Returns:
Type | Description |
---|---|
tuple[ResolveStatus, ResponseT] | The response from the worker. |
Source code in src/guidellm/scheduler/worker.py
Scheduler
Bases: Generic[RequestT, ResponseT]
A class that handles the scheduling of requests to a worker. This class is responsible for managing the lifecycle of the requests, including their creation, queuing, and processing. It uses a multiprocessing approach to handle requests concurrently and efficiently, based on the specified scheduling strategy. The Scheduler class is designed to work with a RequestsWorker, which is an abstract base class that defines the interface for a worker that can resolve requests asynchronously or synchronously. The Scheduler class also supports different scheduling strategies, including synchronous, throughput, and concurrent strategies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
worker | RequestsWorker[RequestT, ResponseT] | The worker that will process the requests. This should be an instance of RequestsWorker. | required |
request_loader | Iterable[RequestT] | An iterable that generates requests. This can be a list, generator, or any other iterable. The requests will be processed by the worker. | required |
Source code in src/guidellm/scheduler/scheduler.py
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
|
run(scheduling_strategy, max_number=None, max_duration=None)
async
The main method that runs the scheduler. This method is a generator that yields SchedulerResult objects at the start and end of the run, as well as at the start and end of each request. It uses multiprocessing to handle requests concurrently and efficiently, based on the specified scheduling strategy. The method also handles the lifecycle of the requests, including their creation, queuing, and processing. The method is designed to be used as an asynchronous generator, allowing it to be used with asyncio and other asynchronous frameworks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
scheduling_strategy | SchedulingStrategy | The scheduling strategy to use. Specifies the times at which requests will be sent as well how many worker processes are used and if requests are scheduled sync or async. This can be one of the following: - "synchronous": Requests are sent synchronously. - "throughput": Requests are sent at the maximum rate possible. - An instance of SchedulingStrategy. | required |
max_number | Optional[int] | The maximum number of requests to process. If None, then no limit is set and either the iterator must be exhaustible or the max_duration must be set. | None |
max_duration | Optional[float] | The maximum duration for the scheduling run. If None, then no limit is set and either the iterator must be exhaustible or the max_number must be set. | None |
Returns:
Type | Description |
---|---|
AsyncGenerator[Union[SchedulerResult, SchedulerRequestResult[RequestT, ResponseT]], None] | An asynchronous generator that yields SchedulerResult objects. Each SchedulerResult object contains information about the request, the response, and the run information. |
Source code in src/guidellm/scheduler/scheduler.py
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 |
|
SchedulerRequestInfo
Bases: StandardBaseModel
Information about a specific request run through the scheduler. This class holds metadata about the request, including the targeted start time, queued time, start time, end time, and the process ID that handled the request.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
targeted_start_time | The targeted start time for the request (time.time()). | required | |
queued_time | The time the request was queued (time.time()). | required | |
scheduled_time | The time the request was scheduled (time.time()) (any sleep time before the request was sent to the worker). | required | |
worker_start | The time the worker started processing request (time.time()). | required | |
worker_end | The time the worker finished processing request. (time.time()). | required | |
process_id | The ID of the underlying process that handled the request. | required |
Source code in src/guidellm/scheduler/result.py
SchedulerResult
Bases: StandardBaseModel
The yielded, iterative result for a scheduler run. These are triggered on the start and end of the run, as well as on the start and end of each request. Depending on the type, it will hold the request and response along with information and statistics about the request and general run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | The type of the result, which can be one of: - "run_start": Indicates the start of the run. - "run_complete": Indicates the completion of the run (teardown happens after). - "request_start": Indicates the start of a request. - "request_complete": Indicates the completion of a request. | required | |
request | The request that was processed. | required | |
response | The response from the worker for the request. | required | |
request_info | Information about the request, including the targeted start time, queued time, start time, end time, and the process ID that handled the request. | required | |
run_info | Information about the current run of the scheduler, including the start and end times, the number of processes, and the scheduling strategy used. It also tracks the number of requests created, queued, pending, and completed during the run. | required |
Source code in src/guidellm/scheduler/result.py
SchedulerRunInfo
Bases: StandardBaseModel
Information about the current run of the scheduler. This class holds metadata about the scheduling run, including the start and end times, the number of processes, and the scheduling strategy used. It also tracks the number of requests created, queued, pending, and completed during the run.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
start_time | The start time of the scheduling run. | required | |
end_time | The end time of the scheduling run; if None, then this will be math.inf. | required | |
end_number | The maximum number of requests to be processed; if None, then this will be math.inf. | required | |
processes | The number of processes used in the scheduling run. | required | |
strategy | The scheduling strategy used in the run. This should be an instance of SchedulingStrategy. | required | |
created_requests | The number of requests created during the run. | required | |
queued_requests | The number of requests queued during the run. | required | |
scheduled_requests | The number of requests scheduled during the run. (requests pending being sent to the worker but recieved by a process) | required | |
processing_requests | The number of requests actively being run. | required | |
completed_requests | The number of requests completed during the run. | required |
Source code in src/guidellm/scheduler/result.py
SchedulingStrategy
Bases: StandardBaseModel
An abstract base class for scheduling strategies. This class defines the interface for scheduling requests and provides a common structure for all scheduling strategies. Subclasses should implement the request_times
method to provide specific scheduling behavior.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | The type of scheduling strategy to use. This should be one of the predefined strategy types. | required |
Source code in src/guidellm/scheduler/strategy.py
processes_limit
property
The limit on the number of worker processes for the scheduling strategy. It determines how many worker processes are created for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
int | The number of processes for the scheduling strategy. |
processing_mode
property
The processing mode for the scheduling strategy, either 'sync' or 'async'. This property determines how the worker processes are setup: either to run synchronously with one request at a time or asynchronously. This property should be implemented by subclasses to return the appropriate processing mode.
Returns:
Type | Description |
---|---|
Literal['sync', 'async'] | The processing mode for the scheduling strategy, either 'sync' or 'async'. |
processing_requests_limit
property
The maximum number of processing requests for the scheduling strategy. It determines how many requests can be processed at one time for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
int | The maximum number of processing requests for the scheduling strategy. |
queued_requests_limit
property
The maximum number of queued requests for the scheduling strategy. It determines how many requests can be queued at one time for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
Optional[int] | The maximum number of queued requests for the scheduling strategy. |
request_times()
A generator that yields timestamps for when requests should be sent. This method should be implemented by subclasses to provide specific scheduling behavior.
Returns:
Type | Description |
---|---|
Generator[float, None, None] | A generator that yields timestamps for request scheduling or -1 for requests that should be sent immediately. |
Source code in src/guidellm/scheduler/strategy.py
SynchronousStrategy
Bases: SchedulingStrategy
A class representing a synchronous scheduling strategy. This strategy schedules requests synchronously, one at a time, with the maximum rate possible. It inherits from the SchedulingStrategy
base class and implements the request_times
method to provide the specific behavior for synchronous scheduling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | The synchronous StrategyType to schedule requests synchronously. | required |
Source code in src/guidellm/scheduler/strategy.py
processes_limit
property
The limit on the number of worker processes for the scheduling strategy. It determines how many worker processes are created for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
int | 1 for the synchronous scheduling strategy to limit the worker processes to one. |
processing_mode
property
The processing mode for the scheduling strategy, either 'sync' or 'async'. This property determines how the worker processes are setup: either to run synchronously with one request at a time or asynchronously.
Returns:
Type | Description |
---|---|
Literal['sync'] | 'sync' for synchronous scheduling strategy for the single worker process. |
processing_requests_limit
property
The maximum number of processing requests for the scheduling strategy. It determines how many requests can be processed at one time for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
int | 1 for the synchronous scheduling strategy to limit the processing requests to one that is ready to be processed. |
queued_requests_limit
property
The maximum number of queued requests for the scheduling strategy. It determines how many requests can be queued at one time for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
int | 1 for the synchronous scheduling strategy to limit the queued requests to one that is ready to be processed. |
request_times()
A generator that yields time.time() so requests are sent immediately, while scheduling them synchronously.
Returns:
Type | Description |
---|---|
Generator[float, None, None] | A generator that yields time.time() for immediate request scheduling. |
Source code in src/guidellm/scheduler/strategy.py
ThroughputStrategy
Bases: SchedulingStrategy
A class representing a throughput scheduling strategy. This strategy schedules as many requests asynchronously as possible, with the maximum rate possible. It inherits from the SchedulingStrategy
base class and implements the request_times
method to provide the specific behavior for throughput scheduling.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
type_ | The throughput StrategyType to schedule requests asynchronously. | required |
Source code in src/guidellm/scheduler/strategy.py
processing_mode
property
The processing mode for the scheduling strategy, either 'sync' or 'async'. This property determines how the worker processes are setup: either to run synchronously with one request at a time or asynchronously.
Returns:
Type | Description |
---|---|
Literal['async'] | 'async' for asynchronous scheduling strategy for the multiple worker processes handling requests. |
processing_requests_limit
property
The maximum number of processing requests for the scheduling strategy. It determines how many requests can be processed at one time for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
int | {self.max_concurrency} for the throughput scheduling strategy to limit the processing requests to the maximum concurrency. If max_concurrency is None, then the default processing requests limit will be used. |
queued_requests_limit
property
The maximum number of queued requests for the scheduling strategy. It determines how many requests can be queued at one time for the scheduling strategy and must be implemented by subclasses.
Returns:
Type | Description |
---|---|
int | The processing requests limit to ensure that there are enough requests even for the worst case scenario where the max concurrent requests are pulled at once for processing. |
request_times()
A generator that yields the start time.time() so requests are sent immediately, while scheduling as many asynchronously as possible.
Returns:
Type | Description |
---|---|
Generator[float, None, None] | A generator that yields the start time.time() for immediate request scheduling. |