run_local_servers.sh 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  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; 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.11.0+cu113 torchvision==0.12.0+cu113 -f https://download.pytorch.org/whl/torch_stable.html
  35. pip install -i https://pypi.org/simple accelerate==0.10.0 huggingface-hub==0.7.0 hivemind==1.1.0
  36. pip install -i https://pypi.org/simple bitsandbytes-cuda113==0.26.0
  37. pip install -i https://pypi.org/simple https://github.com/huggingface/transformers/archive/6589e510fa4e6c442059de2fab84752535de9b23.zip
  38. fi
  39. #######################
  40. # Create Initial peer #
  41. #######################
  42. hivemind-dht &> tmp.out &
  43. sleep 3
  44. INITIAL_PEER=$(python -c "with open('tmp.out') as f: print(f.readlines()[1].split()[-1])" )
  45. echo "Initial peer: ${INITIAL_PEER}"
  46. ##############################
  47. # Initialize the config file #
  48. ##############################
  49. typeset -A cfg
  50. cfg=( # set default values in config array
  51. [device]="cpu"
  52. [block_ids]="1:2"
  53. [id_path]="server.id"
  54. [maddr]="/ip4/127.0.0.1/tcp/30000"
  55. )
  56. ###############
  57. # Run servers #
  58. ###############
  59. for SERVER_ID in $(seq 0 $(( $NUM_SERVERS - 1 )) )
  60. do
  61. ###############
  62. # Read config #
  63. ###############
  64. while read line
  65. do
  66. if echo $line | grep -F = &>/dev/null
  67. then
  68. varname=$(echo "$line" | cut -d '=' -f 1)
  69. cfg[$varname]=$(echo "$line" | cut -d '=' -f 2-)
  70. fi
  71. done < ${CONFIG_PATH}/server_${SERVER_ID}.cfg
  72. echo "=== Server #${SERVER_ID} ==="
  73. echo "Server ID: ${id_path}"
  74. echo "Device: ${cfg[device]}"
  75. echo "Bloom block ids: ${cfg[block_ids]}"
  76. echo "Host maddr: ${cfg[maddr]}"
  77. echo ""
  78. ##############
  79. # Run server #
  80. ##############
  81. tmux new-session -d -s "Server_${SERVER_ID}" bash cli/deploy_server.sh -i ${INITIAL_PEER} -d ${cfg[device]} -p ${cfg[id_path]} -b ${cfg[block_ids]} -a ${cfg[maddr]}
  82. done
  83. #####################
  84. # Kill initial peer #
  85. #####################
  86. sleep 10
  87. pkill -f hivemind-dht # TODO: kill only particular pids of hivemind-dht
  88. rm tmp.out