CUDA Kernels for Large Language Models (LLMs), compatible with torch.compile.
Project description
torch-llm-kernels
A high-performance CUDA kernel library for Large Language Models (LLMs), designed to be fully compatible with torch.compile.
Features
- High-Performance Kernels: Custom-written CUDA kernels designed to maximize GPU throughput.
torch.compileCompatible: All operators include the necessary meta implementations for seamless integration with PyTorch 2.x's compile mode.- Multi-Precision Support: Kernels are templated to support FP32, FP16, and BFloat16 data types, essential for modern LLM training and inference.
- Optimized for Speed: Uses performance-tuning techniques like fast math intrinsics via the
-use_fast_mathflag. - Fully Tested: Includes a comprehensive test suite using pytest to ensure correctness against native PyTorch implementations and to validate gradients.
Roadmap
This library aims to implement a suite of the most critical kernels for accelerating LLMs. Contributions are highly welcome!
- ✅ SwiGLU kernel
- ⬜️ RMSNorm Kernel
- ⬜️ Rotary Position Embedding (RoPE) Kernel
Quick Start
-
Installation
pip install .
-
Run Tests
pip install pytest pytest
Usage
import torch
from torch_llm_kernels import swiglu
device = "cuda"
gate = torch.randn(16, 1024, device=device, dtype=torch.float16)
up = torch.randn(16, 1024, device=device, dtype=torch.float16)
# Use the custom kernel
output = swiglu(gate, up)
# Compile with torch.compile
compiled_swiglu = torch.compile(swiglu)
compiled_output = compiled_swiglu(gate, up)
Contributing
Contributions are what make the open-source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you'd like to help add a new kernel or improve an existing one, please feel free to open an issue to discuss it or submit a pull request.
License
This project is licensed under the MIT License.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file torch_llm_kernels-0.1.0.tar.gz.
File metadata
- Download URL: torch_llm_kernels-0.1.0.tar.gz
- Upload date:
- Size: 8.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8ad3667609a0bf12fac856330da06994c91c78577e9502793afc972f5224a017
|
|
| MD5 |
28a2e1036aac0045ec54fe1df5dd1d40
|
|
| BLAKE2b-256 |
8c80ba55253307b9fbf702d3a10c94ef6fefa8aa89d72454a2a7e655e3a5f316
|
File details
Details for the file torch_llm_kernels-0.1.0-py3-none-any.whl.
File metadata
- Download URL: torch_llm_kernels-0.1.0-py3-none-any.whl
- Upload date:
- Size: 6.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9d6ddb4e1ff89d87dc114f6d3294e5c0bfad116ae2f77a705e9748a5648acf83
|
|
| MD5 |
dca933b0b76ab6186c6e07d3af75093d
|
|
| BLAKE2b-256 |
22bb1e3be599ae2176631c189ff4eea3b0c51e9afad596a226d34d0101192f58
|