|
| 1 | +name: Demo – comprehensive GPU workload with sequential jobs |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + sleep: |
| 6 | + description: "Sleep for this many seconds at the end of each job (optional, for SSH debugging)" |
| 7 | + required: false |
| 8 | + type: number |
| 9 | + default: 0 |
| 10 | + ssh_pubkey: |
| 11 | + description: "Add this SSH public key to instance's `~/.ssh/authorized_keys` (optional, for debugging)" |
| 12 | + required: false |
| 13 | + type: string |
| 14 | + workflow_call: # Tested by `demos.yml` |
| 15 | + inputs: |
| 16 | + sleep: |
| 17 | + required: false |
| 18 | + type: number |
| 19 | + default: 0 |
| 20 | + ssh_pubkey: |
| 21 | + required: false |
| 22 | + type: string |
| 23 | + |
| 24 | +permissions: |
| 25 | + id-token: write # Required for AWS OIDC authentication |
| 26 | + contents: read # Required for actions/checkout |
| 27 | + |
| 28 | +jobs: |
| 29 | + ec2: |
| 30 | + uses: ./.github/workflows/runner.yml |
| 31 | + secrets: inherit |
| 32 | + with: |
| 33 | + ec2_instance_type: g4dn.xlarge |
| 34 | + ec2_image_id: ami-00096836009b16a22 # Deep Learning OSS Nvidia Driver AMI GPU PyTorch |
| 35 | + ssh_pubkey: ${{ inputs.ssh_pubkey }} |
| 36 | + |
| 37 | + # Job 1: Prepare environment and verify GPU |
| 38 | + prepare: |
| 39 | + needs: ec2 |
| 40 | + runs-on: ${{ needs.ec2.outputs.id }} |
| 41 | + outputs: |
| 42 | + gpu-uuid: ${{ steps.gpu-info.outputs.uuid }} |
| 43 | + gpu-name: ${{ steps.gpu-info.outputs.name }} |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + |
| 47 | + - name: Get GPU info |
| 48 | + id: gpu-info |
| 49 | + run: | |
| 50 | + echo "=== Preparing GPU environment ===" |
| 51 | + nvidia-smi |
| 52 | + uuid=$(nvidia-smi --query-gpu=gpu_uuid --format=csv,noheader) |
| 53 | + name=$(nvidia-smi --query-gpu=name --format=csv,noheader) |
| 54 | + echo "uuid=$uuid" >> $GITHUB_OUTPUT |
| 55 | + echo "name=$name" >> $GITHUB_OUTPUT |
| 56 | + echo "GPU UUID: $uuid" |
| 57 | + echo "GPU Name: $name" |
| 58 | +
|
| 59 | + - name: Setup PyTorch environment |
| 60 | + run: | |
| 61 | + echo "=== Setting up PyTorch environment ===" |
| 62 | + # The DLAMI already has PyTorch installed in a conda environment |
| 63 | + # Set up environment for GitHub Actions to use the conda env |
| 64 | + echo "/opt/conda/envs/pytorch/bin" >> $GITHUB_PATH |
| 65 | + echo "CONDA_DEFAULT_ENV=pytorch" >> $GITHUB_ENV |
| 66 | +
|
| 67 | + # Verify PyTorch is available |
| 68 | + /opt/conda/envs/pytorch/bin/python -c "import torch; print(f'PyTorch {torch.__version__} with CUDA {torch.version.cuda}')" |
| 69 | + echo "PyTorch environment ready" |
| 70 | +
|
| 71 | + - name: Sleep (${{ inputs.sleep }}s) |
| 72 | + if: ${{ inputs.sleep > 0 }} |
| 73 | + run: | |
| 74 | + echo "Sleeping for ${{ inputs.sleep }} seconds..." |
| 75 | + echo "Instance IP available in GitHub Actions log for SSH" |
| 76 | + sleep ${{ inputs.sleep }} |
| 77 | +
|
| 78 | + # Job 2: Training simulation |
| 79 | + train: |
| 80 | + needs: [ec2, prepare] |
| 81 | + runs-on: ${{ needs.ec2.outputs.id }} |
| 82 | + steps: |
| 83 | + - uses: actions/checkout@v4 |
| 84 | + |
| 85 | + - name: Verify same GPU |
| 86 | + run: | |
| 87 | + echo "=== Training on GPU ===" |
| 88 | + current_uuid=$(nvidia-smi --query-gpu=gpu_uuid --format=csv,noheader) |
| 89 | + if [[ "$current_uuid" == "${{ needs.prepare.outputs.gpu-uuid }}" ]]; then |
| 90 | + echo "✅ Confirmed: Using same GPU as preparation job" |
| 91 | + echo "GPU: ${{ needs.prepare.outputs.gpu-name }}" |
| 92 | + else |
| 93 | + echo "❌ ERROR: Different GPU!" |
| 94 | + exit 1 |
| 95 | + fi |
| 96 | +
|
| 97 | + - name: Run training benchmark |
| 98 | + run: | |
| 99 | + echo "=== Running GPU Training Benchmark ===" |
| 100 | + # Use the conda environment's Python which has PyTorch pre-installed |
| 101 | + /opt/conda/envs/pytorch/bin/python .github/test-scripts/gpu-benchmark.py |
| 102 | +
|
| 103 | + - name: Sleep (${{ inputs.sleep }}s) |
| 104 | + if: ${{ inputs.sleep > 0 }} |
| 105 | + run: sleep ${{ inputs.sleep }} |
| 106 | + |
| 107 | + # Job 3: Evaluation/testing |
| 108 | + evaluate: |
| 109 | + needs: [ec2, train] |
| 110 | + runs-on: ${{ needs.ec2.outputs.id }} |
| 111 | + steps: |
| 112 | + - name: System diagnostics |
| 113 | + run: | |
| 114 | + echo "=== Final Evaluation ===" |
| 115 | + echo "System Info:" |
| 116 | + uname -a |
| 117 | + lscpu | grep "Model name" || true |
| 118 | + free -h |
| 119 | +
|
| 120 | + echo -e "\nGPU Status:" |
| 121 | + nvidia-smi --query-gpu=name,memory.total,driver_version,utilization.gpu,temperature.gpu --format=csv |
| 122 | +
|
| 123 | + echo -e "\nDisk Usage:" |
| 124 | + df -h / |
| 125 | +
|
| 126 | + echo -e "\nInstance Metadata:" |
| 127 | + curl -s -H "X-aws-ec2-metadata-token: $(curl -X PUT -H 'X-aws-ec2-metadata-token-ttl-seconds: 300' http://169.254.169.254/latest/api/token 2>/dev/null)" http://169.254.169.254/latest/meta-data/instance-type || echo "Metadata unavailable" |
| 128 | +
|
| 129 | + - name: Verify multi-job reuse |
| 130 | + run: | |
| 131 | + echo "=== Verifying EC2 Instance Reuse ===" |
| 132 | + echo "This job successfully ran on the same EC2 instance as the previous jobs" |
| 133 | + echo "The instance will terminate automatically after idle timeout" |
| 134 | +
|
| 135 | + - name: Sleep (${{ inputs.sleep }}s) |
| 136 | + if: ${{ inputs.sleep > 0 }} |
| 137 | + run: sleep ${{ inputs.sleep }} |
0 commit comments