forked from flagos-ai/TransformerEngine-FL
-
Notifications
You must be signed in to change notification settings - Fork 0
201 lines (180 loc) · 7.34 KB
/
Copy pathunit_tests_common.yml
File metadata and controls
201 lines (180 loc) · 7.34 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
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: 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 --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/*" 2>/dev/null \
|| echo "WARNING: No coverage data found"
fi
exit $exit_code
timeout-minutes: 60
- name: Upload Coverage Report
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
- name: Upload Coverage Report to FlagCICD
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 }}-${{ matrix.test_group.name }}.json'
fail_on_error: 'false'