run_local_servers.sh 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. # !/usr/bin/env bash
  2. #################
  3. # Parse options #
  4. #################
  5. instructions() {
  6. echo "Usage: $0 [-n] [-c]" >&2
  7. echo " -n: number of servers to run" >&2
  8. echo " -c: path to the server configs" >&2
  9. exit 1
  10. }
  11. if [ $# != 4 ]; then
  12. instructions
  13. fi
  14. while getopts ":n:c:t:" option; do
  15. case $option in
  16. n) NUM_SERVERS=${OPTARG}
  17. ;;
  18. c) CONFIG_PATH=${OPTARG}
  19. ;;
  20. \?) instructions
  21. ;;
  22. esac
  23. done
  24. ###########################
  25. # Install or activate env #
  26. ###########################
  27. source ~/miniconda3/etc/profile.d/conda.sh
  28. if conda env list | grep ".*bloom-demo.*" >/dev/null 2>/dev/null; then
  29. conda activate bloom-demo
  30. else
  31. conda create -y --name bloom-demo python=3.8.12 pip
  32. conda activate bloom-demo
  33. conda install -y -c conda-forge cudatoolkit-dev==11.3.1 cudatoolkit==11.3.1 cudnn==8.2.1.32
  34. pip install -i https://pypi.org/simple torch==1.12.0+cu113 -f https://download.pytorch.org/whl/torch_stable.html
  35. pip install -i https://pypi.org/simple -r requirements.txt
  36. fi
  37. #######################
  38. # Create Initial peer #
  39. #######################
  40. hivemind-dht &> tmp.out &
  41. sleep 20
  42. INITIAL_PEER=$(python -c "with open('tmp.out') as f: print(f.readlines()[1].split()[-1])" )
  43. echo "Initial peer: ${INITIAL_PEER}"
  44. ##############################
  45. # Initialize the config file #
  46. ##############################
  47. typeset -A cfg
  48. cfg=( # set default values in config array
  49. [device]="cpu"
  50. [block_ids]="1:2"
  51. [id_path]="server.id"
  52. [maddr]="/ip4/127.0.0.1/tcp/30000"
  53. )
  54. ###############
  55. # Run servers #
  56. ###############
  57. for SERVER_ID in $(seq 0 $(( $NUM_SERVERS - 1 )) )
  58. do
  59. ###############
  60. # Read config #
  61. ###############
  62. while read line
  63. do
  64. if echo $line | grep -F = &>/dev/null
  65. then
  66. varname=$(echo "$line" | cut -d '=' -f 1)
  67. cfg[$varname]=$(echo "$line" | cut -d '=' -f 2-)
  68. fi
  69. done < ${CONFIG_PATH}/server_${SERVER_ID}.cfg
  70. echo "=== Server #${SERVER_ID} ==="
  71. echo "Server ID: ${cfg[id_path]}"
  72. echo "Device: ${cfg[device]}"
  73. echo "Bloom block ids: ${cfg[block_ids]}"
  74. echo "Host maddr: ${cfg[maddr]}"
  75. echo ""
  76. ##############
  77. # Run server #
  78. ##############
  79. tmux new-session -d -s "Server_${SERVER_ID}" bash cli/deploy_server.sh -m "bigscience/test-bloomd" -i ${INITIAL_PEER} -d ${cfg[device]} -p ${cfg[id_path]} -b ${cfg[block_ids]} -a ${cfg[maddr]}
  80. done
  81. #####################
  82. # Kill initial peer #
  83. #####################
  84. sleep 180
  85. pkill -f hivemind-dht # TODO: kill only particular pids of hivemind-dht
  86. rm tmp.out