Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/main/apex/setup.py
Views: 792
import torch1from torch.utils import cpp_extension2from setuptools import setup, find_packages3import subprocess45import sys6import warnings7import os89# ninja build does not work unless include_dirs are abs path10this_dir = os.path.dirname(os.path.abspath(__file__))1112def get_cuda_bare_metal_version(cuda_dir):13raw_output = subprocess.check_output([cuda_dir + "/bin/nvcc", "-V"], universal_newlines=True)14output = raw_output.split()15release_idx = output.index("release") + 116release = output[release_idx].split(".")17bare_metal_major = release[0]18bare_metal_minor = release[1][0]1920return raw_output, bare_metal_major, bare_metal_minor2122if not torch.cuda.is_available():23# https://github.com/NVIDIA/apex/issues/48624# Extension builds after https://github.com/pytorch/pytorch/pull/23408 attempt to query torch.cuda.get_device_capability(),25# which will fail if you are compiling in an environment without visible GPUs (e.g. during an nvidia-docker build command).26print('\nWarning: Torch did not find available GPUs on this system.\n',27'If your intention is to cross-compile, this is not an error.\n'28'By default, Apex will cross-compile for Pascal (compute capabilities 6.0, 6.1, 6.2),\n'29'Volta (compute capability 7.0), Turing (compute capability 7.5),\n'30'and, if the CUDA version is >= 11.0, Ampere (compute capability 8.0).\n'31'If you wish to cross-compile for a single specific architecture,\n'32'export TORCH_CUDA_ARCH_LIST="compute capability" before running setup.py.\n')33if os.environ.get("TORCH_CUDA_ARCH_LIST", None) is None:34_, bare_metal_major, _ = get_cuda_bare_metal_version(cpp_extension.CUDA_HOME)35if int(bare_metal_major) == 11:36os.environ["TORCH_CUDA_ARCH_LIST"] = "6.0;6.1;6.2;7.0;7.5;8.0"37else:38os.environ["TORCH_CUDA_ARCH_LIST"] = "6.0;6.1;6.2;7.0;7.5"3940print("\n\ntorch.__version__ = {}\n\n".format(torch.__version__))41TORCH_MAJOR = int(torch.__version__.split('.')[0])42TORCH_MINOR = int(torch.__version__.split('.')[1])4344if TORCH_MAJOR == 0 and TORCH_MINOR < 4:45raise RuntimeError("Apex requires Pytorch 0.4 or newer.\n" +46"The latest stable release can be obtained from https://pytorch.org/")4748cmdclass = {}49ext_modules = []5051extras = {}52if "--pyprof" in sys.argv:53string = "\n\nPyprof has been moved to its own dedicated repository and will " + \54"soon be removed from Apex. Please visit\n" + \55"https://github.com/NVIDIA/PyProf\n" + \56"for the latest version."57warnings.warn(string, DeprecationWarning)58with open('requirements.txt') as f:59required_packages = f.read().splitlines()60extras['pyprof'] = required_packages61try:62sys.argv.remove("--pyprof")63except:64pass65else:66warnings.warn("Option --pyprof not specified. Not installing PyProf dependencies!")6768if "--cpp_ext" in sys.argv or "--cuda_ext" in sys.argv:69if TORCH_MAJOR == 0:70raise RuntimeError("--cpp_ext requires Pytorch 1.0 or later, "71"found torch.__version__ = {}".format(torch.__version__))72from torch.utils.cpp_extension import BuildExtension73cmdclass['build_ext'] = BuildExtension7475if "--cpp_ext" in sys.argv:76from torch.utils.cpp_extension import CppExtension77sys.argv.remove("--cpp_ext")78ext_modules.append(79CppExtension('apex_C',80['csrc/flatten_unflatten.cpp',]))8182def get_cuda_bare_metal_version(cuda_dir):83raw_output = subprocess.check_output([cuda_dir + "/bin/nvcc", "-V"], universal_newlines=True)84output = raw_output.split()85release_idx = output.index("release") + 186release = output[release_idx].split(".")87bare_metal_major = release[0]88bare_metal_minor = release[1][0]8990return raw_output, bare_metal_major, bare_metal_minor9192def check_cuda_torch_binary_vs_bare_metal(cuda_dir):93raw_output, bare_metal_major, bare_metal_minor = get_cuda_bare_metal_version(cuda_dir)94torch_binary_major = torch.version.cuda.split(".")[0]95torch_binary_minor = torch.version.cuda.split(".")[1]9697print("\nCompiling cuda extensions with")98print(raw_output + "from " + cuda_dir + "/bin\n")99100if (bare_metal_major != torch_binary_major) or (bare_metal_minor != torch_binary_minor):101raise RuntimeError("Cuda extensions are being compiled with a version of Cuda that does " +102"not match the version used to compile Pytorch binaries. " +103"Pytorch binaries were compiled with Cuda {}.\n".format(torch.version.cuda) +104"In some cases, a minor-version mismatch will not cause later errors: " +105"https://github.com/NVIDIA/apex/pull/323#discussion_r287021798. "106"You can try commenting out this check (at your own risk).")107108109# Set up macros for forward/backward compatibility hack around110# https://github.com/pytorch/pytorch/commit/4404762d7dd955383acee92e6f06b48144a0742e111# and112# https://github.com/NVIDIA/apex/issues/456113# https://github.com/pytorch/pytorch/commit/eb7b39e02f7d75c26d8a795ea8c7fd911334da7e#diff-4632522f237f1e4e728cb824300403ac114version_ge_1_1 = []115if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 0):116version_ge_1_1 = ['-DVERSION_GE_1_1']117version_ge_1_3 = []118if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 2):119version_ge_1_3 = ['-DVERSION_GE_1_3']120version_ge_1_5 = []121if (TORCH_MAJOR > 1) or (TORCH_MAJOR == 1 and TORCH_MINOR > 4):122version_ge_1_5 = ['-DVERSION_GE_1_5']123version_dependent_macros = version_ge_1_1 + version_ge_1_3 + version_ge_1_5124125if "--distributed_adam" in sys.argv:126from torch.utils.cpp_extension import CUDAExtension127sys.argv.remove("--distributed_adam")128129from torch.utils.cpp_extension import BuildExtension130cmdclass['build_ext'] = BuildExtension131132if torch.utils.cpp_extension.CUDA_HOME is None:133raise RuntimeError("--distributed_adam 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.")134else:135ext_modules.append(136CUDAExtension(name='distributed_adam_cuda',137sources=['apex/contrib/csrc/optimizers/multi_tensor_distopt_adam.cpp',138'apex/contrib/csrc/optimizers/multi_tensor_distopt_adam_kernel.cu'],139include_dirs=[os.path.join(this_dir, 'csrc')],140extra_compile_args={'cxx': ['-O3',] + version_dependent_macros,141'nvcc':['-O3',142'--use_fast_math'] + version_dependent_macros}))143144if "--distributed_lamb" in sys.argv:145from torch.utils.cpp_extension import CUDAExtension146sys.argv.remove("--distributed_lamb")147148from torch.utils.cpp_extension import BuildExtension149cmdclass['build_ext'] = BuildExtension150151if torch.utils.cpp_extension.CUDA_HOME is None:152raise RuntimeError("--distributed_lamb 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.")153else:154ext_modules.append(155CUDAExtension(name='distributed_lamb_cuda',156sources=['apex/contrib/csrc/optimizers/multi_tensor_distopt_lamb.cpp',157'apex/contrib/csrc/optimizers/multi_tensor_distopt_lamb_kernel.cu'],158include_dirs=[os.path.join(this_dir, 'csrc')],159extra_compile_args={'cxx': ['-O3',] + version_dependent_macros,160'nvcc':['-O3',161'--use_fast_math'] + version_dependent_macros}))162163if "--cuda_ext" in sys.argv:164from torch.utils.cpp_extension import CUDAExtension165sys.argv.remove("--cuda_ext")166167if torch.utils.cpp_extension.CUDA_HOME is None:168raise RuntimeError("--cuda_ext 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.")169else:170check_cuda_torch_binary_vs_bare_metal(torch.utils.cpp_extension.CUDA_HOME)171172ext_modules.append(173CUDAExtension(name='amp_C',174sources=['csrc/amp_C_frontend.cpp',175'csrc/multi_tensor_sgd_kernel.cu',176'csrc/multi_tensor_scale_kernel.cu',177'csrc/multi_tensor_axpby_kernel.cu',178'csrc/multi_tensor_l2norm_kernel.cu',179'csrc/multi_tensor_lamb_stage_1.cu',180'csrc/multi_tensor_lamb_stage_2.cu',181'csrc/multi_tensor_adam.cu',182'csrc/multi_tensor_adagrad.cu',183'csrc/multi_tensor_novograd.cu',184'csrc/multi_tensor_lamb.cu'],185extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,186'nvcc':['-lineinfo',187'-O3',188# '--resource-usage',189'--use_fast_math'] + version_dependent_macros}))190ext_modules.append(191CUDAExtension(name='syncbn',192sources=['csrc/syncbn.cpp',193'csrc/welford.cu'],194extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,195'nvcc':['-O3'] + version_dependent_macros}))196197ext_modules.append(198CUDAExtension(name='fused_layer_norm_cuda',199sources=['csrc/layer_norm_cuda.cpp',200'csrc/layer_norm_cuda_kernel.cu'],201extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,202'nvcc':['-maxrregcount=50',203'-O3',204'--use_fast_math'] + version_dependent_macros}))205206ext_modules.append(207CUDAExtension(name='mlp_cuda',208sources=['csrc/mlp.cpp',209'csrc/mlp_cuda.cu'],210extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,211'nvcc':['-O3'] + version_dependent_macros}))212213if "--bnp" in sys.argv:214from torch.utils.cpp_extension import CUDAExtension215sys.argv.remove("--bnp")216217from torch.utils.cpp_extension import BuildExtension218cmdclass['build_ext'] = BuildExtension219220if torch.utils.cpp_extension.CUDA_HOME is None:221raise RuntimeError("--bnp 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.")222else:223ext_modules.append(224CUDAExtension(name='bnp',225sources=['apex/contrib/csrc/groupbn/batch_norm.cu',226'apex/contrib/csrc/groupbn/ipc.cu',227'apex/contrib/csrc/groupbn/interface.cpp',228'apex/contrib/csrc/groupbn/batch_norm_add_relu.cu'],229include_dirs=[os.path.join(this_dir, 'csrc')],230extra_compile_args={'cxx': [] + version_dependent_macros,231'nvcc':['-DCUDA_HAS_FP16=1',232'-D__CUDA_NO_HALF_OPERATORS__',233'-D__CUDA_NO_HALF_CONVERSIONS__',234'-D__CUDA_NO_HALF2_OPERATORS__'] + version_dependent_macros}))235236if "--xentropy" in sys.argv:237from torch.utils.cpp_extension import CUDAExtension238sys.argv.remove("--xentropy")239240from torch.utils.cpp_extension import BuildExtension241cmdclass['build_ext'] = BuildExtension242243if torch.utils.cpp_extension.CUDA_HOME is None:244raise RuntimeError("--xentropy 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.")245else:246ext_modules.append(247CUDAExtension(name='xentropy_cuda',248sources=['apex/contrib/csrc/xentropy/interface.cpp',249'apex/contrib/csrc/xentropy/xentropy_kernel.cu'],250include_dirs=[os.path.join(this_dir, 'csrc')],251extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,252'nvcc':['-O3'] + version_dependent_macros}))253254if "--deprecated_fused_adam" in sys.argv:255from torch.utils.cpp_extension import CUDAExtension256sys.argv.remove("--deprecated_fused_adam")257258from torch.utils.cpp_extension import BuildExtension259cmdclass['build_ext'] = BuildExtension260261if torch.utils.cpp_extension.CUDA_HOME is None:262raise RuntimeError("--deprecated_fused_adam 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.")263else:264ext_modules.append(265CUDAExtension(name='fused_adam_cuda',266sources=['apex/contrib/csrc/optimizers/fused_adam_cuda.cpp',267'apex/contrib/csrc/optimizers/fused_adam_cuda_kernel.cu'],268include_dirs=[os.path.join(this_dir, 'csrc')],269extra_compile_args={'cxx': ['-O3',] + version_dependent_macros,270'nvcc':['-O3',271'--use_fast_math'] + version_dependent_macros}))272273if "--deprecated_fused_lamb" in sys.argv:274from torch.utils.cpp_extension import CUDAExtension275sys.argv.remove("--deprecated_fused_lamb")276277from torch.utils.cpp_extension import BuildExtension278cmdclass['build_ext'] = BuildExtension279280if torch.utils.cpp_extension.CUDA_HOME is None:281raise RuntimeError("--deprecated_fused_lamb 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.")282else:283ext_modules.append(284CUDAExtension(name='fused_lamb_cuda',285sources=['apex/contrib/csrc/optimizers/fused_lamb_cuda.cpp',286'apex/contrib/csrc/optimizers/fused_lamb_cuda_kernel.cu',287'csrc/multi_tensor_l2norm_kernel.cu'],288include_dirs=[os.path.join(this_dir, 'csrc')],289extra_compile_args={'cxx': ['-O3',] + version_dependent_macros,290'nvcc':['-O3',291'--use_fast_math'] + version_dependent_macros}))292293# Check, if ATen/CUDAGenerator.h is found, otherwise use the new ATen/CUDAGeneratorImpl.h, due to breaking change in https://github.com/pytorch/pytorch/pull/36026294generator_flag = []295torch_dir = torch.__path__[0]296if os.path.exists(os.path.join(torch_dir, 'include', 'ATen', 'CUDAGenerator.h')):297generator_flag = ['-DOLD_GENERATOR']298299if "--fast_layer_norm" in sys.argv:300from torch.utils.cpp_extension import CUDAExtension301sys.argv.remove("--fast_layer_norm")302303from torch.utils.cpp_extension import BuildExtension304cmdclass['build_ext'] = BuildExtension.with_options(use_ninja=False)305306if torch.utils.cpp_extension.CUDA_HOME is None:307raise RuntimeError("--fast_layer_norm 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.")308else:309# Check, if CUDA11 is installed for compute capability 8.0310cc_flag = []311_, bare_metal_major, _ = get_cuda_bare_metal_version(cpp_extension.CUDA_HOME)312if int(bare_metal_major) >= 11:313cc_flag.append('-gencode')314cc_flag.append('arch=compute_80,code=sm_80')315316ext_modules.append(317CUDAExtension(name='fast_layer_norm',318sources=['apex/contrib/csrc/layer_norm/ln_api.cpp',319'apex/contrib/csrc/layer_norm/ln_fwd_cuda_kernel.cu',320'apex/contrib/csrc/layer_norm/ln_bwd_semi_cuda_kernel.cu',321],322extra_compile_args={'cxx': ['-O3',] + version_dependent_macros + generator_flag,323'nvcc':['-O3',324'-gencode', 'arch=compute_70,code=sm_70',325'-U__CUDA_NO_HALF_OPERATORS__',326'-U__CUDA_NO_HALF_CONVERSIONS__',327'-I./apex/contrib/csrc/layer_norm/',328'--expt-relaxed-constexpr',329'--expt-extended-lambda',330'--use_fast_math'] + version_dependent_macros + generator_flag + cc_flag}))331if "--fmha" in sys.argv:332from torch.utils.cpp_extension import CUDAExtension333sys.argv.remove("--fmha")334335from torch.utils.cpp_extension import BuildExtension336cmdclass['build_ext'] = BuildExtension.with_options(use_ninja=False)337338if torch.utils.cpp_extension.CUDA_HOME is None:339raise RuntimeError("--fmha 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.")340else:341# Check, if CUDA11 is installed for compute capability 8.0342cc_flag = []343_, bare_metal_major, _ = get_cuda_bare_metal_version(cpp_extension.CUDA_HOME)344if int(bare_metal_major) < 11:345raise RuntimeError("--fmha only supported on SM80")346347ext_modules.append(348CUDAExtension(name='fmhalib',349sources=[350'apex/contrib/csrc/fmha/fmha_api.cpp',351'apex/contrib/csrc/fmha/src/fmha_fprop_fp16_128_64_kernel.sm80.cu',352'apex/contrib/csrc/fmha/src/fmha_fprop_fp16_256_64_kernel.sm80.cu',353'apex/contrib/csrc/fmha/src/fmha_fprop_fp16_384_64_kernel.sm80.cu',354'apex/contrib/csrc/fmha/src/fmha_fprop_fp16_512_64_kernel.sm80.cu',355'apex/contrib/csrc/fmha/src/fmha_dgrad_fp16_128_64_kernel.sm80.cu',356'apex/contrib/csrc/fmha/src/fmha_dgrad_fp16_256_64_kernel.sm80.cu',357'apex/contrib/csrc/fmha/src/fmha_dgrad_fp16_384_64_kernel.sm80.cu',358'apex/contrib/csrc/fmha/src/fmha_dgrad_fp16_512_64_kernel.sm80.cu',359],360extra_compile_args={'cxx': ['-O3',361'-I./apex/contrib/csrc/fmha/src',362] + version_dependent_macros + generator_flag,363'nvcc':['-O3',364'-gencode', 'arch=compute_80,code=sm_80',365'-U__CUDA_NO_HALF_OPERATORS__',366'-U__CUDA_NO_HALF_CONVERSIONS__',367'-I./apex/contrib/csrc/',368'-I./apex/contrib/csrc/fmha/src',369'--expt-relaxed-constexpr',370'--expt-extended-lambda',371'--use_fast_math'] + version_dependent_macros + generator_flag + cc_flag}))372373374if "--fast_multihead_attn" in sys.argv:375from torch.utils.cpp_extension import CUDAExtension376sys.argv.remove("--fast_multihead_attn")377378from torch.utils.cpp_extension import BuildExtension379cmdclass['build_ext'] = BuildExtension.with_options(use_ninja=False)380381if torch.utils.cpp_extension.CUDA_HOME is None:382raise RuntimeError("--fast_multihead_attn 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.")383else:384# Check, if CUDA11 is installed for compute capability 8.0385cc_flag = []386_, bare_metal_major, _ = get_cuda_bare_metal_version(cpp_extension.CUDA_HOME)387if int(bare_metal_major) >= 11:388cc_flag.append('-gencode')389cc_flag.append('arch=compute_80,code=sm_80')390391subprocess.run(["git", "submodule", "update", "--init", "apex/contrib/csrc/multihead_attn/cutlass"])392ext_modules.append(393CUDAExtension(name='fast_additive_mask_softmax_dropout',394sources=['apex/contrib/csrc/multihead_attn/additive_masked_softmax_dropout.cpp',395'apex/contrib/csrc/multihead_attn/additive_masked_softmax_dropout_cuda.cu'],396extra_compile_args={'cxx': ['-O3',] + version_dependent_macros + generator_flag,397'nvcc':['-O3',398'-gencode', 'arch=compute_70,code=sm_70',399'-I./apex/contrib/csrc/multihead_attn/cutlass/',400'-U__CUDA_NO_HALF_OPERATORS__',401'-U__CUDA_NO_HALF_CONVERSIONS__',402'--expt-relaxed-constexpr',403'--expt-extended-lambda',404'--use_fast_math'] + version_dependent_macros + generator_flag + cc_flag}))405ext_modules.append(406CUDAExtension(name='fast_mask_softmax_dropout',407sources=['apex/contrib/csrc/multihead_attn/masked_softmax_dropout.cpp',408'apex/contrib/csrc/multihead_attn/masked_softmax_dropout_cuda.cu'],409extra_compile_args={'cxx': ['-O3',] + version_dependent_macros + generator_flag,410'nvcc':['-O3',411'-gencode', 'arch=compute_70,code=sm_70',412'-I./apex/contrib/csrc/multihead_attn/cutlass/',413'-U__CUDA_NO_HALF_OPERATORS__',414'-U__CUDA_NO_HALF_CONVERSIONS__',415'--expt-relaxed-constexpr',416'--expt-extended-lambda',417'--use_fast_math'] + version_dependent_macros + generator_flag + cc_flag}))418ext_modules.append(419CUDAExtension(name='fast_self_multihead_attn_bias_additive_mask',420sources=['apex/contrib/csrc/multihead_attn/self_multihead_attn_bias_additive_mask.cpp',421'apex/contrib/csrc/multihead_attn/self_multihead_attn_bias_additive_mask_cuda.cu'],422extra_compile_args={'cxx': ['-O3',] + version_dependent_macros + generator_flag,423'nvcc':['-O3',424'-gencode', 'arch=compute_70,code=sm_70',425'-I./apex/contrib/csrc/multihead_attn/cutlass/',426'-U__CUDA_NO_HALF_OPERATORS__',427'-U__CUDA_NO_HALF_CONVERSIONS__',428'--expt-relaxed-constexpr',429'--expt-extended-lambda',430'--use_fast_math'] + version_dependent_macros + generator_flag + cc_flag}))431ext_modules.append(432CUDAExtension(name='fast_self_multihead_attn_bias',433sources=['apex/contrib/csrc/multihead_attn/self_multihead_attn_bias.cpp',434'apex/contrib/csrc/multihead_attn/self_multihead_attn_bias_cuda.cu'],435extra_compile_args={'cxx': ['-O3',] + version_dependent_macros + generator_flag,436'nvcc':['-O3',437'-gencode', 'arch=compute_70,code=sm_70',438'-I./apex/contrib/csrc/multihead_attn/cutlass/',439'-U__CUDA_NO_HALF_OPERATORS__',440'-U__CUDA_NO_HALF_CONVERSIONS__',441'--expt-relaxed-constexpr',442'--expt-extended-lambda',443'--use_fast_math'] + version_dependent_macros + generator_flag + cc_flag}))444ext_modules.append(445CUDAExtension(name='fast_self_multihead_attn',446sources=['apex/contrib/csrc/multihead_attn/self_multihead_attn.cpp',447'apex/contrib/csrc/multihead_attn/self_multihead_attn_cuda.cu'],448extra_compile_args={'cxx': ['-O3',] + version_dependent_macros + generator_flag,449'nvcc':['-O3',450'-gencode', 'arch=compute_70,code=sm_70',451'-I./apex/contrib/csrc/multihead_attn/cutlass/',452'-U__CUDA_NO_HALF_OPERATORS__',453'-U__CUDA_NO_HALF_CONVERSIONS__',454'--expt-relaxed-constexpr',455'--expt-extended-lambda',456'--use_fast_math'] + version_dependent_macros + generator_flag + cc_flag}))457ext_modules.append(458CUDAExtension(name='fast_self_multihead_attn_norm_add',459sources=['apex/contrib/csrc/multihead_attn/self_multihead_attn_norm_add.cpp',460'apex/contrib/csrc/multihead_attn/self_multihead_attn_norm_add_cuda.cu'],461extra_compile_args={'cxx': ['-O3',] + version_dependent_macros + generator_flag,462'nvcc':['-O3',463'-gencode', 'arch=compute_70,code=sm_70',464'-I./apex/contrib/csrc/multihead_attn/cutlass/',465'-U__CUDA_NO_HALF_OPERATORS__',466'-U__CUDA_NO_HALF_CONVERSIONS__',467'--expt-relaxed-constexpr',468'--expt-extended-lambda',469'--use_fast_math'] + version_dependent_macros + generator_flag + cc_flag}))470ext_modules.append(471CUDAExtension(name='fast_encdec_multihead_attn',472sources=['apex/contrib/csrc/multihead_attn/encdec_multihead_attn.cpp',473'apex/contrib/csrc/multihead_attn/encdec_multihead_attn_cuda.cu'],474extra_compile_args={'cxx': ['-O3',] + version_dependent_macros + generator_flag,475'nvcc':['-O3',476'-gencode', 'arch=compute_70,code=sm_70',477'-I./apex/contrib/csrc/multihead_attn/cutlass/',478'-U__CUDA_NO_HALF_OPERATORS__',479'-U__CUDA_NO_HALF_CONVERSIONS__',480'--expt-relaxed-constexpr',481'--expt-extended-lambda',482'--use_fast_math'] + version_dependent_macros + generator_flag + cc_flag}))483ext_modules.append(484CUDAExtension(name='fast_encdec_multihead_attn_norm_add',485sources=['apex/contrib/csrc/multihead_attn/encdec_multihead_attn_norm_add.cpp',486'apex/contrib/csrc/multihead_attn/encdec_multihead_attn_norm_add_cuda.cu'],487extra_compile_args={'cxx': ['-O3',] + version_dependent_macros + generator_flag,488'nvcc':['-O3',489'-gencode', 'arch=compute_70,code=sm_70',490'-I./apex/contrib/csrc/multihead_attn/cutlass/',491'-U__CUDA_NO_HALF_OPERATORS__',492'-U__CUDA_NO_HALF_CONVERSIONS__',493'--expt-relaxed-constexpr',494'--expt-extended-lambda',495'--use_fast_math'] + version_dependent_macros + generator_flag + cc_flag}))496497if "--transducer" in sys.argv:498from torch.utils.cpp_extension import CUDAExtension499sys.argv.remove("--transducer")500501from torch.utils.cpp_extension import BuildExtension502cmdclass['build_ext'] = BuildExtension.with_options(use_ninja=False)503504if torch.utils.cpp_extension.CUDA_HOME is None:505raise RuntimeError("--transducer 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.")506else:507ext_modules.append(508CUDAExtension(name='transducer_joint_cuda',509sources=['apex/contrib/csrc/transducer/transducer_joint.cpp',510'apex/contrib/csrc/transducer/transducer_joint_kernel.cu'],511include_dirs=[os.path.join(this_dir, 'csrc')],512extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,513'nvcc':['-O3'] + version_dependent_macros}))514ext_modules.append(515CUDAExtension(name='transducer_loss_cuda',516sources=['apex/contrib/csrc/transducer/transducer_loss.cpp',517'apex/contrib/csrc/transducer/transducer_loss_kernel.cu'],518include_dirs=[os.path.join(this_dir, 'csrc')],519extra_compile_args={'cxx': ['-O3'] + version_dependent_macros,520'nvcc':['-O3'] + version_dependent_macros}))521522if "--fast_bottleneck" in sys.argv:523from torch.utils.cpp_extension import CUDAExtension524sys.argv.remove("--fast_bottleneck")525526from torch.utils.cpp_extension import BuildExtension527cmdclass['build_ext'] = BuildExtension.with_options(use_ninja=False)528529if torch.utils.cpp_extension.CUDA_HOME is None:530raise RuntimeError("--fast_bottleneck 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.")531else:532subprocess.run(["git", "submodule", "update", "--init", "apex/contrib/csrc/cudnn-frontend/"])533ext_modules.append(534CUDAExtension(name='fast_bottleneck',535sources=['apex/contrib/csrc/bottleneck/bottleneck.cpp'],536include_dirs=['apex/contrib/csrc/cudnn-frontend/include'],537extra_compile_args={'cxx': ['-O3',] + version_dependent_macros + generator_flag}))538539setup(540name='apex',541version='0.1',542packages=find_packages(exclude=('build',543'csrc',544'include',545'tests',546'dist',547'docs',548'tests',549'examples',550'apex.egg-info',)),551description='PyTorch Extensions written by NVIDIA',552ext_modules=ext_modules,553cmdclass=cmdclass,554extras_require=extras,555)556557558