forked from NVIDIA/TransformerEngine
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup.py
More file actions
Latest commit
180 lines (144 loc) · 5.95 KB
/
Copy pathsetup.py
File metadata and controls
180 lines (144 loc) · 5.95 KB
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# Copyright (c) 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# See LICENSE for license information.
"""Installation script."""
importos
importtime
frompathlibimportPath
fromtypingimportList, Tuple
importsetuptools
fromwheel.bdist_wheelimportbdist_wheel
frombuild_tools.build_extimportCMakeExtension, get_build_ext
frombuild_tools.te_versionimportte_version
frombuild_tools.utilsimport (
cuda_archs,
get_frameworks,
remove_dups,
)
frameworks=get_frameworks()
current_file_path=Path(__file__).parent.resolve()
fromsetuptools.command.build_extimportbuild_extasBuildExtension
os.environ["NVTE_PROJECT_BUILDING"] ="1"
if"pytorch"inframeworks:
fromtorch.utils.cpp_extensionimportBuildExtension
elif"jax"inframeworks:
frompybind11.setup_helpersimportbuild_extasBuildExtension
CMakeBuildExtension=get_build_ext(BuildExtension)
archs=cuda_archs()
classTimedBdist(bdist_wheel):
"""Helper class to measure build time"""
defrun(self):
start_time=time.perf_counter()
super().run()
total_time=time.perf_counter() -start_time
print(f"Total time for bdist_wheel: {total_time:.2f} seconds")
defsetup_common_extension() ->CMakeExtension:
"""Setup CMake extension for common library"""
cmake_flags= ["-DCMAKE_CUDA_ARCHITECTURES={}".format(archs)]
ifbool(int(os.getenv("NVTE_UB_WITH_MPI", "0"))):
assert (
os.getenv("MPI_HOME") isnotNone
), "MPI_HOME must be set when compiling with NVTE_UB_WITH_MPI=1"
cmake_flags.append("-DNVTE_UB_WITH_MPI=ON")
ifbool(int(os.getenv("NVTE_ENABLE_NVSHMEM", "0"))):
assert (
os.getenv("NVSHMEM_HOME") isnotNone
), "NVSHMEM_HOME must be set when compiling with NVTE_ENABLE_NVSHMEM=1"
cmake_flags.append("-DNVTE_ENABLE_NVSHMEM=ON")
ifbool(int(os.getenv("NVTE_BUILD_ACTIVATION_WITH_FAST_MATH", "0"))):
cmake_flags.append("-DNVTE_BUILD_ACTIVATION_WITH_FAST_MATH=ON")
# Project directory root
root_path=Path(__file__).resolve().parent
returnCMakeExtension(
name="transformer_engine",
cmake_path=root_path/Path("transformer_engine/common"),
cmake_flags=cmake_flags,
)
defsetup_requirements() ->Tuple[List[str], List[str]]:
"""Setup Python dependencies
Returns dependencies for runtime and testing.
"""
# Common requirements
install_reqs: List[str] = [
"pydantic",
"importlib-metadata>=1.0",
"packaging",
]
test_reqs: List[str] = ["pytest>=8.2.1"]
# Framework-specific requirements
ifnotbool(int(os.getenv("NVTE_RELEASE_BUILD", "0"))):
if"pytorch"inframeworks:
frombuild_tools.pytorchimportinstall_requirements, test_requirements
install_reqs.extend(install_requirements())
test_reqs.extend(test_requirements())
if"jax"inframeworks:
frombuild_tools.jaximportinstall_requirements, test_requirements
install_reqs.extend(install_requirements())
test_reqs.extend(test_requirements())
return [remove_dups(reqs) forreqsin [install_reqs, test_reqs]]
if__name__=="__main__":
__version__=te_version()
withopen("README.rst", encoding="utf-8") asf:
long_description=f.read()
# Settings for building top level empty package for dependency management.
ifbool(int(os.getenv("NVTE_BUILD_METAPACKAGE", "0"))):
assertbool(
int(os.getenv("NVTE_RELEASE_BUILD", "0"))
), "NVTE_RELEASE_BUILD env must be set for metapackage build."
ext_modules= []
package_data= {}
include_package_data=False
install_requires= ([f"transformer_engine_cu12=={__version__}"],)
extras_require= {
"pytorch": [f"transformer_engine_torch=={__version__}"],
"jax": [f"transformer_engine_jax=={__version__}"],
}
else:
install_requires, test_requires=setup_requirements()
ext_modules= [setup_common_extension()]
package_data= {"": ["VERSION.txt"]}
include_package_data=True
extras_require= {"test": test_requires}
ifnotbool(int(os.getenv("NVTE_RELEASE_BUILD", "0"))):
if"pytorch"inframeworks:
frombuild_tools.pytorchimportsetup_pytorch_extension
ext_modules.append(
setup_pytorch_extension(
"transformer_engine/pytorch/csrc",
current_file_path/"transformer_engine"/"pytorch"/"csrc",
current_file_path/"transformer_engine",
)
)
if"jax"inframeworks:
frombuild_tools.jaximportsetup_jax_extension
ext_modules.append(
setup_jax_extension(
"transformer_engine/jax/csrc",
current_file_path/"transformer_engine"/"jax"/"csrc",
current_file_path/"transformer_engine",
)
)
# Configure package
setuptools.setup(
name="transformer_engine",
version=__version__,
packages=setuptools.find_packages(
include=[
"transformer_engine",
"transformer_engine.*",
"transformer_engine/build_tools",
],
),
extras_require=extras_require,
description="Transformer acceleration library",
long_description=long_description,
long_description_content_type="text/x-rst",
ext_modules=ext_modules,
cmdclass={"build_ext": CMakeBuildExtension, "bdist_wheel": TimedBdist},
python_requires=">=3.8",
classifiers=["Programming Language :: Python :: 3"],
install_requires=install_requires,
license_files=("LICENSE",),
include_package_data=include_package_data,
package_data=package_data,
)