forked from NVIDIA/Megatron-LM
-
Notifications
You must be signed in to change notification settings - Fork 0
186 lines (167 loc) · 6.24 KB
/
_build_test_publish_wheel.yml
File metadata and controls
186 lines (167 loc) · 6.24 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
181
182
183
184
185
186
on:
workflow_call:
inputs:
ref:
required: false
description: Ref (SHA or branch) to release
type: string
default: ${{ github.sha }}
dry-run:
required: false
description: Upload to PyPy Test instance
type: boolean
default: true
no-publish:
required: false
description: Do not publish the wheel
type: boolean
default: true
secrets:
TWINE_PASSWORD:
required: true
jobs:
build-and-test-wheels:
strategy:
fail-fast: false
matrix:
include:
- PACKAGE: megatron-core
PLATFORM: arm64
IMAGE: quay.io/pypa/manylinux_2_28_aarch64
- PACKAGE: megatron-core
PLATFORM: amd64
IMAGE: quay.io/pypa/manylinux_2_28_x86_64
- PACKAGE: megatron-fsdp
IMAGE: quay.io/pypa/manylinux_2_28_x86_64
PLATFORM: amd64
runs-on: ${{ matrix.PLATFORM == 'amd64' && 'ubuntu-22.04' || 'ubuntu-22.04-arm' }}
env:
PACKAGE: ${{ matrix.PACKAGE }}
IMAGE: ${{ matrix.IMAGE }}
PLATFORM: ${{ matrix.PLATFORM }}
PUBLISH_DRYRUN: ${{ inputs.dry-run }}
steps:
- name: Checkout repository
uses: actions/checkout@v6
with:
ref: ${{ inputs.ref }}
- name: Build wheel
id: build-wheel
run: |
set -x
if [ "$PACKAGE" = "megatron-core" ]; then
ROOTDIR="megatron/core"
BUILD_DIR="."
elif [ "$PACKAGE" = "megatron-fsdp" ]; then
ROOTDIR="megatron/core/distributed/fsdp/src/megatron_fsdp"
BUILD_DIR="megatron/core/distributed/fsdp/src"
else
echo Unknown package: $PACKAGE
exit 1
fi
if [ "$PUBLISH_DRYRUN" = "true" ]; then
PRE_RELEASE=$(sed -n "s/.*PRE_RELEASE = '\(.*\)'/\1/p" $ROOTDIR/package_info.py)
sed -i "/^PRE_RELEASE/c\PRE_RELEASE = '${PRE_RELEASE}.dev$((RANDOM % 900000 + 100000))'" $ROOTDIR/package_info.py
fi
pushd $BUILD_DIR
rm LICENSE || true
docker run --rm -v $(pwd):/workspace -w /workspace $IMAGE bash -c '\
for python_version in cp311 cp312 cp313; do \
/opt/python/${python_version}-${python_version}/bin/pip install --upgrade "setuptools<80.0.0,>=77.0.0" build; \
done && \
for python_version in cp311 cp312 cp313; do \
/opt/python/${python_version}-${python_version}/bin/python -m build; \
done \
'
PLATFORM_WHEELS=$(find dist -name "*.whl" -not -name "*-none-any.whl")
if [ -n "$PLATFORM_WHEELS" ]; then
echo "Found platform wheels to repair: $PLATFORM_WHEELS"
docker run --rm -v $(pwd):/workspace -w /workspace $IMAGE auditwheel repair $PLATFORM_WHEELS
docker run --rm -v $(pwd):/workspace -w /workspace $IMAGE rm -rf dist/*.whl
docker run --rm -v $(pwd):/workspace -w /workspace $IMAGE cp -a wheelhouse/* dist/
fi
popd
pushd $ROOTDIR
EXPECTED_RELEASE_NUMBER=$(python -c "import package_info; print(package_info.__version__)")
popd
echo "expected-release-number=$EXPECTED_RELEASE_NUMBER" | tee -a "${GITHUB_OUTPUT}"
if [ "$PACKAGE" = "megatron-fsdp" ]; then
mkdir -p dist/
cp -a megatron/core/distributed/fsdp/src/dist/* dist/
fi
ls -al dist/
- name: Test wheels
run: |
ls -al dist/
if [ "$PACKAGE" = "megatron-core" ]; then
ROOTPATH="megatron.core"
WHEEL_PREFIX="megatron_core"
elif [ "$PACKAGE" = "megatron-fsdp" ]; then
ROOTPATH="megatron_fsdp"
WHEEL_PREFIX="megatron_fsdp"
else
echo Unknown package: $PACKAGE
exit 1
fi
if [ "$PACKAGE" = "megatron-core" ]; then
if [[ "$PLATFORM" == "arm64" ]]; then
WHEEL_GLOB="dist/${WHEEL_PREFIX}*cp312*aarch64.whl"
else
WHEEL_GLOB="dist/${WHEEL_PREFIX}*cp312*x86_64.whl"
fi
else
WHEEL_GLOB="dist/${WHEEL_PREFIX}*.whl"
fi
docker run --rm -v $(pwd):/workspace -w /workspace $IMAGE bash -c "\
/opt/python/cp312-cp312/bin/pip install --no-cache-dir $WHEEL_GLOB && \
rm -rf megatron/ && \
RELEASE_NUMBER=\$(/opt/python/cp312-cp312/bin/python -c 'import $ROOTPATH; print($ROOTPATH.__version__)') && \
test '${{ steps.build-wheel.outputs.expected-release-number }}' == \"\$RELEASE_NUMBER\" \
"
- name: Upload wheels
uses: actions/upload-artifact@v6
with:
name: wheels-${{ matrix.PACKAGE }}-${{ matrix.PLATFORM }}-${{ inputs.dry-run && 'dry-run' || 'release' }}
path: dist/
publish-wheels:
needs: [build-and-test-wheels]
runs-on: ubuntu-latest
if: inputs.no-publish == false
strategy:
fail-fast: false
matrix:
include:
- PACKAGE: megatron-core
PLATFORM: arm64
- PACKAGE: megatron-core
PLATFORM: amd64
- PACKAGE: megatron-fsdp
PLATFORM: amd64
env:
PACKAGE: ${{ matrix.PACKAGE }}
steps:
- name: Download wheels
uses: actions/download-artifact@v7
with:
name: wheels-${{ matrix.PACKAGE }}-${{ matrix.PLATFORM }}-${{ inputs.dry-run && 'dry-run' || 'release' }}
path: dist/
merge-multiple: true
- name: Publish wheels
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.TWINE_PASSWORD }}
TWINE_REPOSITORY: ${{ (github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/r')) && 'pypi' || 'testpypi' }}
PLATFORM: ${{ matrix.PLATFORM }}
run: |
# Delete sdist for arm64 since we already upload it with amd64.
if [ "$PLATFORM" == "arm64" ]; then
rm dist/*.tar.gz
fi
ls -al dist/
pip install twine
twine upload \
--verbose \
-r $TWINE_REPOSITORY \
-u $TWINE_USERNAME \
-p $TWINE_PASSWORD \
dist/*