guidellm.scheduler.constraints.saturation
Over-saturation detection constraint implementation.
This module implements the Over-Saturation Detection (OSD) algorithm for detecting when a model becomes over-saturated during benchmarking. Over-saturation occurs when the response rate doesn't keep up with the request rate, leading to degraded performance.
Algorithm Overview:
The OSD algorithm uses statistical slope detection to identify over-saturation:
- Slope Detection: The algorithm tracks two key metrics over time:
- Concurrent requests: Number of requests being processed simultaneously
-
Time-to-first-token (TTFT): Latency for the first token of each response
-
Statistical Analysis: For each metric, the algorithm:
- Maintains a sliding window of recent data points
- Calculates the linear regression slope using online statistics
- Computes the margin of error (MOE) using t-distribution confidence intervals
-
Detects positive slopes with low MOE, indicating degradation
-
Detection Criteria: Over-saturation is detected when:
- Both concurrent requests and TTFT show statistically significant positive slopes
- The minimum duration threshold has been met
-
Sufficient data points are available for reliable slope estimation
-
Window Management: The algorithm maintains bounded memory by:
- Limiting window size by time (maximum_window_seconds)
- Limiting window size by ratio of total requests (maximum_window_ratio)
-
Automatically pruning old data points
-
Constraint Integration: When over-saturation is detected, the constraint:
- Stops request queuing to prevent further degradation
- Stops processing of existing requests (in active mode)
- Provides detailed metadata about detection state
Key Parameters:
- minimum_duration: Minimum seconds before checking for over-saturation (default: 30.0)
- minimum_ttft: Minimum TTFT threshold for violation counting (default: 2.5)
- maximum_window_seconds: Maximum time window for data retention (default: 120.0)
- moe_threshold: Margin of error threshold for slope detection (default: 2.0)
- maximum_window_ratio: Maximum window size as ratio of total requests (default: 0.75)
- minimum_window_size: Minimum data points required for slope estimation (default: 5)
- confidence: Statistical confidence level for t-distribution (default: 0.95)
The constraint integrates with the scheduler by evaluating each request update and providing scheduler actions (continue/stop) based on the current over-saturation state.
OverSaturationConstraint
Bases: Constraint
Constraint that detects and stops execution when over-saturation is detected.
This constraint implements the Over-Saturation Detection (OSD) algorithm to identify when a model becomes over-saturated (response rate doesn't keep up with request rate). When over-saturation is detected, the constraint stops request queuing and optionally stops processing of existing requests.
The constraint maintains internal state for tracking concurrent requests and time-to-first-token (TTFT) metrics, using statistical slope detection to identify performance degradation patterns.
Source code in src/guidellm/scheduler/constraints/saturation.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 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 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 | |
info property
Get current constraint configuration and state information.
Returns:
| Type | Description |
|---|---|
dict[str, Any] | Dictionary containing configuration parameters. |
__call__(state, request_info)
Evaluate constraint against current scheduler state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state | SchedulerState | Current scheduler state. | required |
request_info | RequestInfo | Individual request information. | required |
Returns:
| Type | Description |
|---|---|
SchedulerUpdateAction | Action indicating whether to continue or stop operations. |
Source code in src/guidellm/scheduler/constraints/saturation.py
__init__(minimum_duration=30.0, minimum_ttft=2.5, maximum_window_seconds=120.0, moe_threshold=2.0, maximum_window_ratio=0.75, minimum_window_size=5, confidence=0.95, eps=1e-12, mode='enforce')
Initialize the over-saturation constraint.
Creates a new constraint instance with specified detection parameters. The constraint will track concurrent requests and TTFT metrics, using statistical slope detection to identify when the model becomes over-saturated. All parameters have sensible defaults suitable for most benchmarking scenarios.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
minimum_duration | float | Minimum seconds before checking for over-saturation (default: 30.0) | 30.0 |
minimum_ttft | float | Minimum TTFT threshold in seconds for violation counting (default: 2.5) | 2.5 |
maximum_window_seconds | float | Maximum time window in seconds for data retention (default: 120.0) | 120.0 |
moe_threshold | float | Margin of error threshold for slope detection (default: 2.0) | 2.0 |
maximum_window_ratio | float | Maximum window size as ratio of total requests (default: 0.75) | 0.75 |
minimum_window_size | int | Minimum data points required for slope estimation (default: 5) | 5 |
confidence | float | Statistical confidence level for t-distribution (0-1) (default: 0.95) | 0.95 |
eps | float | Epsilon for numerical stability in calculations (default: 1e-12) | 1e-12 |
mode | Literal['enforce', 'monitor'] | Whether to stop when over-saturation is detected, or only monitor (default: "enforce") | 'enforce' |
Source code in src/guidellm/scheduler/constraints/saturation.py
reset()
Reset all internal state to initial values.
Clears all tracked requests, resets counters, and reinitializes slope checkers. Useful for reusing constraint instances across multiple benchmark runs or resetting state after configuration changes.
Source code in src/guidellm/scheduler/constraints/saturation.py
OverSaturationConstraintArgs
Bases: ConstraintArgs
Arguments for over-saturation detection constraint.
Detects when a model becomes over-saturated using statistical slope analysis of concurrent requests and time-to-first-token metrics.
Attributes:
| Name | Type | Description |
|---|---|---|
kind | Literal['over_saturation'] | Always "over_saturation" |
Source code in src/guidellm/scheduler/constraints/saturation.py
OverSaturationConstraintInitializer
Bases: PydanticConstraintInitializer
Factory for creating OverSaturationConstraint instances from configuration.
Stores an OverSaturationConstraintArgs instance and delegates to OverSaturationConstraint in create_constraint().
Example: ::
from guidellm.scheduler.constraints import OverSaturationConstraintArgs
args = OverSaturationConstraintArgs(mode="enforce", min_seconds=60.0)
initializer = OverSaturationConstraintInitializer(args=args)
constraint = initializer.create_constraint()
Source code in src/guidellm/scheduler/constraints/saturation.py
create_constraint(**_kwargs)
Create an OverSaturationConstraint instance from stored args.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
_kwargs | Additional keyword arguments (unused) | {} |
Returns:
| Type | Description |
|---|---|
Constraint | Configured OverSaturationConstraint instance ready for use |
Source code in src/guidellm/scheduler/constraints/saturation.py
SlopeChecker
Helper class for online slope detection using linear regression.
Maintains running statistics for efficient O(1) updates and provides statistical slope detection with margin of error calculation. Uses online algorithms to compute linear regression statistics incrementally without storing all data points, enabling memory-efficient slope detection for over-saturation detection. Supports adding and removing data points dynamically while maintaining accurate statistical measures.
Example: :: checker = SlopeChecker(moe_threshold=2.0, confidence=0.95) checker.add_data_point(1.0, 2.0) checker.add_data_point(2.0, 3.0) checker.add_data_point(3.0, 4.0) is_positive = checker.check_slope(3.0) # True for positive slope
Source code in src/guidellm/scheduler/constraints/saturation.py
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 | |
__init__(moe_threshold=1.0, confidence=0.95, eps=1e-12)
Initialize slope checker with statistical parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
moe_threshold | float | Maximum margin of error threshold for slope detection | 1.0 |
confidence | float | Statistical confidence level for t-distribution (0-1) | 0.95 |
eps | float | Epsilon value for numerical stability in calculations | 1e-12 |
Source code in src/guidellm/scheduler/constraints/saturation.py
add_data_point(x_new, y_new)
Integrate a new data point into the accumulated statistics.
Updates running sums for linear regression calculation in O(1) time. The data point is incorporated into the statistical model without storing the individual value, enabling memory-efficient slope detection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_new | float | The new x-coordinate (typically time or duration) | required |
y_new | float | The new y-coordinate (typically metric value like TTFT or concurrent requests) | required |
Source code in src/guidellm/scheduler/constraints/saturation.py
check_slope(effective_n)
Check if there is a statistically significant positive slope.
Calculates linear regression slope and margin of error using online statistics. Returns True if the slope is positive and the margin of error is below the threshold, indicating statistically significant degradation. Updates internal slope and margin_of_error attributes for external inspection.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
effective_n | float | Effective sample size for slope estimation (may differ from actual n for correlation adjustment) | required |
Returns:
| Type | Description |
|---|---|
bool | True if positive slope detected with margin of error below threshold |
Source code in src/guidellm/scheduler/constraints/saturation.py
remove_data_point(x_old, y_old)
Remove a data point from the accumulated statistics.
Updates running sums by subtracting the specified data point in O(1) time. Used for window management when pruning old data points to maintain bounded memory usage while preserving statistical accuracy.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x_old | float | The x-coordinate to remove (typically time or duration) | required |
y_old | float | The y-coordinate to remove (typically metric value) | required |
Source code in src/guidellm/scheduler/constraints/saturation.py
approx_t_ppf(p, df)
Approximate the percent point function (PPF) for the t-distribution.
Provides a fast approximation of the t-distribution PPF using numerical methods from Abramowitz & Stegun. This function is significantly faster than scipy.stats.t.ppf while providing sufficient accuracy for statistical slope detection in over-saturation detection. Used internally by SlopeChecker for calculating confidence intervals and margin of error.
Reference: Milton Abramowitz and Irene A. Stegun (Eds.). (1965). Handbook of Mathematical Functions: with Formulas, Graphs, and Mathematical Tables. Dover Publications.
An electronic version of this book is available at:
https://personal.math.ubc.ca/~cbm/aands/.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
p | float | The probability value (e.g., 0.975 for a 95% confidence interval) | required |
df | float | The degrees of freedom for the t-distribution | required |
Returns:
| Type | Description |
|---|---|
float | Approximate t-distribution PPF value, or NaN if df <= 0 |