66 platform :
77 required : true
88 type : string
9- description : Platform name (e.g., cuda, default)
109 device :
1110 required : true
1211 type : string
13- description : Device type (e.g., a100, a800, h100, generic)
1412 image :
1513 required : true
1614 type : string
2725 required : false
2826 type : string
2927 default : ' '
30- description : JSON array of test files to ignore
28+ # New input for hardware-specific initialization (e.g., conda activate)
29+ setup_commands :
30+ required : false
31+ type : string
32+ default : ' '
3133
3234jobs :
33- # 1. Change Detection: Monitors both new unit tests and legacy QA paths
35+ # 1. Change Detection
3436 detect_changes :
3537 runs-on : ubuntu-latest
3638 outputs :
@@ -46,18 +48,15 @@ jobs:
4648 id : filter
4749 run : |
4850 set -euo pipefail
49- # Identify base reference for diff
5051 BASE_REF="${{ github.event_name == 'pull_request' && format('origin/{0}', github.base_ref) || 'HEAD~1' }}"
5152 [ "${{ github.event_name }}" == "pull_request" ] && git fetch origin ${{ github.base_ref }} --depth=1
5253
5354 CHANGED_FILES=$(git diff --name-only $BASE_REF...HEAD 2>/dev/null || git diff --name-only $BASE_REF HEAD)
5455
55- # Logic for core framework and new pytest suite
5656 echo "core=$(echo "$CHANGED_FILES" | grep -qE "^tests/unit_tests/|^megatron/core/" && echo "true" || echo "false")" >> $GITHUB_OUTPUT
57- # Logic for legacy QA L0 scripts and PyTorch specific paths
5857 echo "qa_l0=$(echo "$CHANGED_FILES" | grep -qE "^qa/L0_|^transformer_engine/|^tests/pytorch/" && echo "true" || echo "false")" >> $GITHUB_OUTPUT
5958
60- # 2. Unified Test Execution: Supports both pytest and legacy shell scripts
59+ # 2. Unified Test Execution
6160 unit_test :
6261 needs : detect_changes
6362 defaults :
@@ -68,15 +67,12 @@ jobs:
6867 fail-fast : false
6968 matrix :
7069 test_group :
71- # Modern Pytest architecture
7270 - name : core
7371 path : " tests/unit_tests/test_*.py"
7472 test_type : " pytest"
7573 - name : distributed
7674 path : " tests/unit_tests/distributed/"
7775 test_type : " pytest"
78-
79- # Integrated legacy QA L0 groups
8076 - name : pytorch_unittest
8177 path : " qa/L0_pytorch_unittest/test.sh"
8278 test_type : " sh"
@@ -93,20 +89,16 @@ jobs:
9389 name : unit-${{ inputs.device }}-${{ matrix.test_group.name }}
9490 container :
9591 image : ${{ inputs.image }}
96- ports :
97- - 80
9892 volumes : ${{ fromJson(inputs.container_volumes) }}
99- # Crucial: --pull never prevents internet access; container_options should include --privileged
10093 options : --pull never ${{ inputs.container_options }}
10194
10295 steps :
10396 - name : Check if tests should run
10497 id : should_run
10598 run : |
10699 GROUP='${{ matrix.test_group.name }}'
107- FULL_CI='${{ contains(github.event.pull_request.labels.*.name, 'full ci') }}'
108-
109- if [ "$FULL_CI" == "true" ]; then
100+ # Force run if 'full ci' label exists
101+ if [ "${{ contains(github.event.pull_request.labels.*.name, 'full ci') }}" == "true" ]; then
110102 echo "should_run=true" >> $GITHUB_OUTPUT; exit 0
111103 fi
112104
@@ -115,51 +107,51 @@ jobs:
115107 else
116108 CHANGED='${{ needs.detect_changes.outputs.core }}'
117109 fi
110+ # For debugging, you can force this to true
118111 echo "should_run=$CHANGED" >> $GITHUB_OUTPUT
119112
120113 - name : Checkout source code
121- # if: steps.should_run.outputs.should_run == 'true'
114+ if : steps.should_run.outputs.should_run == 'true'
122115 uses : actions/checkout@v4
123116 with :
124117 set-safe-directory : true
125118
126- - name : Metax Environment Setup
127- # if: steps.should_run.outputs.should_run == 'true'
119+ - name : Environment Setup
120+ if : steps.should_run.outputs.should_run == 'true'
128121 run : |
129122 set -euo pipefail
130- # Dynamically set MACA library path if drivers are mounted
131- if [ -d "/usr/local/maca/lib" ]; then
132- echo "Setting MACA library path..."
133- echo "LD_LIBRARY_PATH=/usr/local/maca/lib:${LD_LIBRARY_PATH:-}" >> $GITHUB_ENV
134- fi
123+ # 1. Execute hardware-specific setup (e.g. conda activate, export paths)
124+
125+ #! setup_commands from all_tests_xxx.yml(like all_tests_metax.yml)
126+ ${{ inputs.setup_commands }}
135127
136- # Install dependencies required by legacy QA scripts
137- pip install --no-cache-dir transformers expecttest boto3==1.42.1
138- # Install current repo in editable mode without re-building
139- pip install -e . --no-deps
128+ # 2. Universal dependency sync using the activated python environment
129+ python3 -m pip install --no-cache-dir transformers expecttest boto3==1.42.1
130+ python3 -m pip install -e . --no-deps
140131 timeout-minutes : 20
141132
142133 - name : Execute Tests
143- # if: steps.should_run.outputs.should_run == 'true'
134+ if : steps.should_run.outputs.should_run == 'true'
144135 working-directory : ${{ github.workspace }}
145136 run : |
146137 set -euo pipefail
138+ # 1. Re-execute setup commands for the new shell session
139+ ${{ inputs.setup_commands }}
147140
148- # Base environment variables (required for legacy scripts)
141+ # 2. Export Common TE Variables
149142 export TE_PATH=$GITHUB_WORKSPACE
150143 export PYTHONPATH=$GITHUB_WORKSPACE:${PYTHONPATH:-}
151144 export RUN_LOG=/tmp/te_logs && mkdir -p $RUN_LOG
152145
153- # Detect local GPU count dynamically (e.g., 2 for C500)
146+ # 3. Dynamic Hardware Detection
154147 NUM_GPUS=$(python3 -c "import torch; print(torch.cuda.device_count() if torch.cuda.is_available() else 0)")
155- echo "=== Detected $NUM_GPUS GPUs, starting execution ==="
148+ echo "=== Platform: ${{ inputs.platform }} | Device: ${{ inputs.device }} | GPUs: $NUM_GPUS ==="
156149
157150 if [ "${{ matrix.test_group.test_type }}" == "sh" ]; then
158151 echo "::group::Executing Legacy Shell Script"
159- # Dynamically detect TE installation path to avoid "SO not found" errors
152+ # Detect TE path for legacy scripts to find C++/MACA extensions
160153 export TE_LIB_PATH=$(python3 -c "import transformer_engine; import os; print(os.path.dirname(transformer_engine.__file__))")
161154
162- # Special env for Lint group
163155 if [[ "${{ matrix.test_group.name }}" == *"lint"* ]]; then
164156 export CPP_ONLY=0
165157 export PYTHON_ONLY=0
@@ -168,11 +160,10 @@ jobs:
168160 echo "::endgroup::"
169161 else
170162 echo "::group::Executing Modern Pytest"
171- # Build deselect options from ignored_tests input
163+ # Extract ignored tests from configuration
172164 IGNORED_TESTS='${{ inputs.ignored_tests }}'
173165 IGNORE_OPTS=$(echo "$IGNORED_TESTS" | python3 -c "import sys, json; t = json.load(sys.stdin); print(' '.join(['--deselect=' + i for i in t])) if t else print('')")
174166
175- # Run distributed tests with torchrun
176167 torchrun --nproc_per_node=$NUM_GPUS -m pytest -v ${{ matrix.test_group.path }} $IGNORE_OPTS -p no:randomly
177168 echo "::endgroup::"
178169 fi
0 commit comments