bench_job.yml 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. # This is the reusable workflow file
  2. name: Distributed Job Runner
  3. on:
  4. workflow_call:
  5. inputs:
  6. config:
  7. required: true
  8. type: string
  9. model:
  10. required: true
  11. type: string
  12. calling_job_name: # New input parameter
  13. required: true
  14. type: string
  15. jobs:
  16. generate-matrix:
  17. runs-on: ubuntu-latest
  18. outputs:
  19. matrix: ${{ steps.set-matrix.outputs.matrix }}
  20. steps:
  21. - id: set-matrix
  22. env:
  23. CONFIG: ${{ inputs.config }}
  24. run: |
  25. MATRIX=$(echo $CONFIG | jq -c '{cpu: [to_entries | .[] | .key as $k | range(.value) | $k]}')
  26. echo "matrix=$MATRIX" >> $GITHUB_OUTPUT
  27. run-distributed-job:
  28. needs: generate-matrix
  29. strategy:
  30. matrix: ${{fromJson(needs.generate-matrix.outputs.matrix)}}
  31. runs-on: ['self-hosted', 'macOS', '${{ matrix.cpu }}']
  32. env:
  33. HARDWARE_CONFIG: ${{ inputs.config }}
  34. model: ${{ inputs.model }}
  35. steps:
  36. - uses: actions/checkout@v4
  37. - name: Install dependencies
  38. run: |
  39. # First, find where python3.12 is installed
  40. which python3.12 || echo "python3.12 not in PATH"
  41. # Add common Python installation locations to PATH
  42. export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
  43. # Now try to create the venv with explicit python3.12
  44. python3.12 -m venv .venv || {
  45. echo "Failed to find python3.12. Checking installation locations:"
  46. ls -l /usr/local/bin/python* /opt/homebrew/bin/python* 2>/dev/null || true
  47. exit 1
  48. }
  49. source .venv/bin/activate
  50. pip install --upgrade pip
  51. pip install -e .
  52. pip install boto3==1.35.76
  53. - name: Configure system
  54. run: |
  55. # Check initial CPU state
  56. echo "Initial CPU state:"
  57. sysctl machdep.cpu || true
  58. sysctl hw.cpufamily || true
  59. sysctl hw.cputype || true
  60. sysctl hw.logicalcpu || true
  61. sysctl hw.physicalcpu || true
  62. # Apply MLX optimizations
  63. ./configure_mlx.sh
  64. # Disable CPU throttling (correct syntax for M-series Macs)
  65. sudo pmset -a powermode 0 2>/dev/null || echo "Failed to set power mode"
  66. sudo pmset -a gpuswitch 2 2>/dev/null || echo "Failed to set GPU mode"
  67. # Check final state
  68. echo "Final CPU state:"
  69. sysctl machdep.cpu || true
  70. pmset -g thermals || true
  71. pmset -g || true
  72. sysctl iogpu
  73. - name: Run exo
  74. env:
  75. aws_access_key_id: ${{ secrets.S3_EXO_BENCHMARKS_AWS_ACCESS_KEY_ID }}
  76. aws_secret_key: ${{ secrets.S3_EXO_BENCHMARKS_AWS_SECRET_ACCESS_KEY }}
  77. run: |
  78. # Debug information
  79. echo "Current commit SHA: $GITHUB_SHA"
  80. git rev-parse HEAD
  81. git status
  82. # List existing exo processes
  83. echo "Existing exo processes:"
  84. ps aux | grep exo || true
  85. CALLING_JOB="${{ inputs.calling_job_name }}"
  86. UNIQUE_JOB_ID="${CALLING_JOB}_${model}_${GITHUB_RUN_ID}"
  87. ALL_NODE_IDS=$(for i in $(seq ${{ strategy.job-total }} -1 0); do echo -n "${UNIQUE_JOB_ID}_${i},"; done | sed 's/,$//')
  88. MY_NODE_ID="${UNIQUE_JOB_ID}_${{ strategy.job-index }}"
  89. echo "Starting exo process with:"
  90. echo "MY_NODE_ID: ${MY_NODE_ID}"
  91. echo "ALL_NODE_IDS: ${ALL_NODE_IDS}"
  92. echo "Total expected nodes: ${{ strategy.job-total }}"
  93. source .venv/bin/activate
  94. export PATH="/usr/local/bin:/opt/homebrew/bin:$PATH"
  95. # Check installed exo version
  96. pip show exo
  97. which .venv/bin/exo
  98. echo "Starting exo daemon..."
  99. DEBUG=6 DEBUG_DISCOVERY=6 .venv/bin/exo --node-id="${MY_NODE_ID}" --node-id-filter="${ALL_NODE_IDS}" --interface-type-filter="Ethernet" --chatgpt-api-port 52415 > output1.log 2>&1 &
  100. PID1=$!
  101. echo "Exo process started with PID: $PID1"
  102. tail -f output1.log &
  103. TAIL1=$!
  104. trap 'kill $TAIL1' EXIT
  105. trap 'kill $PID1' EXIT
  106. echo "Waiting for all nodes to connect..."
  107. for i in {1..100}; do
  108. echo "Attempt $i: Checking node count..."
  109. nodes=$(curl -s http://localhost:52415/topology | jq ".nodes | length")
  110. echo "Current node count: $nodes"
  111. if [ "$nodes" -eq "${{ strategy.job-total }}" ]; then
  112. echo "All nodes connected successfully!"
  113. break
  114. fi
  115. sleep 5
  116. done
  117. if ! kill -0 $PID1 2>/dev/null; then
  118. echo "ERROR: Instance (PID $PID1) died unexpectedly. Full log output:"
  119. cat output1.log
  120. exit 1
  121. fi
  122. if [ "${{ strategy.job-index }}" -eq "0" ]; then
  123. sleep 10
  124. echo "This is the primary node (index 0). Running benchmark..."
  125. GITHUB_JOB=$CALLING_JOB python .github/bench.py
  126. else
  127. echo "This is a secondary node (index ${{ strategy.job-index }}). Waiting for completion..."
  128. sleep 10
  129. while true; do
  130. echo "Checking if primary node is still running..."
  131. nodes=$(curl -s http://localhost:52415/topology | jq ".nodes | length")
  132. echo "Current node count: $nodes"
  133. if [ "$nodes" -lt "${{ strategy.job-total }}" ]; then
  134. echo "Primary node completed, exiting..."
  135. break
  136. fi
  137. sleep 5
  138. done
  139. fi