profile
zeus.profile
Thermally stable energy profiling for GPU workloads.
See our blog post for more details: Thermally Stable Profiling for Accurate GPU Energy Measurement
Public API
profile_parameters-- auto-profile both measurement and cooldown durations.profile_measurement_duration-- sweep measurement durations only.profile_cooldown_duration-- sweep cooldown durations only.measure-- run a single energy measurement trial with known measurement and cooldown durations.
Overview
The module provides functions to determine the best measurement and cooldown durations that yield stable (low-variance) energy measurements for a user-provided callable.
Single trial
============
|<--- cooldown_duration --->| |<--- measurement_duration --->|
| | | |
+----------- idle ----------+-- warmup --+--iter--iter-- ... --iter-----+
| |
+-- energy_per_iter measured --+
Sweep (num_trials = 3, num_warmup_trials = 1)
======================
Warmup trial: [--iter--iter--...--iter--]
Trial 1: [--- cooldown ---|-- warmup --|--iter--iter--...--iter--]
Trial 2: [--- cooldown ---|-- warmup --|--iter--iter--...--iter--]
Trial 3: [--- cooldown ---|-- warmup --|--iter--iter--...--iter--]
\________________________/
measurement_duration=5.0 s [VALID] std of energy_per_iter
< trial_stddev_threshold
Measurement duration sweep: fixes cooldown_duration at the maximum of the
cooldown search range and sweeps measurement_duration. Each configuration is
measured for num_trials trials; configurations whose energy standard
deviation falls below trial_stddev_threshold are considered valid.
Cooldown duration sweep: fixes measurement_duration at the maximum of the measurement search range and sweeps cooldown_duration with the same validity criterion.
Both durations can also be chosen manually and passed directly to
measure.
Multi-GPU / distributed setting: In a distributed setting each rank should
create its own ZeusMonitor with
gpu_indices=[local_rank] and pass it to the profiling functions. Every
rank executes the workload and measures energy on its local GPU.
all_reduce is used internally to
aggregate results across ranks (energy is summed, time takes the max across
ranks, and temperature is averaged). Only rank 0 logs progress and reports.
TrialResult
dataclass
Result of a single measurement trial.
Attributes:
| Name | Type | Description |
|---|---|---|
energy_per_iter |
float
|
Energy consumed per iteration (Joules). |
time_per_iter |
float
|
Wall-clock time per iteration (seconds). |
total_energy |
float
|
Total energy consumed during the measurement window (Joules). |
total_time |
float
|
Total wall-clock time of the measurement window (seconds). |
iterations |
int
|
Number of iterations executed in the window. |
temperature_before |
float
|
GPU temperature (Celsius) before the measurement. |
temperature_after |
float
|
GPU temperature (Celsius) after the measurement. |
Source code in zeus/profile.py
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | |
SweepResult
dataclass
Result of sweeping one parameter value across multiple trials.
Attributes:
| Name | Type | Description |
|---|---|---|
measurement_duration |
float
|
The measurement duration used (seconds). |
cooldown_duration |
float
|
The cooldown duration used (seconds). |
trials |
list[TrialResult]
|
Per-trial results. |
energy_mean |
float
|
Mean |
energy_std |
float
|
Sample standard deviation of |
avg_temperature_before |
float
|
Average temperature before the measurement. |
avg_temperature_after |
float
|
Average temperature after the measurement. |
avg_total_time |
float
|
Mean total time across trials. |
avg_total_energy |
float
|
Mean total energy across trials. |
is_valid |
bool
|
|
Source code in zeus/profile.py
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 | |
__str__
__str__()
One-line summary without per-trial details.
Source code in zeus/profile.py
138 139 140 141 142 143 144 145 146 147 148 149 | |
SweepReport
dataclass
Full report from a measurement-duration or cooldown-duration sweep.
Attributes:
| Name | Type | Description |
|---|---|---|
sweep_param |
tuple[str, list[float]]
|
|
fixed_param |
tuple[str, float]
|
|
entries |
list[SweepResult]
|
All sweep entries (one per swept value). |
Source code in zeus/profile.py
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 | |
__str__
__str__()
Multi-line summary: one line per swept value.
Source code in zeus/profile.py
166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 | |
_is_rank_zero
_is_rank_zero()
Return True when not distributed or when this is rank 0.
Source code in zeus/profile.py
82 83 84 | |
_calibrate_iteration_duration
_calibrate_iteration_duration(target_function, zeus_monitor, num_warmup_iterations, num_calibration_iterations)
Warm up target_function and measure per-iteration execution time.
Source code in zeus/profile.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
_read_avg_gpu_temperature
_read_avg_gpu_temperature(zeus_monitor)
Return the mean GPU temperature (deg C) across all monitored GPUs.
Source code in zeus/profile.py
209 210 211 212 213 | |
_run_trial
_run_trial(target_function, zeus_monitor, cooldown_duration, measurement_duration, num_warmup_iterations, iteration_duration)
Execute one trial: cooldown -> warmup -> measure.
Source code in zeus/profile.py
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 | |
_build_sweep_result
_build_sweep_result(measurement_duration, cooldown_duration, trials, trial_stddev_threshold)
Aggregate trial results into a SweepResult.
Source code in zeus/profile.py
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | |
_sweep
_sweep(target_function, zeus_monitor, sweep_values, fixed_value, sweep_type, num_trials, num_warmup_trials, trial_stddev_threshold, num_warmup_iterations, iteration_duration)
Run a parameter sweep and return a SweepReport.
Warmup trials skip cooldown and warmup iterations and use the maximum measurement duration.
Source code in zeus/profile.py
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 | |
profile_measurement_duration
profile_measurement_duration(target_function, zeus_monitor, measurement_duration_search_range=None, cooldown_duration=10.0, num_trials=10, num_warmup_trials=2, trial_stddev_threshold=0.01, num_warmup_iterations=10, num_calibration_iterations=100, iteration_duration=None)
Sweep measurement durations and return a SweepReport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_function
|
Callable[[], Any]
|
Callable to profile (invoked with no arguments). |
required |
zeus_monitor
|
ZeusMonitor
|
|
required |
measurement_duration_search_range
|
list[float] | None
|
Durations (seconds) to sweep.
Defaults to |
None
|
cooldown_duration
|
float
|
Cooldown held constant during the sweep. |
10.0
|
num_trials
|
int
|
Repeated trials per sweep point. |
10
|
num_warmup_trials
|
int
|
Number of throwaway trials to run before the sweep to warm up the GPU thermal state. |
2
|
trial_stddev_threshold
|
float
|
Maximum acceptable |
0.01
|
num_warmup_iterations
|
int
|
Warm-up iterations before each measurement. |
10
|
num_calibration_iterations
|
int
|
Iterations used to estimate per-iteration time. |
100
|
iteration_duration
|
float | None
|
Pre-calibrated iteration duration (seconds). If |
None
|
Source code in zeus/profile.py
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 | |
profile_cooldown_duration
profile_cooldown_duration(target_function, zeus_monitor, cooldown_duration_search_range=None, measurement_duration=10.0, num_trials=10, num_warmup_trials=2, trial_stddev_threshold=0.01, num_warmup_iterations=10, num_calibration_iterations=100, iteration_duration=None)
Sweep cooldown durations and return a SweepReport.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_function
|
Callable[[], Any]
|
Callable to profile (invoked with no arguments). |
required |
zeus_monitor
|
ZeusMonitor
|
|
required |
cooldown_duration_search_range
|
list[float] | None
|
Durations (seconds) to sweep.
Defaults to |
None
|
measurement_duration
|
float
|
Measurement duration held constant during the sweep. |
10.0
|
num_trials
|
int
|
Repeated trials per sweep point. |
10
|
num_warmup_trials
|
int
|
Number of throwaway trials to run before the sweep to warm up the GPU thermal state. |
2
|
trial_stddev_threshold
|
float
|
Maximum acceptable |
0.01
|
num_warmup_iterations
|
int
|
Warm-up iterations before each measurement. |
10
|
num_calibration_iterations
|
int
|
Iterations used to estimate per-iteration time. |
100
|
iteration_duration
|
float | None
|
Pre-calibrated iteration duration (seconds). If |
None
|
Source code in zeus/profile.py
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 | |
profile_parameters
profile_parameters(target_function, zeus_monitor, measurement_duration_search_range=None, cooldown_duration_search_range=None, num_trials=10, num_warmup_trials=2, trial_stddev_threshold=0.01, num_warmup_iterations=10, num_calibration_iterations=100)
Auto-profile both measurement and cooldown durations.
Performs two sequential sweeps:
- Measurement duration sweep -- cooldown is fixed at the maximum
of
cooldown_duration_search_range. - Cooldown duration sweep -- measurement duration is fixed at the
maximum of
measurement_duration_search_range.
Warmup trials are run once before the first sweep only.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_function
|
Callable[[], Any]
|
Callable to profile (invoked with no arguments). |
required |
zeus_monitor
|
ZeusMonitor
|
|
required |
measurement_duration_search_range
|
list[float] | None
|
Durations (seconds) to sweep.
Defaults to |
None
|
cooldown_duration_search_range
|
list[float] | None
|
Durations (seconds) to sweep.
Defaults to |
None
|
num_trials
|
int
|
Repeated trials per sweep point. |
10
|
num_warmup_trials
|
int
|
Number of throwaway trials to run before the first sweep to warm up the GPU thermal state. |
2
|
trial_stddev_threshold
|
float
|
Maximum acceptable |
0.01
|
num_warmup_iterations
|
int
|
Warm-up iterations before each measurement. |
10
|
num_calibration_iterations
|
int
|
Iterations used to estimate per-iteration time. |
100
|
Returns:
| Type | Description |
|---|---|
tuple[SweepReport, SweepReport]
|
|
Source code in zeus/profile.py
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 | |
measure
measure(target_function, zeus_monitor, measurement_duration, cooldown_duration, num_warmup_iterations=10, num_calibration_iterations=100)
Run a single energy measurement trial.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
target_function
|
Callable[[], Any]
|
Callable to profile (invoked with no arguments). |
required |
zeus_monitor
|
ZeusMonitor
|
|
required |
measurement_duration
|
float
|
Target measurement window length (seconds). |
required |
cooldown_duration
|
float
|
Idle time before the measurement (seconds). |
required |
num_warmup_iterations
|
int
|
Warm-up iterations before the measurement. |
10
|
num_calibration_iterations
|
int
|
Iterations used to estimate per-iteration time. |
100
|
Source code in zeus/profile.py
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 | |