run-tests.yaml 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. name: Tests
  2. on:
  3. push:
  4. branches: [ main ]
  5. pull_request:
  6. jobs:
  7. run-tests:
  8. strategy:
  9. matrix:
  10. include:
  11. - { model: 'bigscience/bloom-560m', os: 'ubuntu', python-version: '3.8' }
  12. - { model: 'bigscience/bloom-560m', os: 'ubuntu', python-version: '3.11' }
  13. - { model: 'Maykeye/TinyLLama-v0', os: 'ubuntu', python-version: '3.8' }
  14. - { model: 'Maykeye/TinyLLama-v0', os: 'ubuntu', python-version: '3.11' }
  15. - { model: 'petals-team/falcon-rw-1b', os: 'ubuntu', python-version: '3.8' }
  16. - { model: 'petals-team/falcon-rw-1b', os: 'ubuntu', python-version: '3.11' }
  17. - { model: 'Maykeye/TinyLLama-v0', os: 'macos', python-version: '3.10' }
  18. - { model: 'Maykeye/TinyLLama-v0', os: 'macos', python-version: '3.11' }
  19. fail-fast: false
  20. runs-on: ${{ matrix.os }}-latest
  21. timeout-minutes: 20
  22. steps:
  23. - name: Increase swap space
  24. if: ${{ matrix.os == 'ubuntu' }}
  25. uses: pierotofy/set-swap-space@master
  26. with:
  27. swap-size-gb: 10
  28. - name: Checkout
  29. uses: actions/checkout@v3
  30. - name: Set up Python
  31. uses: actions/setup-python@v3
  32. with:
  33. python-version: ${{ matrix.python-version }}
  34. - name: Cache dependencies
  35. uses: actions/cache@v3
  36. with:
  37. path: ~/.cache/pip
  38. key: Key-v1-${{ matrix.python-version }}-${{ hashFiles('setup.cfg') }}
  39. - name: Install dependencies
  40. run: |
  41. python -m pip install --upgrade pip
  42. pip install .[dev]
  43. - name: Test
  44. run: |
  45. set -x # Print executed commands
  46. export MODEL_NAME="${{ matrix.model }}"
  47. export REF_NAME="${{ matrix.model }}"
  48. export ADAPTER_NAME="${{ matrix.model == 'bigscience/bloom-560m' && 'artek0chumak/bloom-560m-safe-peft' || '' }}"
  49. export TENSOR_PARALLEL_ARGS="${{ matrix.model == 'bigscience/bloom-560m' && '--tensor_parallel_devices cpu cpu' || '' }}"
  50. # [Step 1] Set up a tiny test swarm (see https://github.com/bigscience-workshop/petals/wiki/Launch-your-own-swarm)
  51. python -m petals.cli.run_dht \
  52. --identity_path tests/bootstrap.id --host_maddrs /ip4/127.0.0.1/tcp/31337 &> bootstrap.log &
  53. BOOTSTRAP_PID=$!
  54. export INITIAL_PEERS=/ip4/127.0.0.1/tcp/31337/p2p/QmS9KwZptnVdB9FFV7uGgaTq4sEKBwcYeKZDfSpyKDUd1g
  55. # ^-- multiaddr in INITIAL_PEERS is determined by --identity_path and --host_maddrs
  56. until [ -s bootstrap.log ]; do sleep 5; done # wait for DHT init
  57. python -m petals.cli.run_server $MODEL_NAME --adapters $ADAPTER_NAME --torch_dtype float32 --num_blocks 5 \
  58. --mean_balance_check_period 10 \
  59. --initial_peers $INITIAL_PEERS --throughput 1 &> server1.log &
  60. SERVER1_PID=$!
  61. # ^-- rebalacing test: this server chooses blocks 0:5, then sees a gap in the swarm and moves there
  62. sleep 10 # wait for the 1st server to choose blocks
  63. python -m petals.cli.run_server $MODEL_NAME --adapters $ADAPTER_NAME --torch_dtype float32 --block_indices 0:5 \
  64. --identity_path tests/server2.id \
  65. --initial_peers $INITIAL_PEERS --throughput 1 &> server2.log &
  66. SERVER2_PID=$!
  67. python -m petals.cli.run_server $MODEL_NAME --adapters $ADAPTER_NAME --torch_dtype float32 --num_blocks 14 \
  68. --attn_cache_tokens 2048 --max_chunk_size_bytes 1024 \
  69. --initial_peers $INITIAL_PEERS --throughput auto &> server3.log &
  70. SERVER3_PID=$!
  71. # ^-- chunking test
  72. python -m petals.cli.run_server $MODEL_NAME $TENSOR_PARALLEL_ARGS --torch_dtype float32 --block_indices 0:2 \
  73. --initial_peers $INITIAL_PEERS --throughput auto &> server4.log &
  74. SERVER4_PID=$!
  75. # ^-- tensor parallelism test (not compatible with adapters yet)
  76. sleep 5 # wait for the log files to appear
  77. tail -n 100 -f bootstrap.log server*.log &
  78. LOGGER_PID=$!
  79. sleep 30 # wait for servers to eval throughput, download layers, and rebalance
  80. kill -0 $BOOTSTRAP_PID $SERVER1_PID $SERVER2_PID $SERVER3_PID $SERVER4_PID # ensure all peers survived init
  81. # [Step 2] Run PyTest
  82. # Share disk cache between Petals servers, clients, and HF Transformers
  83. export TRANSFORMERS_CACHE=~/.cache/petals
  84. # Necessary for @pytest.mark.forked to work properly on macOS, see https://github.com/kevlened/pytest-parallel/issues/93
  85. export no_proxy=*
  86. export OBJC_DISABLE_INITIALIZE_FORK_SAFETY=YES
  87. # Limit default ClientConfig.max_retries to see tracebacks instead of retrying indefinitely
  88. export PETALS_MAX_RETRIES=10
  89. pytest tests --durations=0 --durations-min=1.0 -v
  90. # [Step 3] Check if benchmarks work (their results here are meaningless since it's a tiny swarm of CPU servers)
  91. python benchmarks/benchmark_inference.py --model $MODEL_NAME --initial_peers $INITIAL_PEERS --torch_dtype float32 \
  92. --seq_len 3
  93. python benchmarks/benchmark_forward.py --model $MODEL_NAME --initial_peers $INITIAL_PEERS --torch_dtype float32 \
  94. --seq_len 3 --batch_size 3 --n_steps 1
  95. python benchmarks/benchmark_training.py --model $MODEL_NAME --initial_peers $INITIAL_PEERS --torch_dtype float32 \
  96. --seq_len 3 --batch_size 3 --pre_seq_len 1 --n_steps 1 --task cls
  97. python benchmarks/benchmark_training.py --model $MODEL_NAME --initial_peers $INITIAL_PEERS --torch_dtype float32 \
  98. --seq_len 3 --batch_size 3 --pre_seq_len 1 --n_steps 1 --task causal_lm
  99. # [Step 4] Clean up
  100. kill -s SIGINT $BOOTSTRAP_PID $SERVER1_PID $SERVER2_PID $SERVER3_PID $SERVER4_PID $LOGGER_PID
  101. echo "Done!"