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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
import warnings
|
| 3 |
+
import os
|
| 4 |
+
import threading
|
| 5 |
+
import glob
|
| 6 |
+
from packaging.version import parse, Version
|
| 7 |
+
|
| 8 |
+
from setuptools import setup, find_packages
|
| 9 |
+
import subprocess
|
| 10 |
+
|
| 11 |
+
import torch
|
| 12 |
+
from torch.utils.cpp_extension import (
|
| 13 |
+
BuildExtension,
|
| 14 |
+
CppExtension,
|
| 15 |
+
CUDAExtension,
|
| 16 |
+
CUDA_HOME,
|
| 17 |
+
load,
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
# ninja build does not work unless include_dirs are abs path
|
| 21 |
+
this_dir = os.path.dirname(os.path.abspath(__file__))
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def get_cuda_bare_metal_version(cuda_dir):
|
| 25 |
+
raw_output = subprocess.check_output([cuda_dir + "/bin/nvcc", "-V"], universal_newlines=True)
|
| 26 |
+
output = raw_output.split()
|
| 27 |
+
release_idx = output.index("release") + 1
|
| 28 |
+
bare_metal_version = parse(output[release_idx].split(",")[0])
|
| 29 |
+
|
| 30 |
+
return raw_output, bare_metal_version
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def check_cuda_torch_binary_vs_bare_metal(cuda_dir):
|
| 34 |
+
raw_output, bare_metal_version = get_cuda_bare_metal_version(cuda_dir)
|
| 35 |
+
torch_binary_version = parse(torch.version.cuda)
|
| 36 |
+
|
| 37 |
+
print("\nCompiling cuda extensions with")
|
| 38 |
+
print(raw_output + "from " + cuda_dir + "/bin\n")
|
| 39 |
+
|
| 40 |
+
if (bare_metal_version != torch_binary_version):
|
| 41 |
+
raise RuntimeError(
|
| 42 |
+
"Cuda extensions are being compiled with a version of Cuda that does "
|
| 43 |
+
"not match the version used to compile Pytorch binaries. "
|
| 44 |
+
"Pytorch binaries were compiled with Cuda {}.\n".format(torch.version.cuda)
|
| 45 |
+
+ "In some cases, a minor-version mismatch will not cause later errors: "
|
| 46 |
+
"https://github.com/NVIDIA/apex/pull/323#discussion_r287021798. "
|
| 47 |
+
"You can try commenting out this check (at your own risk)."
|
| 48 |
+
)
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def raise_if_cuda_home_none(global_option: str) -> None:
|
| 52 |
+
if CUDA_HOME is not None:
|
| 53 |
+
return
|
| 54 |
+
raise RuntimeError(
|
| 55 |
+
f"{global_option} was requested, but nvcc was not found. Are you sure your environment has nvcc available? "
|
| 56 |
+
"If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, "
|
| 57 |
+
"only images whose names contain 'devel' will provide nvcc."
|
| 58 |
+
)
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
def check_cudnn_version_and_warn(global_option: str, required_cudnn_version: int) -> bool:
|
| 62 |
+
cudnn_available = torch.backends.cudnn.is_available()
|
| 63 |
+
cudnn_version = torch.backends.cudnn.version() if cudnn_available else None
|
| 64 |
+
if not (cudnn_available and (cudnn_version >= required_cudnn_version)):
|
| 65 |
+
warnings.warn(
|
| 66 |
+
f"Skip `{global_option}` as it requires cuDNN {required_cudnn_version} or later, "
|
| 67 |
+
f"but {'cuDNN is not available' if not cudnn_available else cudnn_version}"
|
| 68 |
+
)
|
| 69 |
+
return False
|
| 70 |
+
return True
|
| 71 |
+
|
| 72 |
+
|
| 73 |
+
if not torch.cuda.is_available():
|
| 74 |
+
# https://github.com/NVIDIA/apex/issues/486
|
| 75 |
+
# Extension builds after https://github.com/pytorch/pytorch/pull/23408 attempt to query torch.cuda.get_device_capability(),
|
| 76 |
+
# which will fail if you are compiling in an environment without visible GPUs (e.g. during an nvidia-docker build command).
|
| 77 |
+
print(
|
| 78 |
+
"\nWarning: Torch did not find available GPUs on this system.\n",
|
| 79 |
+
"If your intention is to cross-compile, this is not an error.\n"
|
| 80 |
+
"By default, Apex will cross-compile for Pascal (compute capabilities 6.0, 6.1, 6.2) (until CUDA 12.8),\n"
|
| 81 |
+
"Volta (compute capability 7.0), Turing (compute capability 7.5),\n"
|
| 82 |
+
"and, if the CUDA version is >= 11.0, Ampere (compute capability 8.0, 8.6), and,\n"
|
| 83 |
+
"if the CUDA version is >= 12.8, Blackwell (compute capability 10.0, 12.0).\n"
|
| 84 |
+
"If you wish to cross-compile for a single specific architecture,\n"
|
| 85 |
+
'export TORCH_CUDA_ARCH_LIST="compute capability" before running setup.py.\n',
|
| 86 |
+
)
|
| 87 |
+
if os.environ.get("TORCH_CUDA_ARCH_LIST", None) is None and CUDA_HOME is not None:
|
| 88 |
+
_, bare_metal_version = get_cuda_bare_metal_version(CUDA_HOME)
|
| 89 |
+
if bare_metal_version >= Version("12.8"):
|
| 90 |
+
os.environ["TORCH_CUDA_ARCH_LIST"] = "7.0;7.5;8.0;8.6;9.0;10.0;12.0"
|
| 91 |
+
elif bare_metal_version >= Version("11.8"):
|
| 92 |
+
os.environ["TORCH_CUDA_ARCH_LIST"] = "6.0;6.1;6.2;7.0;7.5;8.0;8.6;9.0"
|
| 93 |
+
elif bare_metal_version >= Version("11.1"):
|
| 94 |
+
os.environ["TORCH_CUDA_ARCH_LIST"] = "6.0;6.1;6.2;7.0;7.5;8.0;8.6"
|
| 95 |
+
elif bare_metal_version == Version("11.0"):
|
| 96 |
+
os.environ["TORCH_CUDA_ARCH_LIST"] = "6.0;6.1;6.2;7.0;7.5;8.0"
|
| 97 |
+
else:
|
| 98 |
+
os.environ["TORCH_CUDA_ARCH_LIST"] = "6.0;6.1;6.2;7.0;7.5"
|
| 99 |
+
|
| 100 |
+
print("\n\ntorch.__version__ = {}\n\n".format(torch.__version__))
|
| 101 |
+
TORCH_MAJOR = int(torch.__version__.split(".")[0])
|
| 102 |
+
TORCH_MINOR = int(torch.__version__.split(".")[1])
|
| 103 |
+
|
| 104 |
+
if TORCH_MAJOR == 0 and TORCH_MINOR < 4:
|
| 105 |
+
raise RuntimeError(
|
| 106 |
+
"Apex requires Pytorch 0.4 or newer.\nThe latest stable release can be obtained from https://pytorch.org/"
|
| 107 |
+
)
|
| 108 |
+
|
| 109 |
+
cmdclass = {}
|
| 110 |
+
ext_modules = []
|
| 111 |
+
|
| 112 |
+
extras = {}
|
| 113 |
+
|
| 114 |
+
if "--cpp_ext" in sys.argv or "--cuda_ext" in sys.argv:
|
| 115 |
+
if TORCH_MAJOR == 0:
|
| 116 |
+
raise RuntimeError(
|
| 117 |
+
"--cpp_ext requires Pytorch 1.0 or later, " "found torch.__version__ = {}".format(torch.__version__)
|
| 118 |
+
)
|
| 119 |
+
|
| 120 |
+
if "--cpp_ext" in sys.argv:
|
| 121 |
+
sys.argv.remove("--cpp_ext")
|
| 122 |
+
ext_modules.append(CppExtension("apex_C", ["csrc/flatten_unflatten.cpp"]))
|
| 123 |
+
|
| 124 |
+
|
| 125 |
+
# Set up macros for forward/backward compatibility hack around
|
| 126 |
+
# https://github.com/pytorch/pytorch/commit/4404762d7dd955383acee92e6f06b48144a0742e
|
| 127 |
+
# and
|
| 128 |
+
# https://github.com/NVIDIA/apex/issues/456
|
| 129 |
+
# https://github.com/pytorch/pytorch/commit/eb7b39e02f7d75c26d8a795ea8c7fd911334da7e#diff-4632522f237f1e4e728cb824300403ac
|
| 130 |
+
version_ge_1_1 = []
|
| 131 |
+
if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 0):
|
| 132 |
+
version_ge_1_1 = ["-DVERSION_GE_1_1"]
|
| 133 |
+
version_ge_1_3 = []
|
| 134 |
+
if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 2):
|
| 135 |
+
version_ge_1_3 = ["-DVERSION_GE_1_3"]
|
| 136 |
+
version_ge_1_5 = []
|
| 137 |
+
if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 4):
|
| 138 |
+
version_ge_1_5 = ["-DVERSION_GE_1_5"]
|
| 139 |
+
version_dependent_macros = version_ge_1_1 + version_ge_1_3 + version_ge_1_5
|
| 140 |
+
|
| 141 |
+
_, bare_metal_version = get_cuda_bare_metal_version(CUDA_HOME)
|
| 142 |
+
|
| 143 |
+
if "--distributed_adam" in sys.argv:
|
| 144 |
+
sys.argv.remove("--distributed_adam")
|
| 145 |
+
raise_if_cuda_home_none("--distributed_adam")
|
| 146 |
+
ext_modules.append(
|
| 147 |
+
CUDAExtension(
|
| 148 |
+
name="distributed_adam_cuda",
|
| 149 |
+
sources=[
|
| 150 |
+
"apex/contrib/csrc/optimizers/multi_tensor_distopt_adam.cpp",
|
| 151 |
+
"apex/contrib/csrc/optimizers/multi_tensor_distopt_adam_kernel.cu",
|
| 152 |
+
],
|
| 153 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 154 |
+
extra_compile_args={
|
| 155 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 156 |
+
"nvcc": ["-O3", "--use_fast_math"] + version_dependent_macros,
|
| 157 |
+
},
|
| 158 |
+
)
|
| 159 |
+
)
|
| 160 |
+
|
| 161 |
+
if "--distributed_lamb" in sys.argv:
|
| 162 |
+
sys.argv.remove("--distributed_lamb")
|
| 163 |
+
raise_if_cuda_home_none("--distributed_lamb")
|
| 164 |
+
ext_modules.append(
|
| 165 |
+
CUDAExtension(
|
| 166 |
+
name="distributed_lamb_cuda",
|
| 167 |
+
sources=[
|
| 168 |
+
"apex/contrib/csrc/optimizers/multi_tensor_distopt_lamb.cpp",
|
| 169 |
+
"apex/contrib/csrc/optimizers/multi_tensor_distopt_lamb_kernel.cu",
|
| 170 |
+
],
|
| 171 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 172 |
+
extra_compile_args={
|
| 173 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 174 |
+
"nvcc": ["-O3", "--use_fast_math"] + version_dependent_macros,
|
| 175 |
+
},
|
| 176 |
+
)
|
| 177 |
+
)
|
| 178 |
+
|
| 179 |
+
if "--cuda_ext" in sys.argv:
|
| 180 |
+
sys.argv.remove("--cuda_ext")
|
| 181 |
+
raise_if_cuda_home_none("--cuda_ext")
|
| 182 |
+
check_cuda_torch_binary_vs_bare_metal(CUDA_HOME)
|
| 183 |
+
|
| 184 |
+
ext_modules.append(
|
| 185 |
+
CUDAExtension(
|
| 186 |
+
name="amp_C",
|
| 187 |
+
sources=[
|
| 188 |
+
"csrc/amp_C_frontend.cpp",
|
| 189 |
+
"csrc/multi_tensor_sgd_kernel.cu",
|
| 190 |
+
"csrc/multi_tensor_scale_kernel.cu",
|
| 191 |
+
"csrc/multi_tensor_axpby_kernel.cu",
|
| 192 |
+
"csrc/multi_tensor_l2norm_kernel.cu",
|
| 193 |
+
"csrc/multi_tensor_l2norm_kernel_mp.cu",
|
| 194 |
+
"csrc/multi_tensor_l2norm_scale_kernel.cu",
|
| 195 |
+
"csrc/multi_tensor_lamb_stage_1.cu",
|
| 196 |
+
"csrc/multi_tensor_lamb_stage_2.cu",
|
| 197 |
+
"csrc/multi_tensor_adam.cu",
|
| 198 |
+
"csrc/multi_tensor_adagrad.cu",
|
| 199 |
+
"csrc/multi_tensor_novograd.cu",
|
| 200 |
+
"csrc/multi_tensor_lamb.cu",
|
| 201 |
+
"csrc/multi_tensor_lamb_mp.cu",
|
| 202 |
+
"csrc/update_scale_hysteresis.cu",
|
| 203 |
+
],
|
| 204 |
+
extra_compile_args={
|
| 205 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 206 |
+
"nvcc": [
|
| 207 |
+
"-lineinfo",
|
| 208 |
+
"-O3",
|
| 209 |
+
# '--resource-usage',
|
| 210 |
+
"--use_fast_math",
|
| 211 |
+
] + version_dependent_macros,
|
| 212 |
+
},
|
| 213 |
+
)
|
| 214 |
+
)
|
| 215 |
+
ext_modules.append(
|
| 216 |
+
CUDAExtension(
|
| 217 |
+
name="syncbn",
|
| 218 |
+
sources=["csrc/syncbn.cpp", "csrc/welford.cu"],
|
| 219 |
+
extra_compile_args={
|
| 220 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 221 |
+
"nvcc": ["-O3"] + version_dependent_macros,
|
| 222 |
+
},
|
| 223 |
+
)
|
| 224 |
+
)
|
| 225 |
+
|
| 226 |
+
ext_modules.append(
|
| 227 |
+
CUDAExtension(
|
| 228 |
+
name="fused_layer_norm_cuda",
|
| 229 |
+
sources=["csrc/layer_norm_cuda.cpp", "csrc/layer_norm_cuda_kernel.cu"],
|
| 230 |
+
extra_compile_args={
|
| 231 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 232 |
+
"nvcc": ["-maxrregcount=50", "-O3", "--use_fast_math"] + version_dependent_macros,
|
| 233 |
+
},
|
| 234 |
+
)
|
| 235 |
+
)
|
| 236 |
+
|
| 237 |
+
ext_modules.append(
|
| 238 |
+
CUDAExtension(
|
| 239 |
+
name="mlp_cuda",
|
| 240 |
+
sources=["csrc/mlp.cpp", "csrc/mlp_cuda.cu"],
|
| 241 |
+
extra_compile_args={
|
| 242 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 243 |
+
"nvcc": ["-O3"] + version_dependent_macros,
|
| 244 |
+
},
|
| 245 |
+
)
|
| 246 |
+
)
|
| 247 |
+
ext_modules.append(
|
| 248 |
+
CUDAExtension(
|
| 249 |
+
name="fused_dense_cuda",
|
| 250 |
+
sources=["csrc/fused_dense.cpp", "csrc/fused_dense_cuda.cu"],
|
| 251 |
+
extra_compile_args={
|
| 252 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 253 |
+
"nvcc": ["-O3"] + version_dependent_macros,
|
| 254 |
+
},
|
| 255 |
+
)
|
| 256 |
+
)
|
| 257 |
+
|
| 258 |
+
ext_modules.append(
|
| 259 |
+
CUDAExtension(
|
| 260 |
+
name="scaled_upper_triang_masked_softmax_cuda",
|
| 261 |
+
sources=[
|
| 262 |
+
"csrc/megatron/scaled_upper_triang_masked_softmax.cpp",
|
| 263 |
+
"csrc/megatron/scaled_upper_triang_masked_softmax_cuda.cu",
|
| 264 |
+
],
|
| 265 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 266 |
+
extra_compile_args={
|
| 267 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 268 |
+
"nvcc": [
|
| 269 |
+
"-O3",
|
| 270 |
+
"-U__CUDA_NO_HALF_OPERATORS__",
|
| 271 |
+
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
| 272 |
+
"--expt-relaxed-constexpr",
|
| 273 |
+
"--expt-extended-lambda",
|
| 274 |
+
] + version_dependent_macros,
|
| 275 |
+
},
|
| 276 |
+
)
|
| 277 |
+
)
|
| 278 |
+
|
| 279 |
+
ext_modules.append(
|
| 280 |
+
CUDAExtension(
|
| 281 |
+
name="generic_scaled_masked_softmax_cuda",
|
| 282 |
+
sources=[
|
| 283 |
+
"csrc/megatron/generic_scaled_masked_softmax.cpp",
|
| 284 |
+
"csrc/megatron/generic_scaled_masked_softmax_cuda.cu",
|
| 285 |
+
],
|
| 286 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 287 |
+
extra_compile_args={
|
| 288 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 289 |
+
"nvcc": [
|
| 290 |
+
"-O3",
|
| 291 |
+
"-U__CUDA_NO_HALF_OPERATORS__",
|
| 292 |
+
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
| 293 |
+
"--expt-relaxed-constexpr",
|
| 294 |
+
"--expt-extended-lambda",
|
| 295 |
+
] + version_dependent_macros,
|
| 296 |
+
},
|
| 297 |
+
)
|
| 298 |
+
)
|
| 299 |
+
|
| 300 |
+
ext_modules.append(
|
| 301 |
+
CUDAExtension(
|
| 302 |
+
name="scaled_masked_softmax_cuda",
|
| 303 |
+
sources=["csrc/megatron/scaled_masked_softmax.cpp", "csrc/megatron/scaled_masked_softmax_cuda.cu"],
|
| 304 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 305 |
+
extra_compile_args={
|
| 306 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 307 |
+
"nvcc": [
|
| 308 |
+
"-O3",
|
| 309 |
+
"-U__CUDA_NO_HALF_OPERATORS__",
|
| 310 |
+
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
| 311 |
+
"--expt-relaxed-constexpr",
|
| 312 |
+
"--expt-extended-lambda",
|
| 313 |
+
] + version_dependent_macros,
|
| 314 |
+
},
|
| 315 |
+
)
|
| 316 |
+
)
|
| 317 |
+
|
| 318 |
+
ext_modules.append(
|
| 319 |
+
CUDAExtension(
|
| 320 |
+
name="scaled_softmax_cuda",
|
| 321 |
+
sources=["csrc/megatron/scaled_softmax.cpp", "csrc/megatron/scaled_softmax_cuda.cu"],
|
| 322 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 323 |
+
extra_compile_args={
|
| 324 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 325 |
+
"nvcc": [
|
| 326 |
+
"-O3",
|
| 327 |
+
"-U__CUDA_NO_HALF_OPERATORS__",
|
| 328 |
+
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
| 329 |
+
"--expt-relaxed-constexpr",
|
| 330 |
+
"--expt-extended-lambda",
|
| 331 |
+
] + version_dependent_macros,
|
| 332 |
+
},
|
| 333 |
+
)
|
| 334 |
+
)
|
| 335 |
+
|
| 336 |
+
ext_modules.append(
|
| 337 |
+
CUDAExtension(
|
| 338 |
+
name="fused_rotary_positional_embedding",
|
| 339 |
+
sources=[
|
| 340 |
+
"csrc/megatron/fused_rotary_positional_embedding.cpp",
|
| 341 |
+
"csrc/megatron/fused_rotary_positional_embedding_cuda.cu",
|
| 342 |
+
],
|
| 343 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 344 |
+
extra_compile_args={
|
| 345 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 346 |
+
"nvcc": [
|
| 347 |
+
"-O3",
|
| 348 |
+
"-U__CUDA_NO_HALF_OPERATORS__",
|
| 349 |
+
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
| 350 |
+
"--expt-relaxed-constexpr",
|
| 351 |
+
"--expt-extended-lambda",
|
| 352 |
+
] + version_dependent_macros,
|
| 353 |
+
},
|
| 354 |
+
)
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
if bare_metal_version >= Version("11.0"):
|
| 358 |
+
|
| 359 |
+
cc_flag = []
|
| 360 |
+
cc_flag.append("-gencode")
|
| 361 |
+
cc_flag.append("arch=compute_70,code=sm_70")
|
| 362 |
+
cc_flag.append("-gencode")
|
| 363 |
+
cc_flag.append("arch=compute_80,code=sm_80")
|
| 364 |
+
if bare_metal_version >= Version("11.1"):
|
| 365 |
+
cc_flag.append("-gencode")
|
| 366 |
+
cc_flag.append("arch=compute_86,code=sm_86")
|
| 367 |
+
if bare_metal_version >= Version("11.8"):
|
| 368 |
+
cc_flag.append("-gencode")
|
| 369 |
+
cc_flag.append("arch=compute_90,code=sm_90")
|
| 370 |
+
if bare_metal_version >= Version("12.8"):
|
| 371 |
+
cc_flag.append("-gencode")
|
| 372 |
+
cc_flag.append("arch=compute_100,code=sm_100")
|
| 373 |
+
cc_flag.append("-gencode")
|
| 374 |
+
cc_flag.append("arch=compute_120,code=sm_120")
|
| 375 |
+
|
| 376 |
+
ext_modules.append(
|
| 377 |
+
CUDAExtension(
|
| 378 |
+
name="fused_weight_gradient_mlp_cuda",
|
| 379 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 380 |
+
sources=[
|
| 381 |
+
"csrc/megatron/fused_weight_gradient_dense.cpp",
|
| 382 |
+
"csrc/megatron/fused_weight_gradient_dense_cuda.cu",
|
| 383 |
+
"csrc/megatron/fused_weight_gradient_dense_16bit_prec_cuda.cu",
|
| 384 |
+
],
|
| 385 |
+
extra_compile_args={
|
| 386 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 387 |
+
"nvcc": [
|
| 388 |
+
"-O3",
|
| 389 |
+
"-U__CUDA_NO_HALF_OPERATORS__",
|
| 390 |
+
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
| 391 |
+
"--expt-relaxed-constexpr",
|
| 392 |
+
"--expt-extended-lambda",
|
| 393 |
+
"--use_fast_math",
|
| 394 |
+
] + version_dependent_macros + cc_flag,
|
| 395 |
+
},
|
| 396 |
+
)
|
| 397 |
+
)
|
| 398 |
+
|
| 399 |
+
if "--permutation_search" in sys.argv:
|
| 400 |
+
sys.argv.remove("--permutation_search")
|
| 401 |
+
|
| 402 |
+
if CUDA_HOME is None:
|
| 403 |
+
raise RuntimeError("--permutation_search was requested, but nvcc was not found. Are you sure your environment has nvcc available? If you're installing within a container from https://hub.docker.com/r/pytorch/pytorch, only images whose names contain 'devel' will provide nvcc.")
|
| 404 |
+
else:
|
| 405 |
+
cc_flag = ['-Xcompiler', '-fPIC', '-shared']
|
| 406 |
+
ext_modules.append(
|
| 407 |
+
CUDAExtension(name='permutation_search_cuda',
|
| 408 |
+
sources=['apex/contrib/sparsity/permutation_search_kernels/CUDA_kernels/permutation_search_kernels.cu'],
|
| 409 |
+
include_dirs=[os.path.join(this_dir, 'apex', 'contrib', 'sparsity', 'permutation_search_kernels', 'CUDA_kernels')],
|
| 410 |
+
extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,
|
| 411 |
+
'nvcc':['-O3'] + version_dependent_macros + cc_flag}))
|
| 412 |
+
|
| 413 |
+
if "--bnp" in sys.argv:
|
| 414 |
+
sys.argv.remove("--bnp")
|
| 415 |
+
raise_if_cuda_home_none("--bnp")
|
| 416 |
+
ext_modules.append(
|
| 417 |
+
CUDAExtension(
|
| 418 |
+
name="bnp",
|
| 419 |
+
sources=[
|
| 420 |
+
"apex/contrib/csrc/groupbn/batch_norm.cu",
|
| 421 |
+
"apex/contrib/csrc/groupbn/ipc.cu",
|
| 422 |
+
"apex/contrib/csrc/groupbn/interface.cpp",
|
| 423 |
+
"apex/contrib/csrc/groupbn/batch_norm_add_relu.cu",
|
| 424 |
+
],
|
| 425 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 426 |
+
extra_compile_args={
|
| 427 |
+
"cxx": [] + version_dependent_macros,
|
| 428 |
+
"nvcc": [
|
| 429 |
+
"-DCUDA_HAS_FP16=1",
|
| 430 |
+
"-D__CUDA_NO_HALF_OPERATORS__",
|
| 431 |
+
"-D__CUDA_NO_HALF_CONVERSIONS__",
|
| 432 |
+
"-D__CUDA_NO_HALF2_OPERATORS__",
|
| 433 |
+
] + version_dependent_macros,
|
| 434 |
+
},
|
| 435 |
+
)
|
| 436 |
+
)
|
| 437 |
+
|
| 438 |
+
if "--xentropy" in sys.argv:
|
| 439 |
+
from datetime import datetime
|
| 440 |
+
sys.argv.remove("--xentropy")
|
| 441 |
+
raise_if_cuda_home_none("--xentropy")
|
| 442 |
+
xentropy_ver = datetime.today().strftime("%y.%m.%d")
|
| 443 |
+
print(f"`--xentropy` setting version of {xentropy_ver}")
|
| 444 |
+
ext_modules.append(
|
| 445 |
+
CUDAExtension(
|
| 446 |
+
name="xentropy_cuda",
|
| 447 |
+
sources=["apex/contrib/csrc/xentropy/interface.cpp", "apex/contrib/csrc/xentropy/xentropy_kernel.cu"],
|
| 448 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 449 |
+
extra_compile_args={
|
| 450 |
+
"cxx": ["-O3"] + version_dependent_macros + [f'-DXENTROPY_VER="{xentropy_ver}"'],
|
| 451 |
+
"nvcc": ["-O3"] + version_dependent_macros,
|
| 452 |
+
},
|
| 453 |
+
)
|
| 454 |
+
)
|
| 455 |
+
|
| 456 |
+
if "--focal_loss" in sys.argv:
|
| 457 |
+
sys.argv.remove("--focal_loss")
|
| 458 |
+
raise_if_cuda_home_none("--focal_loss")
|
| 459 |
+
ext_modules.append(
|
| 460 |
+
CUDAExtension(
|
| 461 |
+
name='focal_loss_cuda',
|
| 462 |
+
sources=[
|
| 463 |
+
'apex/contrib/csrc/focal_loss/focal_loss_cuda.cpp',
|
| 464 |
+
'apex/contrib/csrc/focal_loss/focal_loss_cuda_kernel.cu',
|
| 465 |
+
],
|
| 466 |
+
include_dirs=[os.path.join(this_dir, 'csrc')],
|
| 467 |
+
extra_compile_args={
|
| 468 |
+
'cxx': ['-O3'] + version_dependent_macros,
|
| 469 |
+
'nvcc':['-O3', '--use_fast_math', '--ftz=false'] + version_dependent_macros,
|
| 470 |
+
},
|
| 471 |
+
)
|
| 472 |
+
)
|
| 473 |
+
|
| 474 |
+
if "--group_norm" in sys.argv:
|
| 475 |
+
sys.argv.remove("--group_norm")
|
| 476 |
+
raise_if_cuda_home_none("--group_norm")
|
| 477 |
+
|
| 478 |
+
# CUDA group norm supports from SM70
|
| 479 |
+
arch_flags = []
|
| 480 |
+
# FIXME: this needs to be done more cleanly
|
| 481 |
+
for arch in [70, 75, 80, 86, 90, 100, 120]:
|
| 482 |
+
arch_flag = f"-gencode=arch=compute_{arch},code=sm_{arch}"
|
| 483 |
+
arch_flags.append(arch_flag)
|
| 484 |
+
arch_flags.append(arch_flag)
|
| 485 |
+
|
| 486 |
+
ext_modules.append(
|
| 487 |
+
CUDAExtension(
|
| 488 |
+
name="group_norm_cuda",
|
| 489 |
+
sources=[
|
| 490 |
+
"apex/contrib/csrc/group_norm/group_norm_nhwc_op.cpp",
|
| 491 |
+
] + glob.glob("apex/contrib/csrc/group_norm/*.cu"),
|
| 492 |
+
include_dirs=[os.path.join(this_dir, 'csrc')],
|
| 493 |
+
extra_compile_args={
|
| 494 |
+
"cxx": ["-O3", "-std=c++17"] + version_dependent_macros,
|
| 495 |
+
"nvcc": [
|
| 496 |
+
"-O3", "-std=c++17", "--use_fast_math", "--ftz=false",
|
| 497 |
+
] + arch_flags + version_dependent_macros,
|
| 498 |
+
},
|
| 499 |
+
)
|
| 500 |
+
)
|
| 501 |
+
|
| 502 |
+
# CUDA group norm V2 is tested on SM100
|
| 503 |
+
if bare_metal_version >= Version("12.8"):
|
| 504 |
+
arch_flags = ["-gencode=arch=compute_100,code=sm_100"]
|
| 505 |
+
else:
|
| 506 |
+
arch_flags = ["-gencode=arch=compute_90,code=compute_90"]
|
| 507 |
+
|
| 508 |
+
ext_modules.append(
|
| 509 |
+
CUDAExtension(
|
| 510 |
+
name="group_norm_v2_cuda",
|
| 511 |
+
sources=[
|
| 512 |
+
"apex/contrib/csrc/group_norm_v2/gn.cpp",
|
| 513 |
+
"apex/contrib/csrc/group_norm_v2/gn_cuda.cu",
|
| 514 |
+
"apex/contrib/csrc/group_norm_v2/gn_utils.cpp",
|
| 515 |
+
] + glob.glob("apex/contrib/csrc/group_norm_v2/gn_cuda_inst_*.cu"),
|
| 516 |
+
extra_compile_args={
|
| 517 |
+
"cxx": ["-O2"] + version_dependent_macros,
|
| 518 |
+
"nvcc": [
|
| 519 |
+
"-O2", "--use_fast_math", "--ftz=false",
|
| 520 |
+
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
| 521 |
+
"-U__CUDA_NO_HALF_OPERATORS__",
|
| 522 |
+
"-U__CUDA_NO_BFLOAT16_CONVERSIONS__",
|
| 523 |
+
"-U__CUDA_NO_BFLOAT16_OPERATORS__",
|
| 524 |
+
] + arch_flags + version_dependent_macros,
|
| 525 |
+
},
|
| 526 |
+
)
|
| 527 |
+
)
|
| 528 |
+
|
| 529 |
+
if "--index_mul_2d" in sys.argv:
|
| 530 |
+
sys.argv.remove("--index_mul_2d")
|
| 531 |
+
raise_if_cuda_home_none("--index_mul_2d")
|
| 532 |
+
ext_modules.append(
|
| 533 |
+
CUDAExtension(
|
| 534 |
+
name='fused_index_mul_2d',
|
| 535 |
+
sources=[
|
| 536 |
+
'apex/contrib/csrc/index_mul_2d/index_mul_2d_cuda.cpp',
|
| 537 |
+
'apex/contrib/csrc/index_mul_2d/index_mul_2d_cuda_kernel.cu',
|
| 538 |
+
],
|
| 539 |
+
include_dirs=[os.path.join(this_dir, 'csrc')],
|
| 540 |
+
extra_compile_args={
|
| 541 |
+
'cxx': ['-O3'] + version_dependent_macros,
|
| 542 |
+
'nvcc':['-O3', '--use_fast_math', '--ftz=false'] + version_dependent_macros,
|
| 543 |
+
},
|
| 544 |
+
)
|
| 545 |
+
)
|
| 546 |
+
|
| 547 |
+
if "--deprecated_fused_adam" in sys.argv:
|
| 548 |
+
sys.argv.remove("--deprecated_fused_adam")
|
| 549 |
+
raise_if_cuda_home_none("--deprecated_fused_adam")
|
| 550 |
+
ext_modules.append(
|
| 551 |
+
CUDAExtension(
|
| 552 |
+
name="fused_adam_cuda",
|
| 553 |
+
sources=[
|
| 554 |
+
"apex/contrib/csrc/optimizers/fused_adam_cuda.cpp",
|
| 555 |
+
"apex/contrib/csrc/optimizers/fused_adam_cuda_kernel.cu",
|
| 556 |
+
],
|
| 557 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 558 |
+
extra_compile_args={
|
| 559 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 560 |
+
"nvcc": ["-O3", "--use_fast_math"] + version_dependent_macros,
|
| 561 |
+
},
|
| 562 |
+
)
|
| 563 |
+
)
|
| 564 |
+
|
| 565 |
+
if "--deprecated_fused_lamb" in sys.argv:
|
| 566 |
+
sys.argv.remove("--deprecated_fused_lamb")
|
| 567 |
+
raise_if_cuda_home_none("--deprecated_fused_lamb")
|
| 568 |
+
ext_modules.append(
|
| 569 |
+
CUDAExtension(
|
| 570 |
+
name="fused_lamb_cuda",
|
| 571 |
+
sources=[
|
| 572 |
+
"apex/contrib/csrc/optimizers/fused_lamb_cuda.cpp",
|
| 573 |
+
"apex/contrib/csrc/optimizers/fused_lamb_cuda_kernel.cu",
|
| 574 |
+
"csrc/multi_tensor_l2norm_kernel.cu",
|
| 575 |
+
],
|
| 576 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 577 |
+
extra_compile_args={
|
| 578 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 579 |
+
"nvcc": ["-O3", "--use_fast_math"] + version_dependent_macros,
|
| 580 |
+
},
|
| 581 |
+
)
|
| 582 |
+
)
|
| 583 |
+
|
| 584 |
+
# Check, if ATen/CUDAGeneratorImpl.h is found, otherwise use ATen/cuda/CUDAGeneratorImpl.h
|
| 585 |
+
# See https://github.com/pytorch/pytorch/pull/70650
|
| 586 |
+
generator_flag = []
|
| 587 |
+
torch_dir = torch.__path__[0]
|
| 588 |
+
if os.path.exists(os.path.join(torch_dir, "include", "ATen", "CUDAGeneratorImpl.h")):
|
| 589 |
+
generator_flag = ["-DOLD_GENERATOR_PATH"]
|
| 590 |
+
|
| 591 |
+
if "--fast_layer_norm" in sys.argv:
|
| 592 |
+
sys.argv.remove("--fast_layer_norm")
|
| 593 |
+
raise_if_cuda_home_none("--fast_layer_norm")
|
| 594 |
+
|
| 595 |
+
cc_flag = []
|
| 596 |
+
cc_flag.append("-gencode")
|
| 597 |
+
cc_flag.append("arch=compute_70,code=sm_70")
|
| 598 |
+
|
| 599 |
+
if bare_metal_version >= Version("11.0"):
|
| 600 |
+
cc_flag.append("-gencode")
|
| 601 |
+
cc_flag.append("arch=compute_80,code=sm_80")
|
| 602 |
+
if bare_metal_version >= Version("11.8"):
|
| 603 |
+
cc_flag.append("-gencode")
|
| 604 |
+
cc_flag.append("arch=compute_90,code=sm_90")
|
| 605 |
+
if bare_metal_version >= Version("12.8"):
|
| 606 |
+
cc_flag.append("-gencode")
|
| 607 |
+
cc_flag.append("arch=compute_100,code=sm_100")
|
| 608 |
+
cc_flag.append("-gencode")
|
| 609 |
+
cc_flag.append("arch=compute_120,code=sm_120")
|
| 610 |
+
|
| 611 |
+
ext_modules.append(
|
| 612 |
+
CUDAExtension(
|
| 613 |
+
name="fast_layer_norm",
|
| 614 |
+
sources=[
|
| 615 |
+
"apex/contrib/csrc/layer_norm/ln_api.cpp",
|
| 616 |
+
"apex/contrib/csrc/layer_norm/ln_fwd_cuda_kernel.cu",
|
| 617 |
+
"apex/contrib/csrc/layer_norm/ln_bwd_semi_cuda_kernel.cu",
|
| 618 |
+
],
|
| 619 |
+
extra_compile_args={
|
| 620 |
+
"cxx": ["-O3"] + version_dependent_macros + generator_flag,
|
| 621 |
+
"nvcc": [
|
| 622 |
+
"-O3",
|
| 623 |
+
"-U__CUDA_NO_HALF_OPERATORS__",
|
| 624 |
+
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
| 625 |
+
"-U__CUDA_NO_BFLOAT16_OPERATORS__",
|
| 626 |
+
"-U__CUDA_NO_BFLOAT16_CONVERSIONS__",
|
| 627 |
+
"-U__CUDA_NO_BFLOAT162_OPERATORS__",
|
| 628 |
+
"-U__CUDA_NO_BFLOAT162_CONVERSIONS__",
|
| 629 |
+
"-I./apex/contrib/csrc/layer_norm/",
|
| 630 |
+
"--expt-relaxed-constexpr",
|
| 631 |
+
"--expt-extended-lambda",
|
| 632 |
+
"--use_fast_math",
|
| 633 |
+
] + version_dependent_macros + generator_flag + cc_flag,
|
| 634 |
+
},
|
| 635 |
+
include_dirs=[os.path.join(this_dir, "apex/contrib/csrc/layer_norm")],
|
| 636 |
+
)
|
| 637 |
+
)
|
| 638 |
+
|
| 639 |
+
if "--fmha" in sys.argv:
|
| 640 |
+
sys.argv.remove("--fmha")
|
| 641 |
+
raise_if_cuda_home_none("--fmha")
|
| 642 |
+
|
| 643 |
+
if bare_metal_version < Version("11.0"):
|
| 644 |
+
raise RuntimeError("--fmha only supported on sm_80 and sm_90 GPUs")
|
| 645 |
+
|
| 646 |
+
cc_flag = []
|
| 647 |
+
cc_flag.append("-gencode")
|
| 648 |
+
cc_flag.append("arch=compute_80,code=sm_80")
|
| 649 |
+
if bare_metal_version >= Version("11.8"):
|
| 650 |
+
cc_flag.append("-gencode")
|
| 651 |
+
cc_flag.append("arch=compute_90,code=sm_90")
|
| 652 |
+
if bare_metal_version >= Version("12.8"):
|
| 653 |
+
cc_flag.append("-gencode")
|
| 654 |
+
cc_flag.append("arch=compute_100,code=sm_100")
|
| 655 |
+
cc_flag.append("-gencode")
|
| 656 |
+
cc_flag.append("arch=compute_120,code=sm_120")
|
| 657 |
+
|
| 658 |
+
ext_modules.append(
|
| 659 |
+
CUDAExtension(
|
| 660 |
+
name="fmhalib",
|
| 661 |
+
sources=[
|
| 662 |
+
"apex/contrib/csrc/fmha/fmha_api.cpp",
|
| 663 |
+
"apex/contrib/csrc/fmha/src/fmha_fill.cu",
|
| 664 |
+
"apex/contrib/csrc/fmha/src/fmha_noloop_reduce.cu",
|
| 665 |
+
"apex/contrib/csrc/fmha/src/fmha_fprop_fp16_128_64_kernel.sm80.cu",
|
| 666 |
+
"apex/contrib/csrc/fmha/src/fmha_fprop_fp16_256_64_kernel.sm80.cu",
|
| 667 |
+
"apex/contrib/csrc/fmha/src/fmha_fprop_fp16_384_64_kernel.sm80.cu",
|
| 668 |
+
"apex/contrib/csrc/fmha/src/fmha_fprop_fp16_512_64_kernel.sm80.cu",
|
| 669 |
+
"apex/contrib/csrc/fmha/src/fmha_dgrad_fp16_128_64_kernel.sm80.cu",
|
| 670 |
+
"apex/contrib/csrc/fmha/src/fmha_dgrad_fp16_256_64_kernel.sm80.cu",
|
| 671 |
+
"apex/contrib/csrc/fmha/src/fmha_dgrad_fp16_384_64_kernel.sm80.cu",
|
| 672 |
+
"apex/contrib/csrc/fmha/src/fmha_dgrad_fp16_512_64_kernel.sm80.cu",
|
| 673 |
+
],
|
| 674 |
+
extra_compile_args={
|
| 675 |
+
"cxx": ["-O3"] + version_dependent_macros + generator_flag,
|
| 676 |
+
"nvcc": [
|
| 677 |
+
"-O3",
|
| 678 |
+
"-U__CUDA_NO_HALF_OPERATORS__",
|
| 679 |
+
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
| 680 |
+
"--expt-relaxed-constexpr",
|
| 681 |
+
"--expt-extended-lambda",
|
| 682 |
+
"--use_fast_math",
|
| 683 |
+
] + version_dependent_macros + generator_flag + cc_flag,
|
| 684 |
+
},
|
| 685 |
+
include_dirs=[
|
| 686 |
+
os.path.join(this_dir, "apex/contrib/csrc"),
|
| 687 |
+
os.path.join(this_dir, "apex/contrib/csrc/fmha/src"),
|
| 688 |
+
],
|
| 689 |
+
)
|
| 690 |
+
)
|
| 691 |
+
|
| 692 |
+
|
| 693 |
+
if "--fast_multihead_attn" in sys.argv:
|
| 694 |
+
sys.argv.remove("--fast_multihead_attn")
|
| 695 |
+
raise_if_cuda_home_none("--fast_multihead_attn")
|
| 696 |
+
|
| 697 |
+
cc_flag = []
|
| 698 |
+
cc_flag.append("-gencode")
|
| 699 |
+
cc_flag.append("arch=compute_70,code=sm_70")
|
| 700 |
+
|
| 701 |
+
if bare_metal_version >= Version("11.0"):
|
| 702 |
+
cc_flag.append("-gencode")
|
| 703 |
+
cc_flag.append("arch=compute_80,code=sm_80")
|
| 704 |
+
if bare_metal_version >= Version("11.1"):
|
| 705 |
+
cc_flag.append("-gencode")
|
| 706 |
+
cc_flag.append("arch=compute_86,code=sm_86")
|
| 707 |
+
if bare_metal_version >= Version("11.8"):
|
| 708 |
+
cc_flag.append("-gencode")
|
| 709 |
+
cc_flag.append("arch=compute_90,code=sm_90")
|
| 710 |
+
if bare_metal_version >= Version("12.8"):
|
| 711 |
+
cc_flag.append("-gencode")
|
| 712 |
+
cc_flag.append("arch=compute_100,code=sm_100")
|
| 713 |
+
cc_flag.append("-gencode")
|
| 714 |
+
cc_flag.append("arch=compute_120,code=sm_120")
|
| 715 |
+
|
| 716 |
+
subprocess.run(["git", "submodule", "update", "--init", "apex/contrib/csrc/multihead_attn/cutlass"])
|
| 717 |
+
ext_modules.append(
|
| 718 |
+
CUDAExtension(
|
| 719 |
+
name="fast_multihead_attn",
|
| 720 |
+
sources=[
|
| 721 |
+
"apex/contrib/csrc/multihead_attn/multihead_attn_frontend.cpp",
|
| 722 |
+
"apex/contrib/csrc/multihead_attn/additive_masked_softmax_dropout_cuda.cu",
|
| 723 |
+
"apex/contrib/csrc/multihead_attn/masked_softmax_dropout_cuda.cu",
|
| 724 |
+
"apex/contrib/csrc/multihead_attn/encdec_multihead_attn_cuda.cu",
|
| 725 |
+
"apex/contrib/csrc/multihead_attn/encdec_multihead_attn_norm_add_cuda.cu",
|
| 726 |
+
"apex/contrib/csrc/multihead_attn/self_multihead_attn_cuda.cu",
|
| 727 |
+
"apex/contrib/csrc/multihead_attn/self_multihead_attn_bias_additive_mask_cuda.cu",
|
| 728 |
+
"apex/contrib/csrc/multihead_attn/self_multihead_attn_bias_cuda.cu",
|
| 729 |
+
"apex/contrib/csrc/multihead_attn/self_multihead_attn_norm_add_cuda.cu",
|
| 730 |
+
],
|
| 731 |
+
extra_compile_args={
|
| 732 |
+
"cxx": ["-O3"] + version_dependent_macros + generator_flag,
|
| 733 |
+
"nvcc": [
|
| 734 |
+
"-O3",
|
| 735 |
+
"-U__CUDA_NO_HALF_OPERATORS__",
|
| 736 |
+
"-U__CUDA_NO_HALF_CONVERSIONS__",
|
| 737 |
+
"--expt-relaxed-constexpr",
|
| 738 |
+
"--expt-extended-lambda",
|
| 739 |
+
"--use_fast_math",
|
| 740 |
+
]
|
| 741 |
+
+ version_dependent_macros
|
| 742 |
+
+ generator_flag
|
| 743 |
+
+ cc_flag,
|
| 744 |
+
},
|
| 745 |
+
include_dirs=[
|
| 746 |
+
os.path.join(this_dir, "apex/contrib/csrc/multihead_attn/cutlass/include/"),
|
| 747 |
+
os.path.join(this_dir, "apex/contrib/csrc/multihead_attn/cutlass/tools/util/include")
|
| 748 |
+
],
|
| 749 |
+
)
|
| 750 |
+
)
|
| 751 |
+
|
| 752 |
+
if "--transducer" in sys.argv:
|
| 753 |
+
sys.argv.remove("--transducer")
|
| 754 |
+
raise_if_cuda_home_none("--transducer")
|
| 755 |
+
ext_modules.append(
|
| 756 |
+
CUDAExtension(
|
| 757 |
+
name="transducer_joint_cuda",
|
| 758 |
+
sources=[
|
| 759 |
+
"apex/contrib/csrc/transducer/transducer_joint.cpp",
|
| 760 |
+
"apex/contrib/csrc/transducer/transducer_joint_kernel.cu",
|
| 761 |
+
],
|
| 762 |
+
extra_compile_args={
|
| 763 |
+
"cxx": ["-O3"] + version_dependent_macros + generator_flag,
|
| 764 |
+
"nvcc": ["-O3"] + version_dependent_macros + generator_flag,
|
| 765 |
+
},
|
| 766 |
+
include_dirs=[os.path.join(this_dir, "csrc"), os.path.join(this_dir, "apex/contrib/csrc/multihead_attn")],
|
| 767 |
+
)
|
| 768 |
+
)
|
| 769 |
+
ext_modules.append(
|
| 770 |
+
CUDAExtension(
|
| 771 |
+
name="transducer_loss_cuda",
|
| 772 |
+
sources=[
|
| 773 |
+
"apex/contrib/csrc/transducer/transducer_loss.cpp",
|
| 774 |
+
"apex/contrib/csrc/transducer/transducer_loss_kernel.cu",
|
| 775 |
+
],
|
| 776 |
+
include_dirs=[os.path.join(this_dir, "csrc")],
|
| 777 |
+
extra_compile_args={
|
| 778 |
+
"cxx": ["-O3"] + version_dependent_macros,
|
| 779 |
+
"nvcc": ["-O3"] + version_dependent_macros,
|
| 780 |
+
},
|
| 781 |
+
)
|
| 782 |
+
)
|
| 783 |
+
|
| 784 |
+
if "--cudnn_gbn" in sys.argv:
|
| 785 |
+
sys.argv.remove("--cudnn_gbn")
|
| 786 |
+
raise_if_cuda_home_none("--cudnn_gbn")
|
| 787 |
+
if check_cudnn_version_and_warn("--cudnn_gbn", 8500):
|
| 788 |
+
subprocess.run(["git", "submodule", "update", "--init", "apex/contrib/csrc/cudnn-frontend/"])
|
| 789 |
+
ext_modules.append(
|
| 790 |
+
CUDAExtension(
|
| 791 |
+
name="cudnn_gbn_lib",
|
| 792 |
+
sources=[
|
| 793 |
+
"apex/contrib/csrc/cudnn_gbn/norm_sample.cpp",
|
| 794 |
+
"apex/contrib/csrc/cudnn_gbn/cudnn_gbn.cpp",
|
| 795 |
+
],
|
| 796 |
+
include_dirs=[os.path.join(this_dir, "apex/contrib/csrc/cudnn-frontend/include")],
|
| 797 |
+
extra_compile_args={"cxx": ["-O3", "-g"] + version_dependent_macros + generator_flag},
|
| 798 |
+
)
|
| 799 |
+
)
|
| 800 |
+
|
| 801 |
+
if "--peer_memory" in sys.argv:
|
| 802 |
+
sys.argv.remove("--peer_memory")
|
| 803 |
+
raise_if_cuda_home_none("--peer_memory")
|
| 804 |
+
ext_modules.append(
|
| 805 |
+
CUDAExtension(
|
| 806 |
+
name="peer_memory_cuda",
|
| 807 |
+
sources=[
|
| 808 |
+
"apex/contrib/csrc/peer_memory/peer_memory_cuda.cu",
|
| 809 |
+
"apex/contrib/csrc/peer_memory/peer_memory.cpp",
|
| 810 |
+
],
|
| 811 |
+
extra_compile_args={"cxx": ["-O3"] + version_dependent_macros + generator_flag},
|
| 812 |
+
)
|
| 813 |
+
)
|
| 814 |
+
|
| 815 |
+
# NOTE: Requires NCCL >= 2.10.3
|
| 816 |
+
if "--nccl_p2p" in sys.argv:
|
| 817 |
+
sys.argv.remove("--nccl_p2p")
|
| 818 |
+
raise_if_cuda_home_none("--nccl_p2p")
|
| 819 |
+
# Check NCCL version.
|
| 820 |
+
_nccl_version_getter = load(
|
| 821 |
+
name="_nccl_version_getter",
|
| 822 |
+
sources=["apex/contrib/csrc/nccl_p2p/nccl_version.cpp", "apex/contrib/csrc/nccl_p2p/nccl_version_check.cu"],
|
| 823 |
+
|
| 824 |
+
)
|
| 825 |
+
_available_nccl_version = _nccl_version_getter.get_nccl_version()
|
| 826 |
+
if _available_nccl_version >= (2, 10):
|
| 827 |
+
ext_modules.append(
|
| 828 |
+
CUDAExtension(
|
| 829 |
+
name="nccl_p2p_cuda",
|
| 830 |
+
sources=[
|
| 831 |
+
"apex/contrib/csrc/nccl_p2p/nccl_p2p_cuda.cu",
|
| 832 |
+
"apex/contrib/csrc/nccl_p2p/nccl_p2p.cpp",
|
| 833 |
+
],
|
| 834 |
+
extra_compile_args={"cxx": ["-O3"] + version_dependent_macros + generator_flag},
|
| 835 |
+
)
|
| 836 |
+
)
|
| 837 |
+
else:
|
| 838 |
+
warnings.warn(
|
| 839 |
+
f"Skip `--nccl_p2p` as it requires NCCL 2.10.3 or later, but {_available_nccl_version[0]}.{_available_nccl_version[1]}"
|
| 840 |
+
)
|
| 841 |
+
|
| 842 |
+
# note (mkozuki): Now `--fast_bottleneck` option (i.e. apex/contrib/bottleneck) depends on `--peer_memory` and `--nccl_p2p`.
|
| 843 |
+
if "--fast_bottleneck" in sys.argv:
|
| 844 |
+
sys.argv.remove("--fast_bottleneck")
|
| 845 |
+
raise_if_cuda_home_none("--fast_bottleneck")
|
| 846 |
+
if check_cudnn_version_and_warn("--fast_bottleneck", 8400):
|
| 847 |
+
subprocess.run(["git", "submodule", "update", "--init", "apex/contrib/csrc/cudnn-frontend/"])
|
| 848 |
+
ext_modules.append(
|
| 849 |
+
CUDAExtension(
|
| 850 |
+
name="fast_bottleneck",
|
| 851 |
+
sources=["apex/contrib/csrc/bottleneck/bottleneck.cpp"],
|
| 852 |
+
include_dirs=[os.path.join(this_dir, "apex/contrib/csrc/cudnn-frontend/include")],
|
| 853 |
+
extra_compile_args={"cxx": ["-O3"] + version_dependent_macros + generator_flag},
|
| 854 |
+
)
|
| 855 |
+
)
|
| 856 |
+
|
| 857 |
+
|
| 858 |
+
if "--fused_conv_bias_relu" in sys.argv:
|
| 859 |
+
sys.argv.remove("--fused_conv_bias_relu")
|
| 860 |
+
raise_if_cuda_home_none("--fused_conv_bias_relu")
|
| 861 |
+
if check_cudnn_version_and_warn("--fused_conv_bias_relu", 8400):
|
| 862 |
+
subprocess.run(["git", "submodule", "update", "--init", "apex/contrib/csrc/cudnn-frontend/"])
|
| 863 |
+
ext_modules.append(
|
| 864 |
+
CUDAExtension(
|
| 865 |
+
name="fused_conv_bias_relu",
|
| 866 |
+
sources=["apex/contrib/csrc/conv_bias_relu/conv_bias_relu.cpp"],
|
| 867 |
+
include_dirs=[os.path.join(this_dir, "apex/contrib/csrc/cudnn-frontend/include")],
|
| 868 |
+
extra_compile_args={"cxx": ["-O3"] + version_dependent_macros + generator_flag},
|
| 869 |
+
)
|
| 870 |
+
)
|
| 871 |
+
|
| 872 |
+
|
| 873 |
+
if "--nccl_allocator" in sys.argv:
|
| 874 |
+
sys.argv.remove("--nccl_allocator")
|
| 875 |
+
raise_if_cuda_home_none("--nccl_allocator")
|
| 876 |
+
_nccl_version_getter = load(
|
| 877 |
+
name="_nccl_version_getter",
|
| 878 |
+
sources=["apex/contrib/csrc/nccl_p2p/nccl_version.cpp", "apex/contrib/csrc/nccl_p2p/nccl_version_check.cu"],
|
| 879 |
+
)
|
| 880 |
+
_available_nccl_version = _nccl_version_getter.get_nccl_version()
|
| 881 |
+
if _available_nccl_version >= (2, 19):
|
| 882 |
+
ext_modules.append(
|
| 883 |
+
CUDAExtension(
|
| 884 |
+
name="_apex_nccl_allocator",
|
| 885 |
+
sources=[
|
| 886 |
+
"apex/contrib/csrc/nccl_allocator/NCCLAllocator.cpp",
|
| 887 |
+
],
|
| 888 |
+
include_dirs=[os.path.join(this_dir, "apex/apex/contrib/csrc/nccl_allocator")],
|
| 889 |
+
libraries=["nccl"],
|
| 890 |
+
extra_compile_args={"cxx": ["-O3"] + version_dependent_macros + generator_flag},
|
| 891 |
+
)
|
| 892 |
+
)
|
| 893 |
+
else:
|
| 894 |
+
warnings.warn(
|
| 895 |
+
f"Skip `--nccl_allocator` as it requires NCCL 2.19 or later, but {_available_nccl_version[0]}.{_available_nccl_version[1]}"
|
| 896 |
+
)
|
| 897 |
+
|
| 898 |
+
|
| 899 |
+
if "--gpu_direct_storage" in sys.argv:
|
| 900 |
+
sys.argv.remove("--gpu_direct_storage")
|
| 901 |
+
raise_if_cuda_home_none("--gpu_direct_storage")
|
| 902 |
+
ext_modules.append(
|
| 903 |
+
CUDAExtension(
|
| 904 |
+
name="_apex_gpu_direct_storage",
|
| 905 |
+
sources=["apex/contrib/csrc/gpu_direct_storage/gds.cpp", "apex/contrib/csrc/gpu_direct_storage/gds_pybind.cpp"],
|
| 906 |
+
include_dirs=[os.path.join(this_dir, "apex/contrib/csrc/gpu_direct_storage")],
|
| 907 |
+
libraries=["cufile"],
|
| 908 |
+
extra_compile_args={"cxx": ["-O3"] + version_dependent_macros + generator_flag},
|
| 909 |
+
)
|
| 910 |
+
)
|
| 911 |
+
|
| 912 |
+
|
| 913 |
+
# Patch because `setup.py bdist_wheel` and `setup.py develop` do not support the `parallel` option
|
| 914 |
+
parallel = None
|
| 915 |
+
if "--parallel" in sys.argv:
|
| 916 |
+
idx = sys.argv.index("--parallel")
|
| 917 |
+
parallel = int(sys.argv[idx + 1])
|
| 918 |
+
sys.argv.pop(idx + 1)
|
| 919 |
+
sys.argv.pop(idx)
|
| 920 |
+
|
| 921 |
+
|
| 922 |
+
# Prevent file conflicts when multiple extensions are compiled simultaneously
|
| 923 |
+
class BuildExtensionSeparateDir(BuildExtension):
|
| 924 |
+
build_extension_patch_lock = threading.Lock()
|
| 925 |
+
thread_ext_name_map = {}
|
| 926 |
+
|
| 927 |
+
def finalize_options(self):
|
| 928 |
+
if parallel is not None:
|
| 929 |
+
self.parallel = parallel
|
| 930 |
+
super().finalize_options()
|
| 931 |
+
|
| 932 |
+
def build_extension(self, ext):
|
| 933 |
+
with self.build_extension_patch_lock:
|
| 934 |
+
if not getattr(self.compiler, "_compile_separate_output_dir", False):
|
| 935 |
+
compile_orig = self.compiler.compile
|
| 936 |
+
|
| 937 |
+
def compile_new(*args, **kwargs):
|
| 938 |
+
return compile_orig(*args, **{
|
| 939 |
+
**kwargs,
|
| 940 |
+
"output_dir": os.path.join(
|
| 941 |
+
kwargs["output_dir"],
|
| 942 |
+
self.thread_ext_name_map[threading.current_thread().ident]),
|
| 943 |
+
})
|
| 944 |
+
self.compiler.compile = compile_new
|
| 945 |
+
self.compiler._compile_separate_output_dir = True
|
| 946 |
+
self.thread_ext_name_map[threading.current_thread().ident] = ext.name
|
| 947 |
+
objects = super().build_extension(ext)
|
| 948 |
+
return objects
|
| 949 |
+
|
| 950 |
+
|
| 951 |
+
setup(
|
| 952 |
+
name="apex",
|
| 953 |
+
version="0.1",
|
| 954 |
+
packages=find_packages(
|
| 955 |
+
exclude=("build", "csrc", "include", "tests", "dist", "docs", "tests", "examples", "apex.egg-info",)
|
| 956 |
+
),
|
| 957 |
+
install_requires=["packaging>20.6"],
|
| 958 |
+
description="PyTorch Extensions written by NVIDIA",
|
| 959 |
+
ext_modules=ext_modules,
|
| 960 |
+
cmdclass={"build_ext": BuildExtensionSeparateDir} if ext_modules else {},
|
| 961 |
+
extras_require=extras,
|
| 962 |
+
)
|