forked from NVIDIA/TransformerEngine
-
Notifications
You must be signed in to change notification settings - Fork 30
299 lines (275 loc) · 10.2 KB
/
Copy pathunit_tests_common.yml
File metadata and controls
299 lines (275 loc) · 10.2 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
287
288
289
290
291
292
293
294
295
296
297
298
299
name: Common Unit Tests
on:
workflow_call:
inputs:
platform:
required: true
type: string
device:
required: true
type: string
image:
required: true
type: string
container_pull_policy:
required: false
type: string
default: never
runs_on:
required: true
type: string
container_volumes:
required: true
type: string
container_options:
required: true
type: string
checkout_submodules:
required: false
type: string
default: 'false'
setup_script:
required: false
type: string
default: ''
test_artifact_name:
required: false
type: string
default: ''
test_artifact_path:
required: false
type: string
default: ''
test_matrix:
required: true
type: string
timeout_minutes:
required: false
type: number
default: 90
coverage_enabled:
required: false
type: boolean
default: false
coverage_required:
required: false
type: boolean
default: false
coverage_sources:
required: false
type: string
default: ''
coverage_include:
required: false
type: string
default: ''
coverage_omit:
required: false
type: string
default: ''
coverage_python:
required: false
type: string
default: python3
jobs:
unit_test:
defaults:
run:
shell: bash
runs-on: ${{ fromJson(inputs.runs_on) }}
strategy:
fail-fast: false
matrix:
test_group: ${{ fromJson(inputs.test_matrix) }}
name: unit-${{ inputs.device }}-${{ matrix.test_group.name }}
container:
image: ${{ inputs.image }}
volumes: ${{ fromJson(inputs.container_volumes) }}
options: --pull ${{ inputs.container_pull_policy }} ${{ inputs.container_options }}
steps:
- name: Prepare checkout environment
run: |
/usr/bin/git config --global safe.directory '*'
/usr/bin/git config --global --unset-all credential.helper 2>/dev/null || true
/usr/bin/git config --system --unset-all credential.helper 2>/dev/null || true
- name: Checkout source code
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: ${{ inputs.checkout_submodules }}
set-safe-directory: true
- name: Download prebuilt test artifact
if: inputs.test_artifact_name != ''
uses: actions/download-artifact@v4
with:
name: ${{ inputs.test_artifact_name }}
path: ${{ github.workspace }}/${{ inputs.test_artifact_path }}
- name: Set up test environment
if: inputs.setup_script != ''
env:
TE_CI_ARTIFACT_DIR: ${{ inputs.test_artifact_path }}
run: bash "$GITHUB_WORKSPACE/${{ inputs.setup_script }}"
- name: Execute tests
working-directory: ${{ github.workspace }}
env:
TE_TEST_GROUP_JSON: ${{ toJson(matrix.test_group) }}
COVERAGE_ENABLED: ${{ inputs.coverage_enabled }}
COVERAGE_REQUIRED: ${{ inputs.coverage_required }}
COVERAGE_SOURCES: ${{ inputs.coverage_sources }}
COVERAGE_INCLUDE: ${{ inputs.coverage_include }}
COVERAGE_OMIT: ${{ inputs.coverage_omit }}
run: |
set -euo pipefail
export TE_PATH="$GITHUB_WORKSPACE"
export TE_LIB_PATH="$(python3 -c 'import site; print(site.getsitepackages()[0])')"
export PYTHONPATH="$GITHUB_WORKSPACE:${PYTHONPATH:-}"
mkdir -p logs
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:-}"
coverage_active=false
if [ "$COVERAGE_ENABLED" = "true" ]; then
if python3 -c "import importlib.metadata as m; import coverage, pytest_cov; print('[coverage] coverage', m.version('coverage'), 'pytest-cov', m.version('pytest-cov'))"; then
coverage_args=""
IFS=',' read -ra sources <<< "$COVERAGE_SOURCES"
for source in "${sources[@]}"; do
[ -n "$source" ] && coverage_args+=" --cov=$source"
done
export PYTEST_ADDOPTS="${PYTEST_ADDOPTS:-}${coverage_args} --cov-append --cov-report="
coverage_active=true
elif [ "$COVERAGE_REQUIRED" = "true" ]; then
echo "Coverage dependencies are required but missing from the CI image: coverage pytest-cov" >&2
exit 1
else
echo "WARNING: Coverage dependencies are missing from the CI image; collection disabled"
fi
fi
set +e
python3 tests/test_utils/run_ci_test_group.py
test_exit=$?
set -e
coverage_exit=0
if [ "$coverage_active" = "true" ]; then
shopt -s nullglob
coverage_fragments=(.coverage.*)
shopt -u nullglob
if [ "${#coverage_fragments[@]}" -gt 0 ]; then
python3 -m coverage combine --keep
fi
coverage_name="coverage-${{ inputs.platform }}-${{ inputs.device }}-${{ matrix.test_group.name }}"
if [ -f .coverage ]; then
coverage_command=(
python3 -m coverage json
-o "${coverage_name}.json"
-i
)
if [ -n "$COVERAGE_INCLUDE" ]; then
coverage_command+=(--include="$COVERAGE_INCLUDE")
fi
if [ -n "$COVERAGE_OMIT" ]; then
coverage_command+=(--omit="$COVERAGE_OMIT")
fi
"${coverage_command[@]}"
cp .coverage "${coverage_name}.coverage"
else
echo "WARNING: No raw coverage data found for ${{ matrix.test_group.name }}"
[ "$COVERAGE_REQUIRED" = "true" ] && coverage_exit=1
fi
fi
[ "$test_exit" -eq 0 ] && [ "$coverage_exit" -eq 0 ]
timeout-minutes: ${{ inputs.timeout_minutes }}
- name: Upload coverage artifact
if: ${{ !cancelled() && inputs.coverage_enabled }}
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
if-no-files-found: ignore
aggregate_coverage:
name: unit-${{ inputs.device }}-pytorch-unittest-coverage
needs: unit_test
if: ${{ !cancelled() && inputs.coverage_enabled }}
defaults:
run:
shell: bash
runs-on: ${{ fromJson(inputs.runs_on) }}
container:
image: ${{ inputs.image }}
volumes: ${{ fromJson(inputs.container_volumes) }}
options: --pull ${{ inputs.container_pull_policy }} ${{ 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
env:
COVERAGE_REQUIRED: ${{ inputs.coverage_required }}
COVERAGE_INCLUDE: ${{ inputs.coverage_include }}
COVERAGE_OMIT: ${{ inputs.coverage_omit }}
COVERAGE_PYTHON: ${{ inputs.coverage_python }}
run: |
set -euo pipefail
"$COVERAGE_PYTHON" -c "import importlib.metadata as m; import coverage; print('[coverage] coverage', m.version('coverage'))"
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 "coverage_aggregated=false" >> "$GITHUB_OUTPUT"
echo "WARNING: No raw coverage files found for aggregation"
if [ "$COVERAGE_REQUIRED" = "true" ]; then
exit 1
fi
exit 0
fi
"$COVERAGE_PYTHON" -m coverage combine coverage-raw
coverage_name="coverage-${{ inputs.platform }}-${{ inputs.device }}-pytorch-unittest.json"
coverage_command=(
"$COVERAGE_PYTHON" -m coverage json
-o "$coverage_name"
-i
)
if [ -n "$COVERAGE_INCLUDE" ]; then
coverage_command+=(--include="$COVERAGE_INCLUDE")
fi
if [ -n "$COVERAGE_OMIT" ]; then
coverage_command+=(--omit="$COVERAGE_OMIT")
fi
"${coverage_command[@]}"
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'