|
| 1 | +# Copyright 2025 Google LLC |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +--- |
| 16 | +- name: Run prerequisite NCCL scripts |
| 17 | + shell: | |
| 18 | + set -x -e |
| 19 | + cd {{ ansible_user_dir }} |
| 20 | + rm -rf cluster-toolkit |
| 21 | + git clone https://github.com/GoogleCloudPlatform/cluster-toolkit.git |
| 22 | + cd cluster-toolkit/{{ nccl_test_path }} |
| 23 | + bash import_pytorch_container.sh |
| 24 | + sbatch --wait build-nccl-tests.sh |
| 25 | + args: |
| 26 | + chdir: "{{ ansible_user_dir }}" |
| 27 | + executable: /bin/bash |
| 28 | + register: build_result |
| 29 | + |
| 30 | +- name: Wait for aperture devices on compute nodes |
| 31 | + shell: | |
| 32 | + srun -N 2 --partition=a3mega --pty bash -c ' |
| 33 | + max_attempts=60 # Wait for up to 5 minute |
| 34 | + attempt=0 |
| 35 | + while [ -z "$(ls -A /dev/aperture_devices 2>/dev/null)" ]; do |
| 36 | + echo "Node $(hostname): Waiting for aperture devices... (Attempt $(($attempt + 1)))" |
| 37 | + if [ $attempt -ge $max_attempts ]; then |
| 38 | + echo "ERROR: Node $(hostname): Aperture devices not found after $max_attempts attempts." >&2 |
| 39 | + exit 1 |
| 40 | + fi |
| 41 | + attempt=$(($attempt + 1)) |
| 42 | + sleep 5 |
| 43 | + done |
| 44 | + echo "Node $(hostname): Aperture devices are ready." |
| 45 | + ' |
| 46 | + args: |
| 47 | + chdir: "{{ ansible_user_dir }}/cluster-toolkit/{{ nccl_test_path }}" |
| 48 | + executable: /bin/bash |
| 49 | + |
| 50 | +- name: Submit NCCL test job and get job ID |
| 51 | + shell: "sbatch run-nccl-tests.sh | awk '{print $4}'" |
| 52 | + args: |
| 53 | + chdir: "{{ ansible_user_dir }}/cluster-toolkit/{{ nccl_test_path }}" |
| 54 | + executable: /bin/bash |
| 55 | + register: sbatch_output |
| 56 | + changed_when: false |
| 57 | + |
| 58 | +- name: Set job_id fact |
| 59 | + set_fact: |
| 60 | + job_id: "{{ sbatch_output.stdout | trim }}" |
| 61 | + |
| 62 | +- name: Wait for NCCL test job to complete |
| 63 | + command: "sacct -j {{ job_id }} -n -o State" |
| 64 | + register: job_status |
| 65 | + until: "'COMPLETED' in job_status.stdout or 'FAILED' in job_status.stdout or 'TIMEOUT' in job_status.stdout" |
| 66 | + retries: 60 # wait for 30 minutes |
| 67 | + delay: 30 |
| 68 | + changed_when: false |
| 69 | + |
| 70 | +- name: Check final job status |
| 71 | + fail: |
| 72 | + msg: "NCCL test job {{ job_id }} failed with status {{ job_status.stdout }}. Check slurm-{{ job_id }}.out on the login node." |
| 73 | + when: "'COMPLETED' not in job_status.stdout" |
| 74 | + |
| 75 | +- name: Verify NCCL test output |
| 76 | + shell: "cat slurm-{{ job_id }}.out | grep '# Avg bus bandwidth'" |
| 77 | + args: |
| 78 | + chdir: "{{ ansible_user_dir }}/cluster-toolkit/{{ nccl_test_path }}" |
| 79 | + executable: /bin/bash |
| 80 | + register: nccl_output |
| 81 | + changed_when: false |
| 82 | + |
| 83 | +- name: Display NCCL Test Result |
| 84 | + debug: |
| 85 | + msg: "NCCL Test Result: {{ nccl_output.stdout }}" |
| 86 | + when: nccl_output.stdout is defined and nccl_output.stdout != "" |
| 87 | + |
| 88 | +- name: Extract average bus bandwidth |
| 89 | + shell: "echo '{{ nccl_output.stdout }}' | awk -F':' '{print $NF}'" |
| 90 | + register: avg_bus_bandwidth |
| 91 | + changed_when: false |
| 92 | + when: nccl_output.stdout is defined and nccl_output.stdout != "" |
| 93 | + |
| 94 | +- name: Ensure average bus bandwidth is sufficient |
| 95 | + fail: |
| 96 | + msg: "Average bus bandwidth is {{ avg_bus_bandwidth.stdout | trim }} GB/s, which is below the threshold of 30 GB/s." |
| 97 | + when: (avg_bus_bandwidth.stdout | default('0') | float) < 30 |
0 commit comments