|
| 1 | +name: Set Matrix |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + outputs: |
| 6 | + matrix: |
| 7 | + description: dynamically set matrix |
| 8 | + value: ${{ jobs.set.outputs.matrix }} |
| 9 | + |
| 10 | +jobs: |
| 11 | + set: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + outputs: |
| 14 | + matrix: ${{ steps.set.outputs.matrix }} |
| 15 | + env: |
| 16 | + # Event flags evaluated by github actions before the step runs: |
| 17 | + IS_MAIN_PUSH: ${{ github.event_name == 'push' && github.ref == 'refs/heads/main' }} |
| 18 | + IS_SCHEDULE: ${{ github.event_name == 'schedule' }} |
| 19 | + IS_8GPU_TAG: ${{ startsWith(github.ref, 'refs/tags/ciflow/8gpu/') }} |
| 20 | + TRIGGERED_8GPU_LABEL: ${{ github.event_name == 'pull_request' && github.event.action == 'labeled' }} |
| 21 | + |
| 22 | + steps: |
| 23 | + - id: set |
| 24 | + run: | |
| 25 | + # Define ROCm matrix |
| 26 | + ROCM_MATRIX='{ |
| 27 | + "name": "rocm", |
| 28 | + "runner": "linux.rocm.gpu.gfx942.8", |
| 29 | + "gpu-arch-type": "rocm", |
| 30 | + "gpu-arch-version": "7.0", |
| 31 | + "docker-image": "torchtitan-rocm-ubuntu-22.04-clang12", |
| 32 | + "index-url": "https://download.pytorch.org/whl/nightly/rocm7.0" |
| 33 | + }' |
| 34 | +
|
| 35 | + # Define CUDA matrix |
| 36 | + CUDA_MATRIX='{ |
| 37 | + "name": "cuda", |
| 38 | + "runner": "linux.g5.48xlarge.nvidia.gpu", |
| 39 | + "gpu-arch-type": "cuda", |
| 40 | + "gpu-arch-version": "12.6", |
| 41 | + "docker-image": "torchtitan-ubuntu-20.04-clang12", |
| 42 | + "index-url": "https://download.pytorch.org/whl/nightly/cu126" |
| 43 | + }' |
| 44 | +
|
| 45 | + # Use default value as 'false' for unset environment variables |
| 46 | + IS_MAIN_PUSH="${IS_MAIN_PUSH:-false}" |
| 47 | + IS_SCHEDULE="${IS_SCHEDULE:-false}" |
| 48 | + IS_8GPU_TAG="${IS_8GPU_TAG:-false}" |
| 49 | + TRIGGERED_8GPU_LABEL="${TRIGGERED_8GPU_LABEL:-false}" |
| 50 | +
|
| 51 | + # Decide which matrix entries to include based on event type |
| 52 | + # Runs ROCm only for push tag OR when PR label gets triggered |
| 53 | + if [[ "$IS_8GPU_TAG" == "true" || "$TRIGGERED_8GPU_LABEL" == "true" ]]; then |
| 54 | + cat > matrix.json <<JSON |
| 55 | + {"include": [$ROCM_MATRIX]} |
| 56 | + JSON |
| 57 | +
|
| 58 | + # Runs CUDA and ROCm for normal PR (if PR label is present) OR for push to main, cron schedule |
| 59 | + elif [[ ("$IS_MAIN_PUSH" == "true" || "$IS_SCHEDULE" == "true") ]]; then |
| 60 | + cat > matrix.json <<JSON |
| 61 | + {"include": [$CUDA_MATRIX,$ROCM_MATRIX]} |
| 62 | + JSON |
| 63 | +
|
| 64 | + # Runs CUDA only as default (includes normal PR, if PR label is NOT present) |
| 65 | + else |
| 66 | + cat > matrix.json <<JSON |
| 67 | + {"include": [$CUDA_MATRIX]} |
| 68 | + JSON |
| 69 | + fi |
| 70 | +
|
| 71 | + # Export matrix to job outputs |
| 72 | + { |
| 73 | + echo 'matrix<<EOF' |
| 74 | + cat matrix.json |
| 75 | + echo 'EOF' |
| 76 | + } >> $GITHUB_OUTPUT |
0 commit comments