run-tests.yaml 5.3 KB

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