Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ pip install keep-gpu

## Usage

### Use keep-gpu as a cli tool

```bash
keep-gpu
Expand All @@ -49,6 +50,28 @@ Specify GPU IDs to run on (default is all available GPUs):
keep-gpu --gpu-ids 0,1,2
```

### Use keep-gpu api in your code

Non-blocking gpu keeping logic with `CudaGPUController`:
```python
from keep_gpu.single_gpu_controller.cuda_gpu_controller import CudaGPUController
ctrl = CudaGPUController(rank=0, interval=0.5)
# occupy GPU while you do CPU-only work
# this is non-blocking
ctrl.keep()
dataset.process()
ctrl.release() # give GPU memory back
model.train_start() # now run real GPU training
```

Use `CudaGPUController` as a context manager:
```python
from keep_gpu.single_gpu_controller.cuda_gpu_controller import CudaGPUController
with CudaGPUController(rank=0, interval=0.5):
dataset.process() # GPU occupied inside this block
model.train_start() # GPU free after exiting block
```

## Credits

This package was created with [Cookiecutter](https://github.com/audreyr/cookiecutter) and the [audreyr/cookiecutter-pypackage](https://github.com/audreyr/cookiecutter-pypackage) project template.
Expand Down
2 changes: 1 addition & 1 deletion src/keep_gpu/single_gpu_controller/cuda_gpu_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class CudaGPUController(BaseGPUController):

```python
ctrl = CudaGPUController(rank=0, interval=0.5)
ctrl.start() # occupy GPU while you do CPU-only work
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
Expand Down