power_limit
zeus.optimizer.power_limit
Optimizers that select the optimum power limit.
This module contains the following pieces:
GlobalPowerLimitOptimizer
is the main class that implements the state machine and the logic for profiling power limits and selecting the optimum power limit.PowerLimitMeasurement
and various state classes are helpers that support the state machine.OptimumSelector
is an abstract base class for selecting the optimum power limit from a list of power limit profiling results. There are concrete classes that implement different selection strategies, like minimizing energy, minimizing time, minimizing the Zeus time-energy cost, or selecting the lowest power limit that meets the given maximum training time slowdown factor.HFGlobalPowerLimitOptimizer
is a wrapper for the Hugging FaceTrainerCallback
class that usesGlobalPowerLimitOptimizer
.
OptimumSelector
Bases: ABC
Base class for optimum power limit selectors.
Source code in zeus/optimizer/power_limit.py
40 41 42 43 44 45 |
|
select
abstractmethod
select(measurements)
Select the optimal power limit (W) from measurements.
Source code in zeus/optimizer/power_limit.py
43 44 45 |
|
Energy
Bases: OptimumSelector
Selects the power limit that minimizes energy consumption.
Source code in zeus/optimizer/power_limit.py
48 49 50 51 52 53 |
|
select
select(measurements)
Select the optimal power limit (W) from measurements.
Source code in zeus/optimizer/power_limit.py
51 52 53 |
|
Time
Bases: OptimumSelector
Selects the power limit that minimizes training time.
This may not necessarily choose the maximum power limit, as time profiling results can be slightly noisy. However, we believe that's actually better because it means that training time is very similar among higher power limits, but lower power limit will consume less power.
Source code in zeus/optimizer/power_limit.py
56 57 58 59 60 61 62 63 64 65 66 67 |
|
select
select(measurements)
Select the optimal power limit (W) from measurements.
Source code in zeus/optimizer/power_limit.py
65 66 67 |
|
ZeusCost
Bases: OptimumSelector
Selects the power limit that minimizes a linear Zeus time-energy cost function.
Cost function is \(\eta \cdot \text{Energy} + (1 - \eta) \cdot \text{MaxPower} \cdot \text{Time}\).
Source code in zeus/optimizer/power_limit.py
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 |
|
__init__
__init__(eta_knob, world_size=1)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
eta_knob |
float
|
The \(0 \le \eta \le 1\) knob for the Zeus time-energy cost function. |
required |
world_size |
int
|
The number of GPUs in the training job. Defaults to 1. |
1
|
Source code in zeus/optimizer/power_limit.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
select
select(measurements)
Select the optimal power limit (W) from measurements.
Source code in zeus/optimizer/power_limit.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
|
MaxSlowdownConstraint
Bases: OptimumSelector
Selects the minumum power limit that does not slow down training by more than the given factor.
Source code in zeus/optimizer/power_limit.py
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 |
|
__init__
__init__(factor)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
factor |
float
|
The maximum allowed slowdown factor. Greater than or equal to 1.0. |
required |
Source code in zeus/optimizer/power_limit.py
112 113 114 115 116 117 118 119 120 121 122 123 |
|
select
select(measurements)
Select the optimal power limit (W) from measurements.
Source code in zeus/optimizer/power_limit.py
125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
Ready
Bases: BaseModel
State for when we are ready to start measuring the next power limit.
Initial state of the state machine if no previous profiling results were given.
Ready
-> Warmup
after step
'th on_step_begin
.
Source code in zeus/optimizer/power_limit.py
140 141 142 143 144 145 146 147 148 |
|
Warmup
Bases: BaseModel
State for when we are warming up for a power limit.
Warmup
-> Profiling
on the steps
'th on_step_begin
.
Warmup
-> Ready
on on_epoch_end
before steps
'th on_step_begin
.
Source code in zeus/optimizer/power_limit.py
151 152 153 154 155 156 157 158 159 |
|
Profiling
Bases: BaseModel
State for when we are profiling a power limit.
Profiling
-> Warmup
after steps
'th on_step_begin
and
there are still power limits left to profile.
Profiling
-> Done
after steps
'th on_step_begin
and
there are no more power limits left to profile.
Profiling
-> Ready
on on_epoch_end
before steps
'th on_step_begin
.
Source code in zeus/optimizer/power_limit.py
162 163 164 165 166 167 168 169 170 171 172 173 |
|
Done
Bases: BaseModel
State for when we are done profiling all power limits.
Initial state of the state machine if previous profiling results were given. Final state of the state machine in any case.
Source code in zeus/optimizer/power_limit.py
176 177 178 179 180 181 182 183 |
|
PowerLimitMeasurement
Bases: BaseModel
POD for GPU energy and time measurements for one power limit (W).
Source code in zeus/optimizer/power_limit.py
186 187 188 189 190 191 |
|
_PowerLimitMeasurementList
Bases: BaseModel
Proxy class to save and load a list of PowerLimitMeasurement
s.
Source code in zeus/optimizer/power_limit.py
194 195 196 197 |
|
GlobalPowerLimitOptimizer
Bases: Callback
Optimizer for the power limit knob.
This optimizer uses the JIT profiling log to determine the optimal power limit.
Source code in zeus/optimizer/power_limit.py
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 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 |
|
__init__
__init__(
monitor,
optimum_selector=None,
wait_steps=1,
warmup_steps=10,
profile_steps=40,
pl_step=25,
profile_path=None,
)
GPU indices to profile and optimize for are taken from monitor.gpu_indices
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
monitor |
ZeusMonitor
|
|
required |
optimum_selector |
OptimumSelector | None
|
The optimum selector to use. If not given, use |
None
|
wait_steps |
int
|
Number of steps to pass by before doing anything at the beginning.
Useful if you have something like |
1
|
warmup_steps |
int
|
Number of warmup iterations for each power limit. |
10
|
profile_steps |
int
|
Number of profie iterations for each power limit. |
40
|
pl_step |
int
|
The stride between power limits to explore, in unites of Watts. |
25
|
profile_path |
str | Path | None
|
If the path points to an existing file, load the profile from the file
and do not run any profiling. If the path points to a non-existing file, profile
and save the profile to the file. If |
None
|
Source code in zeus/optimizer/power_limit.py
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 |
|
on_epoch_end
on_epoch_end()
Mark the end of a training epoch.
Source code in zeus/optimizer/power_limit.py
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 |
|
on_step_begin
on_step_begin()
Mark the beginning of a training step.
Source code in zeus/optimizer/power_limit.py
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 |
|
_set_power_limit
_set_power_limit(power_limit)
Set the power limit for all GPUs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
power_limit |
int
|
The power limit to set, in milliWatts. |
required |
Source code in zeus/optimizer/power_limit.py
426 427 428 429 430 431 432 433 434 435 436 437 438 |
|
_compute_optimal_power_limit
_compute_optimal_power_limit()
Compute the optimal power limit in milliWatts.
Source code in zeus/optimizer/power_limit.py
440 441 442 443 444 |
|
_save_profile
_save_profile()
Save JIT profiling results and the optimal power limit to a JSON file.
Source code in zeus/optimizer/power_limit.py
446 447 448 449 450 451 452 453 454 455 456 457 458 |
|
HFGlobalPowerLimitOptimizer
Bases: TrainerCallback
[Wrapped for Hugging Face Trainer Callback] Optimizer for the power limit knob.
This optimizer uses the JIT profiling log to determine the optimal power limit.
See GlobalPowerLimitOptimizer
for the underlying optimizer implementation.
Source code in zeus/optimizer/power_limit.py
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 |
|
__init__
__init__(
monitor,
optimum_selector=None,
wait_steps=1,
warmup_steps=10,
profile_steps=40,
pl_step=25,
profile_path=None,
)
GPU indices to profile and optimize for are taken from monitor.gpu_indices
.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
monitor |
ZeusMonitor
|
|
required |
optimum_selector |
OptimumSelector | None
|
The optimum selector to use. If not given, use |
None
|
wait_steps |
int
|
Number of steps to pass by before doing anything at the beginning.
Useful if you have something like |
1
|
warmup_steps |
int
|
Number of warmup iterations for each power limit. |
10
|
profile_steps |
int
|
Number of profie iterations for each power limit. |
40
|
pl_step |
int
|
The stride between power limits to explore, in unites of Watts. |
25
|
profile_path |
str | Path | None
|
If the path points to an existing file, load the profile from the file
and do not run any profiling. If the path points to a non-existing file, profile
and save the profile to the file. If |
None
|
Source code in zeus/optimizer/power_limit.py
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 |
|
on_epoch_end
on_epoch_end(args, state, control, model, **kwargs)
Mark the end of a training epoch.
Source code in zeus/optimizer/power_limit.py
529 530 531 532 533 534 535 536 537 538 |
|
on_step_begin
on_step_begin(args, state, control, model, **kwargs)
Mark the beginning of a training step.
Source code in zeus/optimizer/power_limit.py
540 541 542 543 544 545 546 547 548 549 |
|