build_wheels.sh 2.76 KB
Newer Older
1
# Copyright (c) 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
2
3
4
5
6
7
#
# See LICENSE for license information.

set -e

PLATFORM=${1:-manylinux_2_28_x86_64}
8
9
BUILD_METAPACKAGE=${2:-true}
BUILD_COMMON=${3:-true}
10
BUILD_PYTORCH=${4:-true}
11
BUILD_JAX=${5:-true}
12
CUDA_MAJOR=${6:-12}
13
14

export NVTE_RELEASE_BUILD=1
15
export PIP_CONSTRAINT=""
16
17
export TARGET_BRANCH=${TARGET_BRANCH:-}
mkdir -p /wheelhouse/logs
18
19
20
21
22
23
24

# Generate wheels for common library.
git config --global --add safe.directory /TransformerEngine
cd /TransformerEngine
git checkout $TARGET_BRANCH
git submodule update --init --recursive

25
# Install deps
26
/opt/python/cp310-cp310/bin/pip install cmake pybind11[global] ninja setuptools wheel nvidia-mathdx==25.1.1
27

28
29
30
31
32
33
if $BUILD_METAPACKAGE ; then
        cd /TransformerEngine
        NVTE_BUILD_METAPACKAGE=1 /opt/python/cp310-cp310/bin/python setup.py bdist_wheel 2>&1 | tee /wheelhouse/logs/metapackage.txt
        mv dist/* /wheelhouse/
fi

34
if $BUILD_COMMON ; then
35
36
37
38
        VERSION=`cat build_tools/VERSION.txt`
        WHL_BASE="transformer_engine-${VERSION}"

        # Create the wheel.
39
        /opt/python/cp310-cp310/bin/python setup.py bdist_wheel --verbose --python-tag=py3 --plat-name=$PLATFORM 2>&1 | tee /wheelhouse/logs/common.txt
40

41
        # Repack the wheel for specific cuda version.
42
        /opt/python/cp310-cp310/bin/wheel unpack dist/*
43
        # From python 3.10 to 3.11, the package name delimiter in metadata got changed from - (hyphen) to _ (underscore).
44
45
46
        sed -i "s/Name: transformer-engine/Name: transformer-engine-cu${CUDA_MAJOR}/g" "transformer_engine-${VERSION}/transformer_engine-${VERSION}.dist-info/METADATA"
        sed -i "s/Name: transformer_engine/Name: transformer_engine_cu${CUDA_MAJOR}/g" "transformer_engine-${VERSION}/transformer_engine-${VERSION}.dist-info/METADATA"
        mv "${WHL_BASE}/${WHL_BASE}.dist-info" "${WHL_BASE}/transformer_engine_cu${CUDA_MAJOR}-${VERSION}.dist-info"
47
        /opt/python/cp310-cp310/bin/wheel pack ${WHL_BASE}
48
49

        # Rename the wheel to make it python version agnostic.
50
51
        whl_name=$(basename dist/*)
        IFS='-' read -ra whl_parts <<< "$whl_name"
52
        whl_name_target="${whl_parts[0]}_cu${CUDA_MAJOR}-${whl_parts[1]}-py3-none-${whl_parts[4]}"
53
54
        rm -rf $WHL_BASE dist
        mv *.whl /wheelhouse/"$whl_name_target"
55
56
57
58
fi

if $BUILD_PYTORCH ; then
	cd /TransformerEngine/transformer_engine/pytorch
59
	/opt/python/cp310-cp310/bin/pip install torch
60
	/opt/python/cp310-cp310/bin/python setup.py sdist 2>&1 | tee /wheelhouse/logs/torch.txt
61
62
63
64
65
	cp dist/* /wheelhouse/
fi

if $BUILD_JAX ; then
	cd /TransformerEngine/transformer_engine/jax
66
	/opt/python/cp310-cp310/bin/pip install "jax[cuda${CUDA_MAJOR}_local]" jaxlib
67
	/opt/python/cp310-cp310/bin/python setup.py sdist 2>&1 | tee /wheelhouse/logs/jax.txt
68
69
	cp dist/* /wheelhouse/
fi