setup.py 2.01 KB
Newer Older
1
# Copyright (c) 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#
# See LICENSE for license information.

"""Installation script for TE pytorch extensions."""

# pylint: disable=wrong-import-position,wrong-import-order

import sys
import os
import shutil
from pathlib import Path

import setuptools

try:
17
    from torch.utils.cpp_extension import BuildExtension
18
19
20
21
22
23
24
except ImportError as e:
    raise RuntimeError("This package needs Torch to build.") from e


current_file_path = Path(__file__).parent.resolve()
build_tools_dir = current_file_path.parent.parent / "build_tools"
if bool(int(os.getenv("NVTE_RELEASE_BUILD", "0"))) or os.path.isdir(build_tools_dir):
25
26
27
28
    build_tools_copy = current_file_path / "build_tools"
    if build_tools_copy.exists():
        shutil.rmtree(build_tools_copy)
    shutil.copytree(build_tools_dir, build_tools_copy)
29
30
31


from build_tools.build_ext import get_build_ext
32
from build_tools.utils import copy_common_headers
33
from build_tools.te_version import te_version
34
from build_tools.pytorch import setup_pytorch_extension, install_requirements, test_requirements
35
36


37
os.environ["NVTE_PROJECT_BUILDING"] = "1"
38
CMakeBuildExtension = get_build_ext(BuildExtension, True)
39
40
41
42
43


if __name__ == "__main__":
    # Extensions
    common_headers_dir = "common_headers"
44
    copy_common_headers(current_file_path.parent, str(current_file_path / common_headers_dir))
45
46
    ext_modules = [
        setup_pytorch_extension(
47
48
49
            "csrc", current_file_path / "csrc", current_file_path / common_headers_dir
        )
    ]
50
51
52
53
54
55
56
57

    # Configure package
    setuptools.setup(
        name="transformer_engine_torch",
        version=te_version(),
        description="Transformer acceleration library - Torch Lib",
        ext_modules=ext_modules,
        cmdclass={"build_ext": CMakeBuildExtension},
58
59
        install_requires=install_requirements(),
        tests_require=test_requirements(),
60
61
62
    )
    if any(x in sys.argv for x in (".", "sdist", "bdist_wheel")):
        shutil.rmtree(common_headers_dir)
63
        shutil.rmtree("build_tools")