-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
72 lines (63 loc) · 2.19 KB
/
Copy pathsetup.py
File metadata and controls
72 lines (63 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
"""
setup.py
========
Builds the CUDA extension (fused_rmsnorm_linear) and packages all kernels.
Build commands
--------------
# Development install (editable, recompiles on change):
pip install -e . --no-build-isolation
# Production wheel:
pip wheel . --no-build-isolation
# Rebuild just the extension after editing .cu files:
python setup.py build_ext --inplace
Environment notes
-----------------
- A30 / A100 / 3090 → SM86: set TORCH_CUDA_ARCH_LIST="8.6"
- V100 → SM70: set TORCH_CUDA_ARCH_LIST="7.0"
- T4 (Colab) → SM75: set TORCH_CUDA_ARCH_LIST="7.5"
e.g.: TORCH_CUDA_ARCH_LIST="7.5" pip install -e . --no-build-isolation
Add -lineinfo for Nsight Compute source correlation during development.
"""
import os
from setuptools import setup, find_packages
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
# ── detect target arch ─────────────────────────────────────────────────────
# Falls back to SM86 (A30 / RTX 3090) if not set.
arch = os.environ.get("TORCH_CUDA_ARCH_LIST", "8.6")
nvcc_flags = [
"-O3",
f"-arch=sm_{arch.replace('.', '')}",
"--use_fast_math",
"-lineinfo", # source correlation in Nsight Compute
"--expt-relaxed-constexpr",
]
setup(
name="llm_kernels",
version="0.1.0",
description="Custom LLM GPU kernels: Flash Attention, fused RMSNorm+Linear, int8 GEMM",
author="Your Name",
python_requires=">=3.9",
packages=find_packages(exclude=["benchmarks", "tests"]),
ext_modules=[
CUDAExtension(
name="llm_kernels_cuda", # import name for the .so
sources=[
"csrc/bindings.cpp",
"csrc/fused_rmsnorm_linear.cu",
],
extra_compile_args={
"cxx": ["-O3", "-std=c++17"],
"nvcc": nvcc_flags,
},
)
],
cmdclass={"build_ext": BuildExtension},
install_requires=[
"torch>=2.2.0",
"triton>=2.2.0",
],
extras_require={
"bench": ["tabulate", "matplotlib"],
"dev": ["pytest", "black", "isort"],
},
)