-
Notifications
You must be signed in to change notification settings - Fork 93
/
setup.py
executable file
·153 lines (134 loc) · 4.73 KB
/
setup.py
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
#!/usr/bin/env python3
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.
"""The setuptools based setup module.
Reference:
https://packaging.python.org/guides/distributing-packages-using-setuptools/
"""
import os, sys
import subprocess
import platform as pf
import shutil
from typing import List, Tuple
from setuptools import setup, find_packages, Command
from torch.utils.cpp_extension import BuildExtension, CUDAExtension, CppExtension
try:
from torch.utils.cpp_extension import IS_HIP_EXTENSION
except:
IS_HIP_EXTENSION = False
if len(sys.argv) <= 1:
sys.argv += ['install']
root_path = os.path.dirname(sys.argv[0])
root_path = root_path if root_path else '.'
root_path = os.path.abspath(root_path)
os.chdir(root_path)
class Tester(Command):
"""Cmdclass for `python setup.py test`.
Args:
Command (distutils.cmd.Command):
Abstract base class for defining command classes.
"""
description = 'test the code using pytest'
user_options: List[Tuple[str, str, str]] = []
def initialize_options(self):
"""Set default values for options that this command supports."""
pass
def finalize_options(self):
"""Set final values for options that this command supports."""
pass
def run(self):
"""Run pytest."""
subprocess.check_call('python3 -m pytest -v -s tests/', shell=True)
def install(use_cuda, use_nccl):
ext_libs = []
if pf.system() == 'Linux':
ext_args = ['-Wno-sign-compare', '-Wno-unused-but-set-variable', '-Wno-terminate', '-Wno-unused-function', '-Wno-strict-aliasing']
elif pf.system() == 'Darwin':
ext_args = ['-mmacosx-version-min=10.13']
else:
ext_args = []
if not use_cuda:
use_nccl = False
extension = CppExtension
else:
ext_libs += ['cuda', 'nvrtc'] if not IS_HIP_EXTENSION else []
ext_args += ['-DUSE_GPU']
extension = CUDAExtension
if use_nccl:
if IS_HIP_EXTENSION:
ext_libs += ['rccl']
else:
ext_libs += ['nccl']
ext_args += ['-DUSE_NCCL']
setup(
name='tutel',
version='0.3',
description='An Optimized Mixture-of-Experts Implementation.',
url='https://github.com/microsoft/Tutel',
author='Microsoft',
author_email='tutel@microsoft.com',
license='MIT',
classifiers=[
'Development Status :: 2 - Pre-Alpha',
'Environment :: GPU',
'Intended Audience :: Developers',
'Intended Audience :: Education',
'Intended Audience :: Science/Research',
'License :: OSI Approved :: MIT License',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3 :: Only',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: 3.6',
'Programming Language :: Python :: 3.7',
'Programming Language :: Python :: 3.8',
'Programming Language :: Python :: 3.9',
'Topic :: Scientific/Engineering',
'Topic :: Scientific/Engineering :: Artificial Intelligence',
'Topic :: Software Development',
'Topic :: Software Development :: Libraries',
'Topic :: Software Development :: Libraries :: Python Modules',
],
keywords=['Mixture of Experts', 'MoE', 'Optimization'],
packages=find_packages(exclude=['tests']),
python_requires='>=3.6, <4',
install_requires=[
"numpy",
],
zip_safe=False,
extras_require={
'test': [
'GPUtil>=1.4.0',
'pytest-subtests>=0.4.0',
'pytest>=6.2.2',
],
},
ext_modules=[
extension('tutel_custom_kernel', [
'./tutel/custom/custom_kernel.cpp',
],
library_dirs=['/usr/local/cuda/lib64/stubs'],
libraries=ext_libs,
extra_compile_args={'cxx': ext_args})
],
cmdclass={
'build_ext': BuildExtension,
'test': Tester,
},
project_urls={
'Source': 'https://github.com/microsoft/Tutel',
'Tracker': 'https://github.com/microsoft/Tutel/issues',
},
)
if int(os.environ.get('NO_CUDA', 0)) == 1:
print('Installing without CUDA extension..')
install(use_cuda=False, use_nccl=False)
else:
try:
install(use_cuda=True, use_nccl=True)
except:
print('Try installing without NCCL extension..')
try:
install(use_cuda=True, use_nccl=False)
except:
print('Try installing without CUDA extension..')
install(use_cuda=False, use_nccl=False)