setup.py 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. #!/usr/bin/env python3
  2. # Copyright (c) Microsoft Corporation.
  3. # Licensed under the MIT License.
  4. """The setuptools based setup module.
  5. Reference:
  6. https://packaging.python.org/guides/distributing-packages-using-setuptools/
  7. """
  8. import os, sys
  9. import subprocess
  10. import platform as pf
  11. import shutil
  12. from typing import List, Tuple
  13. from setuptools import setup, find_packages, Command
  14. from torch.utils.cpp_extension import BuildExtension, CUDAExtension, CppExtension
  15. try:
  16. from torch.utils.cpp_extension import IS_HIP_EXTENSION
  17. except:
  18. IS_HIP_EXTENSION = False
  19. if len(sys.argv) <= 1:
  20. sys.argv += ['install']
  21. root_path = os.path.dirname(sys.argv[0])
  22. root_path = root_path if root_path else '.'
  23. root_path = os.path.abspath(root_path)
  24. os.chdir(root_path)
  25. class Tester(Command):
  26. """Cmdclass for `python setup.py test`.
  27. Args:
  28. Command (distutils.cmd.Command):
  29. Abstract base class for defining command classes.
  30. """
  31. description = 'test the code using pytest'
  32. user_options: List[Tuple[str, str, str]] = []
  33. def initialize_options(self):
  34. """Set default values for options that this command supports."""
  35. pass
  36. def finalize_options(self):
  37. """Set final values for options that this command supports."""
  38. pass
  39. def run(self):
  40. """Run pytest."""
  41. subprocess.check_call('python3 -m pytest -v -s tests/', shell=True)
  42. def install(use_cuda, use_nccl):
  43. ext_libs = []
  44. ext_args = ['-Wno-sign-compare', '-Wno-unused-but-set-variable', '-Wno-terminate', '-Wno-unused-function', '-Wno-strict-aliasing'] if pf.system() == 'Linux' else []
  45. if not use_cuda:
  46. use_nccl = False
  47. extension = CppExtension
  48. else:
  49. ext_libs += ['cuda', 'nvrtc'] if not IS_HIP_EXTENSION else []
  50. ext_args += ['-DUSE_GPU']
  51. extension = CUDAExtension
  52. if use_nccl:
  53. if IS_HIP_EXTENSION:
  54. ext_libs += ['rccl']
  55. else:
  56. ext_libs += ['nccl']
  57. ext_args += ['-DUSE_NCCL']
  58. setup(
  59. name='tutel',
  60. version='0.3',
  61. description='An Optimized Mixture-of-Experts Implementation.',
  62. url='https://github.com/microsoft/Tutel',
  63. author='Microsoft',
  64. author_email='tutel@microsoft.com',
  65. license='MIT',
  66. classifiers=[
  67. 'Development Status :: 2 - Pre-Alpha',
  68. 'Environment :: GPU',
  69. 'Intended Audience :: Developers',
  70. 'Intended Audience :: Education',
  71. 'Intended Audience :: Science/Research',
  72. 'License :: OSI Approved :: MIT License',
  73. 'Programming Language :: Python :: 3',
  74. 'Programming Language :: Python :: 3 :: Only',
  75. 'Programming Language :: Python :: 3.5',
  76. 'Programming Language :: Python :: 3.6',
  77. 'Programming Language :: Python :: 3.7',
  78. 'Programming Language :: Python :: 3.8',
  79. 'Programming Language :: Python :: 3.9',
  80. 'Topic :: Scientific/Engineering',
  81. 'Topic :: Scientific/Engineering :: Artificial Intelligence',
  82. 'Topic :: Software Development',
  83. 'Topic :: Software Development :: Libraries',
  84. 'Topic :: Software Development :: Libraries :: Python Modules',
  85. ],
  86. keywords=['Mixture of Experts', 'MoE', 'Optimization'],
  87. packages=find_packages(exclude=['tests']),
  88. python_requires='>=3.6, <4',
  89. install_requires=[
  90. "numpy",
  91. ],
  92. zip_safe=False,
  93. extras_require={
  94. 'test': [
  95. 'GPUtil>=1.4.0',
  96. 'pytest-subtests>=0.4.0',
  97. 'pytest>=6.2.2',
  98. ],
  99. },
  100. ext_modules=[
  101. extension('tutel_custom_kernel', [
  102. './tutel/custom/custom_kernel.cpp',
  103. ],
  104. library_dirs=['/usr/local/cuda/lib64/stubs'],
  105. libraries=ext_libs,
  106. extra_compile_args={'cxx': ext_args})
  107. ],
  108. cmdclass={
  109. 'build_ext': BuildExtension,
  110. 'test': Tester,
  111. },
  112. project_urls={
  113. 'Source': 'https://github.com/microsoft/Tutel',
  114. 'Tracker': 'https://github.com/microsoft/Tutel/issues',
  115. },
  116. )
  117. if int(os.environ.get('NO_CUDA', 0)) == 1:
  118. print('Installing without CUDA extension..')
  119. install(use_cuda=False, use_nccl=False)
  120. else:
  121. try:
  122. install(use_cuda=True, use_nccl=True)
  123. except:
  124. print('Try installing without NCCL extension..')
  125. try:
  126. install(use_cuda=True, use_nccl=False)
  127. except:
  128. print('Try installing without CUDA extension..')
  129. install(use_cuda=False, use_nccl=False)