-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathsetup.py
More file actions
106 lines (94 loc) · 3.1 KB
/
Copy pathsetup.py
File metadata and controls
106 lines (94 loc) · 3.1 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import os
import sys
from setuptools import setup, find_packages
def _is_sdist_build():
"""Check if we are building a source distribution (no compilation needed)."""
return "sdist" in sys.argv or "egg_info" in sys.argv
def get_cuda_arch_flags():
import torch
cuda_arch = os.environ.get("CUDA_ARCH")
if cuda_arch:
return [f"-gencode=arch=compute_{cuda_arch},code=sm_{cuda_arch}"]
if not torch.cuda.is_available():
raise RuntimeError(
"CUDA is required to build mhc (set CUDA_ARCH env var for headless builds)"
)
major, minor = torch.cuda.get_device_capability()
return [f"-gencode=arch=compute_{major}{minor},code=sm_{major}{minor}"]
def get_extra_defines():
import torch
cuda_arch = os.environ.get("CUDA_ARCH")
if cuda_arch:
defines = []
if int(cuda_arch) >= 90:
defines.append("-DMHC_ENABLE_PDL")
return defines
if not torch.cuda.is_available():
return []
major, _ = torch.cuda.get_device_capability()
defines = []
if major >= 9:
defines.append("-DMHC_ENABLE_PDL")
return defines
# Skip CUDA extension entirely for sdist builds (no CUDA toolkit needed)
if _is_sdist_build():
ext_modules = []
cmdclass = {}
else:
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
ext_modules = [
CUDAExtension(
name="mhc_cuda",
sources=["src/python/bindings.cu"],
include_dirs=[
os.path.join(
os.path.dirname(os.path.abspath(__file__)), "src/csrc/include"
),
os.path.join(
os.path.dirname(os.path.abspath(__file__)), "src/csrc/kernels"
),
],
extra_compile_args={
"cxx": ["-O3"],
"nvcc": [
"-O3",
"--expt-relaxed-constexpr",
"-U__CUDA_NO_HALF_OPERATORS__",
"-U__CUDA_NO_HALF_CONVERSIONS__",
"-U__CUDA_NO_BFLOAT16_CONVERSIONS__",
"--use_fast_math",
]
+ get_cuda_arch_flags()
+ get_extra_defines(),
},
libraries=["cublas", "cublasLt"],
)
]
cmdclass = {"build_ext": BuildExtension}
setup(
name="mhc-cuda",
version="0.1.0",
description="CUDA implementation of Manifold-Constrained Hyper-Connections",
long_description=open("README.md").read() if os.path.exists("README.md") else "",
long_description_content_type="text/markdown",
author="Andre Slavescu",
url="https://github.com/AndreSlavescu/mHC.cu",
packages=find_packages(where="src/python"),
package_dir={"": "src/python"},
ext_modules=ext_modules,
cmdclass=cmdclass,
python_requires=">=3.10",
install_requires=[
"accelerate>=0.26.0",
"datasets",
"safetensors",
"sentencepiece",
"tiktoken",
"torch>=2.0.0",
"tqdm",
"transformers",
],
extras_require={
"dev": ["black", "pytest", "ruff"],
},
)