GPU Scheduler
A simple tool to schedule gpu resources.
Let's say you have a server with 4 GPUs and you want to run 10 jobs (each job requires 1 GPU). They can finish any time and you don't want to sit in front of the server to run one after another, You can use this tool to schedule the jobs and it will run the jobs as soon as needed gpu is available.
Installation
pip install gpu-scheduler
Usage
import time
from gpu_scheduler import GPUScheduler
def hf_with_given_gpu_ids(model_id, gpu_ids: list):
device_map = {str(i): f"cuda:{gpu_id}" for i, gpu_id in enumerate(gpu_ids)}
model = AutoModel.from_pretrained(model_id, device_map=device_map)
# ...
return model
def func(model_id, gpu_ids: list):
"""
The function must accept gpu_ids as an argument
This is the list of GPU IDs that the job will run on
You have to manually set the GPU IDs in your code, i.e., above `hf_with_given_gpu_ids` function
"""
time.sleep(4) # Simulate job running
return model_id, gpu_ids
if __name__ == "__main__":
# Initialize scheduler with available GPUs
scheduler = GPUScheduler([0, 1, 2, 3]) # 4 GPUs numbered 0-3
# Add example model training jobs with different GPU requirements
scheduler.add_job(0, func, num_gpus=1, model_id="model_small")
scheduler.add_job(1, func, num_gpus=2, model_id="model_medium")
scheduler.add_job(2, func, num_gpus=4, model_id="model_large")
scheduler.add_job(3, func, num_gpus=1, model_id="model_small_2")
scheduler.add_job(4, func, num_gpus=2, model_id="model_medium_2")
scheduler.add_job(5, func, num_gpus=3, model_id="model_large_2")
# This job will fail because it requires more GPUs than are available
scheduler.add_job(999, func, num_gpus=5, model_id="model_too_big")
# Start processing jobs
scheduler.start_scheduler()
print("Job results:")
for job_id, result in scheduler.results:
print(f"{job_id=}: {result=}")
Output
Job results:
job_id=999: result='Error: Job 999 requires 5 GPUs, but only 4 are available in total'
job_id=1: result=('model_medium', [1, 2])
job_id=0: result=('model_small', [0])
job_id=3: result=('model_small_2', [3])
job_id=5: result=('model_large_2', [1, 2, 0])
job_id=2: result=('model_large', [3, 1, 2, 0])
job_id=4: result=('model_medium_2', [3, 1])
Metadata
Release files for gpu-scheduler 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| gpu_scheduler-0.1.1.tar.gz | 5.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| gpu_scheduler-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.8 kB
Release files / gpu_scheduler-0.1.1.tar.gz
| Download URL | gpu_scheduler-0.1.1.tar.gz |
|---|---|
| Size | 5.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
71b74e7a8a2b1440f3e15915ba805f768720a49d8c8f868909d37496c531ea1c
|
|
BLAKE2b-256 checksum How to use checksums |
f06133d078fec39961d5d688e891085f403755f79981630348c0f58d57d35035
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.
Transparency logRelease files / gpu_scheduler-0.1.1-py3-none-any.whl
| Download URL | gpu_scheduler-0.1.1-py3-none-any.whl |
|---|---|
| Size | 3.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e295f587491b541a171e423caee794f6bbd66891fa7aba0329a1ab28e0bd0215
|
|
BLAKE2b-256 checksum How to use checksums |
3eae34d01652aa9718a5858db7b5f6f78c18205b38a1679ef9328a2b22126987
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Feb 28, 2025.
Transparency log