setup.py 2.73 KB
Newer Older
1
import torch
2
from setuptools import setup, find_packages
3

jjsjann123's avatar
jjsjann123 committed
4
5
import sys

6
7
8
9
if not torch.cuda.is_available():
    print("Warning: Torch did not find available GPUs on this system.\n",
          "If your intention is to cross-compile, this is not an error.")

10
11
12
13
14
15
16
17
print("torch.__version__  = ", torch.__version__)
TORCH_MAJOR = int(torch.__version__.split('.')[0])
TORCH_MINOR = int(torch.__version__.split('.')[1])

if TORCH_MAJOR == 0 and TORCH_MINOR < 4:
      raise RuntimeError("APEx requires Pytorch 0.4 or newer.\n" +
                         "The latest stable release can be obtained from https://pytorch.org/")

jjsjann123's avatar
jjsjann123 committed
18
19
20
cmdclass = {}
ext_modules = []

21
22
23
24
25
26
27
28
29
30
31
if "--cpp_ext" in sys.argv or "--cuda_ext" in sys.argv:
    from torch.utils.cpp_extension import BuildExtension
    cmdclass['build_ext'] = BuildExtension

if "--cpp_ext" in sys.argv:
    from torch.utils.cpp_extension import CppExtension
    sys.argv.remove("--cpp_ext")
    ext_modules.append(
        CppExtension('apex_C',
                     ['csrc/flatten_unflatten.cpp',]))

jjsjann123's avatar
jjsjann123 committed
32
if "--cuda_ext" in sys.argv:
33
    from torch.utils.cpp_extension import CUDAExtension
jjsjann123's avatar
jjsjann123 committed
34
    sys.argv.remove("--cuda_ext")
35
36
37
38
39
    ext_modules.append(
        CUDAExtension(name='fused_adam_cuda',
                      sources=['apex/optimizers/csrc/fused_adam_cuda.cpp',
                               'apex/optimizers/csrc/fused_adam_cuda_kernel.cu'],
                      extra_compile_args={'cxx': ['-O3',],
ngimel's avatar
ngimel committed
40
                                          'nvcc':['-O3', 
41
42
43
44
45
                                                  '--use_fast_math']}))
    ext_modules.append(
        CUDAExtension(name='syncbn',
                      sources=['csrc/syncbn.cpp',
                               'csrc/welford.cu']))
46
47
48
49
50
51
52
53
    ext_modules.append(
        CUDAExtension(name='fused_layer_norm_cuda',
                      sources=['apex/normalization/csrc/layer_norm_cuda.cpp',
                               'apex/normalization/csrc/layer_norm_cuda_kernel.cu'],
                      extra_compile_args={'cxx': ['-O3',],
                                          'nvcc':['-maxrregcount=50',
                                                  '-O3', 
                                                  '--use_fast_math']}))
jjsjann123's avatar
jjsjann123 committed
54

Christian Sarofeen's avatar
Christian Sarofeen committed
55
setup(
56
57
    name='apex',
    version='0.1',
58
59
60
61
    packages=find_packages(exclude=('build',
                                    'csrc',
                                    'include',
                                    'tests',
62
63
64
65
66
                                    'dist',
                                    'docs',
                                    'tests',
                                    'examples',
                                    'apex.egg-info',)),
Christian Sarofeen's avatar
Christian Sarofeen committed
67
    description='PyTorch Extensions written by NVIDIA',
jjsjann123's avatar
jjsjann123 committed
68
69
    ext_modules=ext_modules,
    cmdclass=cmdclass,
Christian Sarofeen's avatar
Christian Sarofeen committed
70
)