Skip to main content

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.compile Compatible: 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_math flag.
  • 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

  1. Installation

    pip install .
    
  2. 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.

Metadata

Release files for torch-llm-kernels 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for torch-llm-kernels 0.1.0
File Size Uploaded Provenance Actions
torch_llm_kernels-0.1.0.tar.gz 8.0 kB Without provenance Details for torch_llm_kernels-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for torch-llm-kernels 0.1.0
File Interpreter ABI Platform Actions
torch_llm_kernels-0.1.0-py3-none-any.whl Python 3 none any Details for torch_llm_kernels-0.1.0-py3-none-any.whl

Total release size: 14.4 kB

Release files / torch_llm_kernels-0.1.0.tar.gz

Download URL torch_llm_kernels-0.1.0.tar.gz
Size 8.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8ad3667609a0bf12fac856330da06994c91c78577e9502793afc972f5224a017
BLAKE2b-256 checksum
How to use checksums
8c80ba55253307b9fbf702d3a10c94ef6fefa8aa89d72454a2a7e655e3a5f316
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Release files / torch_llm_kernels-0.1.0-py3-none-any.whl

Download URL torch_llm_kernels-0.1.0-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9d6ddb4e1ff89d87dc114f6d3294e5c0bfad116ae2f77a705e9748a5648acf83
BLAKE2b-256 checksum
How to use checksums
22bb1e3be599ae2176631c189ff4eea3b0c51e9afad596a226d34d0101192f58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.10.0

Security for torch-llm-kernels 0.1.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page