Skip to main content

A simple tool to schedule gpu resources.

Project description

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])

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gpu_scheduler-0.1.1.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gpu_scheduler-0.1.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

File details

Details for the file gpu_scheduler-0.1.1.tar.gz.

File metadata

  • Download URL: gpu_scheduler-0.1.1.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for gpu_scheduler-0.1.1.tar.gz
Algorithm Hash digest
SHA256 71b74e7a8a2b1440f3e15915ba805f768720a49d8c8f868909d37496c531ea1c
MD5 e9c87310b5ee4e6d1ac00fe9a53f29ca
BLAKE2b-256 f06133d078fec39961d5d688e891085f403755f79981630348c0f58d57d35035

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpu_scheduler-0.1.1.tar.gz:

Publisher: publish.yml on dipta007/gpu-scheduler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gpu_scheduler-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gpu_scheduler-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for gpu_scheduler-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 e295f587491b541a171e423caee794f6bbd66891fa7aba0329a1ab28e0bd0215
MD5 86999427f8b4678dfd013990d2db75cd
BLAKE2b-256 3eae34d01652aa9718a5858db7b5f6f78c18205b38a1679ef9328a2b22126987

See more details on using hashes here.

Provenance

The following attestation bundles were made for gpu_scheduler-0.1.1-py3-none-any.whl:

Publisher: publish.yml on dipta007/gpu-scheduler

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page