Skip to main content

Correctness-gated CUDA Graph pooling for Hugging Face greedy decoding

Project description

GPUOpt Runtime

PyPI Python Tests License

I built this because a lot of smaller LLM workloads waste time launching the same CUDA operations over and over. GPUOpt captures that decode work once, checks the output, and reuses it when the next request has a compatible shape.

It is not a driver replacement and it does not pretend every model gets faster. If graph capture or validation fails, it drops back to eager SDPA instead of silently returning questionable output.

What it does

  • pools CUDA Graphs by model, GPU, dtype, batch, and capacity
  • validates every token for a new shape before trusting it
  • resets and refills the KV cache after capture
  • reuses compatible graphs with an LRU cache
  • tracks capture time, cache hits, speed, and VRAM
  • enforces configurable VRAM limits

Install

Install the release from PyPI:

python -m pip install gpuopt-runtime

To run the example, include its optional dependencies:

python -m pip install "gpuopt-runtime[examples]"

Use it

import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from gpuopt import CUDAGraphPool

name = "Qwen/Qwen2.5-0.5B-Instruct"
tokenizer = AutoTokenizer.from_pretrained(name)
model = AutoModelForCausalLM.from_pretrained(
    name,
    dtype=torch.float16,
    device_map={"": "cuda"},
    attn_implementation="sdpa",
).eval()
inputs = tokenizer("Explain GPU launch overhead.", return_tensors="pt").to("cuda")

pool = CUDAGraphPool(max_entries=4)
result = pool.generate_greedy(model, inputs, new_tokens=64)
print(tokenizer.decode(result.token_ids[0]))
print(result.metrics())

The first compatible request captures and validates the graph. Later requests reuse it without paying that cost again.

You can also run the included example directly from the repository:

python examples/qwen_greedy.py

Results so far

GPU Eager SDPA CUDA Graph Steady state speedup Exact
RTX 5070 60.06 tok/s 281.18 tok/s 4.68x 64/64
A100 1g.10gb MIG 70.55 tok/s 130.14 tok/s 1.84x 64/64

These are Qwen2.5-0.5B greedy decode measurements, not a promise for every GPU or model. Cold requests also pay capture and validation costs.

Test your GPU

I want results from more GPUs and models. If you try GPUOpt, open an issue with your GPU, model, PyTorch version, eager speed, graph speed, whether the tokens matched, and any fallback reason reported in the metrics.

Share a result or report a problem

Current limits

Version 0.1 is for NVIDIA CUDA, Hugging Face causal models, greedy decoding, and unpadded prompts. Sampling, padded batches, continuous batching, and serving across multiple GPUs still need proper tests before I call them supported.

Licensed under Apache-2.0.

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

gpuopt_runtime-0.1.1.tar.gz (19.1 kB view details)

Uploaded Source

Built Distribution

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

gpuopt_runtime-0.1.1-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gpuopt_runtime-0.1.1.tar.gz
  • Upload date:
  • Size: 19.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for gpuopt_runtime-0.1.1.tar.gz
Algorithm Hash digest
SHA256 343e48609b946270d43b29a1a1421b15e5c0c3952a6ded532269b17b7633bdef
MD5 ddb43b988523a4792cb02326e53ea33a
BLAKE2b-256 a9009ec7b96cddfa603e942551c6e985eeec6efab6e977acdc2e3b0acf721949

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gpuopt_runtime-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 15.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for gpuopt_runtime-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb0223a05606ff8c76e04e82ab0053aedea0041babcf3959cfe8bb27b5b6588a
MD5 440253242b341ae5d7192d27be8b0742
BLAKE2b-256 89c5b45fe2b85c28ae0ffbd0a2d40aa18ddd6410fff2de3578434e9cb549637f

See more details on using hashes here.

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