forked from NVIDIA/TransformerEngine
-
Notifications
You must be signed in to change notification settings - Fork 28
286 lines (253 loc) · 10.6 KB
/
Copy pathunit_tests_common.yml
File metadata and controls
286 lines (253 loc) · 10.6 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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
name: Common Unit Tests
on:
workflow_call:
inputs:
platform:
required: true
type: string
device:
required: true
type: string
image:
required: true
type: string
runs_on:
required: true
type: string
container_volumes:
required: true
type: string
container_options:
required: true
type: string
# Platform-specific environment setup script path (from platform config)
setup_script:
required: false
type: string
default: ''
# Platform-specific build environment variables (JSON object from config)
build_env:
required: false
type: string
default: '{}'
jobs:
unit_test:
defaults:
run:
shell: bash
runs-on: ${{ fromJson(inputs.runs_on) }}
strategy:
fail-fast: false
matrix:
test_group:
- name: pytorch_debug
path: "qa/L0_pytorch_debug_unittest/test.sh"
test_type: "debug"
- name: pytorch_unittest
path: "qa/L0_pytorch_unittest/test.sh"
test_type: "unittest"
- name: pytorch_distributed_unittest
path: "qa/L1_pytorch_distributed_unittest/test.sh"
test_type: "unittest"
- name: pytorch_onnx_unittest
path: "qa/L1_pytorch_onnx_unittest/test.sh"
test_type: "unittest"
name: unit-${{ inputs.device }}-${{ matrix.test_group.name }}
container:
image: ${{ inputs.image }}
volumes: ${{ fromJson(inputs.container_volumes) }}
options: --pull never ${{ inputs.container_options }}
steps:
# Cuda requires git safe.directory configuration and 3 checkout attempts to handle submodule-heavy repos
- name: Configure Git Safe Directory on Cuda
if: inputs.platform == 'cuda'
run: /usr/bin/git config --global safe.directory '*'
- name: Checkout Source Code on Cuda (attempt 1)
id: checkout1
if: inputs.platform == 'cuda'
uses: actions/checkout@v4
continue-on-error: true
with:
fetch-depth: 0
submodules: recursive
set-safe-directory: true
- name: Checkout Source Code on Cuda (attempt 2)
id: checkout2
if: inputs.platform == 'cuda' && steps.checkout1.outcome == 'failure'
uses: actions/checkout@v4
continue-on-error: true
with:
fetch-depth: 0
submodules: recursive
set-safe-directory: true
- name: Checkout Source Code on Cuda (attempt 3)
id: checkout3
if: inputs.platform == 'cuda' && steps.checkout2.outcome == 'failure'
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
set-safe-directory: true
# Metax requires to clean vscode-remote-container
- name: Configure Clean Git Env on Metax
if: inputs.platform == 'metax'
run: |
git config --global --unset-all credential.helper 2>/dev/null || true
git config --system --unset-all credential.helper 2>/dev/null || true
# Metax no need submodules
- name: Checkout Source Code on Metax
if: inputs.platform == 'metax'
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Environment Setup
if: inputs.setup_script != ''
run: |
bash $GITHUB_WORKSPACE/${{ inputs.setup_script }}
- name: Execute Tests
working-directory: ${{ github.workspace }}
run: |
set -euo pipefail
# Load platform-specific environment variables
while IFS='=' read -r key value; do
[ -n "$key" ] && export "$key=$value"
done < <(echo '${{ inputs.build_env }}' | python3 -c "
import json, sys
env = json.load(sys.stdin)
for k, v in env.items():
print(f'{k}={v}')
")
# Activate conda environment
if ${{inputs.platform == 'metax'}}; then
source /opt/conda/etc/profile.d/conda.sh
conda activate base
else
source /opt/miniconda3/etc/profile.d/conda.sh
conda activate flagscale-train
fi
echo "PATH=$PATH" >> $GITHUB_ENV
export TE_PATH=$GITHUB_WORKSPACE
export TE_LIB_PATH=$(python3 -c "import site; print(site.getsitepackages()[0])")
export PYTHONPATH=$GITHUB_WORKSPACE:${PYTHONPATH:-}
export PATH=${CUDA_HOME:-/usr/local/cuda}/bin:$PATH
export LD_LIBRARY_PATH=${CUDA_HOME:-/usr/local/cuda}/lib:${LD_LIBRARY_PATH:-}
# check envs before running tests
echo "TE_PATH=$TE_PATH"
echo "TE_LIB_PATH=$TE_LIB_PATH"
echo "PYTHONPATH=$PYTHONPATH"
echo "PATH=$PATH"
echo "LD_LIBRARY_PATH=$LD_LIBRARY_PATH"
# Ensure log directory exists regardless of volume mount state
mkdir -p /logs
# Coverage setup: install once + configure collection via PYTEST_ADDOPTS
COVERAGE_ENABLED=false
if pip3 install coverage pytest-cov --quiet 2>/dev/null; then
export PYTEST_ADDOPTS="--cov=transformer_engine/pytorch --cov=transformer_engine/debug --cov=transformer_engine/plugin --cov-append --cov-report="
COVERAGE_ENABLED=true
else
echo "WARNING: Failed to install coverage/pytest-cov, coverage collection disabled"
fi
if [[ "${{ matrix.test_group.name }}" != *"debug"* ]]; then
# Fail fast on backend/API mismatch before running the full test group.
# Skip for debug group (does not use FP8/optimizer symbols).
python3 -c "import sys, importlib; import transformer_engine.common as _te_common; tex = importlib.import_module('transformer_engine_torch'); required=['multi_tensor_scale','multi_tensor_compute_scale_and_scale_inv']; missing=[n for n in required if not hasattr(tex, n)]; print('[TE check] module:', tex); print('[TE check] file:', getattr(tex, '__file__', 'N/A')); print('[TE check] missing:', ', '.join(missing) if missing else 'none'); sys.exit(1 if missing else 0)"
fi
bash ${{ matrix.test_group.path }}
exit_code=$?
# Combine coverage fragments and generate JSON report
if [ "$COVERAGE_ENABLED" = "true" ]; then
python3 -m coverage combine --keep 2>/dev/null || true
python3 -m coverage json \
-o "coverage-${{ inputs.platform }}-${{ inputs.device }}-${{ matrix.test_group.name }}.json" \
--include="transformer_engine/pytorch/*,transformer_engine/debug/*,transformer_engine/plugin/*" \
--omit="*/setup.py,*/transformer_engine/plugin/core/_build_config.py" \
-i 2>/dev/null \
|| echo "WARNING: No coverage data found"
if [ -f .coverage ]; then
cp .coverage "coverage-${{ inputs.platform }}-${{ inputs.device }}-${{ matrix.test_group.name }}.coverage"
fi
fi
exit $exit_code
timeout-minutes: 60
- name: Upload Coverage Artifact
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: coverage-${{ inputs.platform }}-${{ inputs.device }}-${{ matrix.test_group.name }}
path: |
coverage-${{ inputs.platform }}-${{ inputs.device }}-${{ matrix.test_group.name }}.json
coverage-${{ inputs.platform }}-${{ inputs.device }}-${{ matrix.test_group.name }}.coverage
aggregate_coverage:
name: unit-${{ inputs.device }}-pytorch-unittest-coverage
needs: unit_test
if: always()
defaults:
run:
shell: bash
runs-on: ${{ fromJson(inputs.runs_on) }}
container:
image: ${{ inputs.image }}
volumes: ${{ fromJson(inputs.container_volumes) }}
options: --pull never ${{ inputs.container_options }}
steps:
- name: Checkout Source Code
uses: actions/checkout@v4
with:
fetch-depth: 0
set-safe-directory: true
- name: Download Coverage Artifacts
uses: actions/download-artifact@v4
continue-on-error: true
with:
pattern: coverage-${{ inputs.platform }}-${{ inputs.device }}-pytorch_*
path: coverage-artifacts
merge-multiple: true
- name: Aggregate PyTorch Coverage
id: aggregate
run: |
set -euo pipefail
if ${{inputs.platform == 'metax'}}; then
source /opt/conda/etc/profile.d/conda.sh
conda activate base
else
source /opt/miniconda3/etc/profile.d/conda.sh
conda activate flagscale-train
fi
python3 -m pip install coverage --quiet
mkdir -p coverage-raw
coverage_count=0
for coverage_file in coverage-artifacts/*.coverage; do
[ -f "$coverage_file" ] || continue
coverage_count=$((coverage_count + 1))
cp "$coverage_file" "coverage-raw/.coverage.$coverage_count"
done
if [ "$coverage_count" -eq 0 ]; then
echo "WARNING: No raw coverage files found for aggregation"
echo "coverage_aggregated=false" >> "$GITHUB_OUTPUT"
exit 0
fi
python3 -m coverage combine coverage-raw
python3 -m coverage json \
-o "coverage-${{ inputs.platform }}-${{ inputs.device }}-pytorch-unittest.json" \
--include="transformer_engine/pytorch/*,transformer_engine/debug/*,transformer_engine/plugin/*" \
--omit="*/setup.py,*/transformer_engine/plugin/core/_build_config.py" \
-i
echo "coverage_aggregated=true" >> "$GITHUB_OUTPUT"
- name: Upload Aggregated Coverage Artifact
if: steps.aggregate.outputs.coverage_aggregated == 'true'
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: coverage-${{ inputs.platform }}-${{ inputs.device }}-pytorch-unittest
path: coverage-${{ inputs.platform }}-${{ inputs.device }}-pytorch-unittest.json
- name: Upload Coverage Report to FlagCICD
if: steps.aggregate.outputs.coverage_aggregated == 'true'
uses: flagos-ai/FlagOps/actions/post-pytest-report@v2
continue-on-error: true
env:
NO_PROXY: "flagcicd-inner.flagos.net"
with:
backend_url: 'http://flagcicd-inner.flagos.net:8000/metrics/'
user_id: '000000000000000000'
report_path: 'coverage-${{ inputs.platform }}-${{ inputs.device }}-pytorch-unittest.json'
fail_on_error: 'false'