setup.py 2.03 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
17
18
19
20
21
22
23
24
25
#
# See LICENSE for license information.

"""Installation script for TE paddle-paddle extensions."""

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

import sys
import os
import shutil
from pathlib import Path

import setuptools
from paddle.utils.cpp_extension import BuildExtension

try:
    import paddle  # pylint: disable=unused-import
except ImportError as e:
    raise RuntimeError("This package needs Paddle Paddle 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):
26
27
28
29
    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)
30
31


32
33
34
35
from build_tools.build_ext import get_build_ext
from build_tools.utils import copy_common_headers
from build_tools.te_version import te_version
from build_tools.paddle import setup_paddle_extension
36
37


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


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

    # Configure package
    setuptools.setup(
        name="transformer_engine_paddle",
        version=te_version(),
        description="Transformer acceleration library - Paddle Paddle Lib",
        ext_modules=ext_modules,
        cmdclass={"build_ext": CMakeBuildExtension},
59
        install_requires=["paddlepaddle-gpu>=2.6.1"],
60
61
62
63
        tests_require=["numpy"],
    )
    if any(x in sys.argv for x in (".", "sdist", "bdist_wheel")):
        shutil.rmtree(common_headers_dir)
64
        shutil.rmtree("build_tools")