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
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 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 | |
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 | None | Individual request information, or | 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', stopping_scope='current')
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' |
stopping_scope | Literal['current', 'all'] | Whether to halt only the current benchmark or also prevent escalation to subsequent rates/streams. (default: "current") | 'current' |
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
OverSaturationConstraintInitializer
Bases: PydanticConstraintInitializer
Factory for creating OverSaturationConstraint instances from configuration.
Stores an OverSaturationConstraintArgs instance and delegates to OverSaturationConstraint in create_constraint().
Example: ::
from guidellm.schemas.scheduler 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
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 | |
__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.
The approximation is within 0.5% of the exact quantile for ten or more degrees of freedom and degrades below that, reaching 49% low at one degree of freedom. Use t_ppf where small-sample accuracy matters.
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 |