setup.py 2.28 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Copyright (c) 2022-2024, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# See LICENSE for license information.

"""Installation script for TE jax extensions."""

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

import sys
import os
import shutil
from pathlib import Path

import setuptools

try:
    import jax  # pylint: disable=unused-import
except ImportError as e:
    raise RuntimeError("This package needs Jax 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
32
33
34
35


from build_tools.build_ext import get_build_ext
from build_tools.utils import package_files, copy_common_headers, install_and_import
from build_tools.te_version import te_version
from build_tools.jax import setup_jax_extension

36
install_and_import("pybind11")
37
38
39
40
41
42
43
44
from pybind11.setup_helpers import build_ext as BuildExtension

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_jax_extension(
48
49
50
            "csrc", current_file_path / "csrc", current_file_path / common_headers_dir
        )
    ]
51
52
53
54
55
56
57
58
59
60
61
62

    # Configure package
    setuptools.setup(
        name="transformer_engine_jax",
        version=te_version(),
        packages=["csrc", common_headers_dir, "build_tools"],
        description="Transformer acceleration library - Jax Lib",
        ext_modules=ext_modules,
        cmdclass={"build_ext": CMakeBuildExtension},
        install_requires=["jax", "flax>=0.7.1"],
        tests_require=["numpy", "praxis"],
        include_package_data=True,
63
64
65
66
67
        package_data={
            "csrc": package_files("csrc"),
            common_headers_dir: package_files(common_headers_dir),
            "build_tools": package_files("build_tools"),
        },
68
69
70
    )
    if any(x in sys.argv for x in (".", "sdist", "bdist_wheel")):
        shutil.rmtree(common_headers_dir)