API Reference¶
Autogenerated docs for the public modules most users interact with. The CLI module exposes the Typer entry point, while the controllers and utilities power both the command-line and Python recipes.
CLI entrypoint for KeepGPU.
list_gpus(host=typer.Option(DEFAULT_SERVICE_HOST, '--host', help='Service host.'), port=typer.Option(DEFAULT_SERVICE_PORT, '--port', help='Service port.'))
¶
List GPU telemetry from local service.
Source code in keep_gpu/cli.py
534 535 536 537 538 539 540 541 542 543 544 545 | |
main(ctx, interval=typer.Option(300, help='Interval in seconds between GPU usage checks (blocking mode only).'), gpu_ids=typer.Option(None, help='Comma-separated GPU IDs for blocking mode (default: all).'), vram=typer.Option('1GiB', '--vram', help='Amount of VRAM to keep occupied (blocking mode).'), legacy_threshold=typer.Option(None, '--threshold', hidden=True, help='Deprecated alias: numeric maps to busy-threshold, string maps to vram.'), busy_threshold=typer.Option(-1, '--busy-threshold', '--util-threshold', help='Max utilization threshold before backing off (blocking mode).'))
¶
Run blocking keep-alive mode when no subcommand is provided.
Source code in keep_gpu/cli.py
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 | |
serve(host=typer.Option(DEFAULT_SERVICE_HOST, help='Host interface for KeepGPU local service.'), port=typer.Option(DEFAULT_SERVICE_PORT, help='Port for KeepGPU local service.'))
¶
Run KeepGPU local service (HTTP + JSON-RPC + dashboard).
Source code in keep_gpu/cli.py
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 | |
service_stop(host=typer.Option(DEFAULT_SERVICE_HOST, '--host', help='Service host.'), port=typer.Option(DEFAULT_SERVICE_PORT, '--port', help='Service port.'), force=typer.Option(False, '--force', help='Stop service even if active sessions exist.'))
¶
Stop local KeepGPU service daemon started by auto-start logic.
Source code in keep_gpu/cli.py
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 | |
start(gpu_ids=typer.Option(None, help='Comma-separated GPU IDs.'), vram=typer.Option('1GiB', '--vram', help='VRAM to keep per GPU.'), interval=typer.Option(300, help='Interval in seconds between checks.'), busy_threshold=typer.Option(-1, '--busy-threshold', '--util-threshold', help='Back off when utilization exceeds this percent.'), job_id=typer.Option(None, help='Optional custom job id. Auto-generated when omitted.'), host=typer.Option(DEFAULT_SERVICE_HOST, '--host', help='KeepGPU service host.'), port=typer.Option(DEFAULT_SERVICE_PORT, '--port', help='KeepGPU service port.'), auto_start=typer.Option(True, '--auto-start/--no-auto-start', help='Auto-start local service when unavailable.'))
¶
Start a non-blocking keep session and return a job id.
Use keep-gpu stop --job-id <id> to release this session and
keep-gpu service-stop to stop the local service daemon.
Source code in keep_gpu/cli.py
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 | |
status(job_id=typer.Option(None, help='Session id to inspect.'), host=typer.Option(DEFAULT_SERVICE_HOST, '--host', help='Service host.'), port=typer.Option(DEFAULT_SERVICE_PORT, '--port', help='Service port.'))
¶
Show session status from KeepGPU local service.
Source code in keep_gpu/cli.py
480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 | |
stop(job_id=typer.Option(None, help='Session id to stop. Omit with --all to stop every session.'), all_sessions=typer.Option(False, '--all', help='Stop all sessions.'), host=typer.Option(DEFAULT_SERVICE_HOST, '--host', help='Service host.'), port=typer.Option(DEFAULT_SERVICE_PORT, '--port', help='Service port.'))
¶
Stop one session or all sessions.
Source code in keep_gpu/cli.py
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 | |
CudaGPUController
¶
Bases: BaseGPUController
CudaGPUController Keep a single CUDA GPU busy by repeatedly running lightweight elementwise workloads in a background thread.
Typical usage:
ctrl = CudaGPUController(rank=0, interval=0.5)
ctrl.keep() # occupy GPU while you do CPU-only work
dataset.process()
ctrl.release() # give GPU memory back
model.train_start() # now run real GPU training
Or as a context manager:
with CudaGPUController(rank=0, interval=0.5):
dataset.process() # GPU occupied inside this block
model.train_start() # GPU free after exiting block
Source code in keep_gpu/single_gpu_controller/cuda_gpu_controller.py
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 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 | |
__init__(*, rank, interval=1.0, relu_iterations=5000, matmul_iterations=None, vram_to_keep='1000 MB', busy_threshold=10)
¶
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
rank
|
int
|
Local CUDA device index to occupy. |
required |
interval
|
float
|
Sleep time (seconds) between workload batches. Defaults to 1.0. |
1.0
|
relu_iterations
|
int
|
Number of in-place ReLU ops per batch. |
5000
|
matmul_iterations
|
int
|
Legacy alias for
|
None
|
vram_to_keep
|
int or str
|
Amount of VRAM to keep busy,
e.g. |
'1000 MB'
|
busy_threshold
|
int
|
If current utilisation (%) exceeds this threshold, the worker will insert extra sleeps to avoid hogging the GPU. |
10
|
Source code in keep_gpu/single_gpu_controller/cuda_gpu_controller.py
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 | |
keep()
¶
Launch the background thread that keeps the GPU busy.
Source code in keep_gpu/single_gpu_controller/cuda_gpu_controller.py
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 | |
release()
¶
Stop the background thread and clear CUDA cache so the memory becomes immediately available to other code.
Source code in keep_gpu/single_gpu_controller/cuda_gpu_controller.py
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 | |