2021-10-28 16:21:23 +00:00
|
|
|
import os
|
2023-03-07 10:04:10 +00:00
|
|
|
import sys
|
2023-03-03 13:45:05 +00:00
|
|
|
from typing import List
|
2022-11-17 05:42:33 +00:00
|
|
|
|
2023-01-03 12:29:39 +00:00
|
|
|
from setuptools import find_packages, setup
|
2021-10-28 16:21:23 +00:00
|
|
|
|
2022-11-30 08:45:15 +00:00
|
|
|
try:
|
2024-01-25 09:01:48 +00:00
|
|
|
import torch # noqa
|
|
|
|
from torch.utils.cpp_extension import BuildExtension
|
2023-09-19 06:20:26 +00:00
|
|
|
|
2023-01-05 05:53:28 +00:00
|
|
|
TORCH_AVAILABLE = True
|
2022-11-30 08:45:15 +00:00
|
|
|
except ImportError:
|
2023-01-05 05:53:28 +00:00
|
|
|
TORCH_AVAILABLE = False
|
2022-11-30 08:45:15 +00:00
|
|
|
|
2023-03-03 13:45:05 +00:00
|
|
|
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
|
2024-01-25 09:01:48 +00:00
|
|
|
BUILD_EXT = int(os.environ.get("BUILD_EXT", "0")) == 1
|
2023-03-03 13:45:05 +00:00
|
|
|
|
2023-03-07 10:04:10 +00:00
|
|
|
# we do not support windows currently
|
2023-09-19 06:20:26 +00:00
|
|
|
if sys.platform == "win32":
|
2023-03-07 10:04:10 +00:00
|
|
|
raise RuntimeError("Windows is not supported yet. Please try again within the Windows Subsystem for Linux (WSL).")
|
|
|
|
|
2023-03-03 13:45:05 +00:00
|
|
|
|
|
|
|
def fetch_requirements(path) -> List[str]:
|
|
|
|
"""
|
|
|
|
This function reads the requirements file.
|
|
|
|
|
|
|
|
Args:
|
|
|
|
path (str): the path to the requirements file.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The lines in the requirements file.
|
|
|
|
"""
|
2023-09-19 06:20:26 +00:00
|
|
|
with open(path, "r") as fd:
|
2021-11-15 08:43:28 +00:00
|
|
|
return [r.strip() for r in fd.readlines()]
|
|
|
|
|
|
|
|
|
2023-03-03 13:45:05 +00:00
|
|
|
def fetch_readme() -> str:
|
|
|
|
"""
|
|
|
|
This function reads the README.md file in the current directory.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The lines in the README file.
|
|
|
|
"""
|
2023-09-19 06:20:26 +00:00
|
|
|
with open("README.md", encoding="utf-8") as f:
|
2022-02-15 07:15:03 +00:00
|
|
|
return f.read()
|
|
|
|
|
|
|
|
|
2023-03-03 13:45:05 +00:00
|
|
|
def get_version() -> str:
|
|
|
|
"""
|
|
|
|
This function reads the version.txt and generates the colossalai/version.py file.
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
The library version stored in version.txt.
|
|
|
|
"""
|
|
|
|
|
2022-11-30 08:45:15 +00:00
|
|
|
setup_file_path = os.path.abspath(__file__)
|
|
|
|
project_path = os.path.dirname(setup_file_path)
|
2023-09-19 06:20:26 +00:00
|
|
|
version_txt_path = os.path.join(project_path, "version.txt")
|
|
|
|
version_py_path = os.path.join(project_path, "colossalai/version.py")
|
2022-11-30 08:45:15 +00:00
|
|
|
|
|
|
|
with open(version_txt_path) as f:
|
2022-04-27 07:26:12 +00:00
|
|
|
version = f.read().strip()
|
2022-02-15 07:15:03 +00:00
|
|
|
|
2022-11-30 08:45:15 +00:00
|
|
|
# write version into version.py
|
2023-09-19 06:20:26 +00:00
|
|
|
with open(version_py_path, "w") as f:
|
2022-11-30 08:45:15 +00:00
|
|
|
f.write(f"__version__ = '{version}'\n")
|
|
|
|
return version
|
2022-10-03 09:13:30 +00:00
|
|
|
|
|
|
|
|
2024-01-25 09:01:48 +00:00
|
|
|
if BUILD_EXT:
|
|
|
|
if not TORCH_AVAILABLE:
|
|
|
|
raise ModuleNotFoundError(
|
2024-03-05 07:35:54 +00:00
|
|
|
"[extension] PyTorch is not found while BUILD_EXT=1. You need to install PyTorch first in order to build CUDA extensions"
|
2024-01-25 09:01:48 +00:00
|
|
|
)
|
2023-01-06 12:50:26 +00:00
|
|
|
|
2024-01-25 09:01:48 +00:00
|
|
|
from extensions import ALL_EXTENSIONS
|
2023-09-19 06:20:26 +00:00
|
|
|
|
2023-03-03 13:45:05 +00:00
|
|
|
op_names = []
|
2024-01-25 09:01:48 +00:00
|
|
|
ext_modules = []
|
2023-03-03 13:45:05 +00:00
|
|
|
|
2024-01-25 09:01:48 +00:00
|
|
|
for ext_cls in ALL_EXTENSIONS:
|
|
|
|
ext = ext_cls()
|
2024-03-27 03:19:32 +00:00
|
|
|
if ext.support_aot and ext.is_available():
|
|
|
|
ext.assert_compatible()
|
2024-01-25 09:01:48 +00:00
|
|
|
op_names.append(ext.name)
|
|
|
|
ext_modules.append(ext.build_aot())
|
2022-11-17 05:42:33 +00:00
|
|
|
|
2023-03-03 13:45:05 +00:00
|
|
|
# show log
|
2024-01-25 09:01:48 +00:00
|
|
|
if len(ext_modules) == 0:
|
|
|
|
raise RuntimeError("[extension] Could not find any kernel compatible with the current environment.")
|
|
|
|
else:
|
|
|
|
op_name_list = ", ".join(op_names)
|
|
|
|
print(f"[extension] Building extensions{op_name_list}")
|
|
|
|
else:
|
|
|
|
ext_modules = []
|
2023-03-03 13:45:05 +00:00
|
|
|
|
2024-02-27 07:19:13 +00:00
|
|
|
version = get_version()
|
|
|
|
package_name = "colossalai"
|
2023-09-19 06:20:26 +00:00
|
|
|
|
|
|
|
setup(
|
|
|
|
name=package_name,
|
|
|
|
version=version,
|
|
|
|
packages=find_packages(
|
|
|
|
exclude=(
|
2024-02-27 07:19:13 +00:00
|
|
|
"extensions",
|
2023-09-19 06:20:26 +00:00
|
|
|
"benchmark",
|
|
|
|
"docker",
|
|
|
|
"tests",
|
|
|
|
"docs",
|
|
|
|
"examples",
|
|
|
|
"tests",
|
|
|
|
"scripts",
|
|
|
|
"requirements",
|
|
|
|
"*.egg-info",
|
2024-02-26 11:46:58 +00:00
|
|
|
),
|
2023-09-19 06:20:26 +00:00
|
|
|
),
|
|
|
|
description="An integrated large-scale model training system with efficient parallelization techniques",
|
|
|
|
long_description=fetch_readme(),
|
|
|
|
long_description_content_type="text/markdown",
|
|
|
|
license="Apache Software License 2.0",
|
|
|
|
url="https://www.colossalai.org",
|
|
|
|
project_urls={
|
|
|
|
"Forum": "https://github.com/hpcaitech/ColossalAI/discussions",
|
|
|
|
"Bug Tracker": "https://github.com/hpcaitech/ColossalAI/issues",
|
|
|
|
"Examples": "https://github.com/hpcaitech/ColossalAI-Examples",
|
|
|
|
"Documentation": "http://colossalai.readthedocs.io",
|
|
|
|
"Github": "https://github.com/hpcaitech/ColossalAI",
|
|
|
|
},
|
|
|
|
ext_modules=ext_modules,
|
|
|
|
cmdclass={"build_ext": BuildExtension} if ext_modules else {},
|
|
|
|
install_requires=fetch_requirements("requirements/requirements.txt"),
|
|
|
|
entry_points="""
|
2022-04-19 02:59:44 +00:00
|
|
|
[console_scripts]
|
2022-04-19 07:14:54 +00:00
|
|
|
colossalai=colossalai.cli:cli
|
2023-09-19 06:20:26 +00:00
|
|
|
""",
|
|
|
|
python_requires=">=3.6",
|
|
|
|
classifiers=[
|
|
|
|
"Programming Language :: Python :: 3",
|
|
|
|
"License :: OSI Approved :: Apache Software License",
|
|
|
|
"Environment :: GPU :: NVIDIA CUDA",
|
|
|
|
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
|
|
"Topic :: System :: Distributed Computing",
|
|
|
|
],
|
|
|
|
package_data={
|
|
|
|
"colossalai": [
|
2024-02-26 11:46:58 +00:00
|
|
|
"kernel/extensions/csrc/**/*",
|
2024-06-06 03:47:48 +00:00
|
|
|
"kernel/extensions/pybind/**/*",
|
2023-09-19 06:20:26 +00:00
|
|
|
]
|
|
|
|
},
|
|
|
|
)
|