run_local_servers.sh 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  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. pip install -i https://test.pypi.org/simple/ bitsandbytes-cuda113
  37. fi
  38. #######################
  39. # Create Initial peer #
  40. #######################
  41. hivemind-dht &> tmp.out &
  42. sleep 5
  43. INITIAL_PEER=$(python -c "with open('tmp.out') as f: print(f.readlines()[1].split()[-1])" )
  44. echo "Initial peer: ${INITIAL_PEER}"
  45. ##############################
  46. # Initialize the config file #
  47. ##############################
  48. typeset -A cfg
  49. cfg=( # set default values in config array
  50. [device]="cpu"
  51. [block_ids]="1:2"
  52. [id_path]="server.id"
  53. [maddr]="/ip4/127.0.0.1/tcp/30000"
  54. )
  55. ###############
  56. # Run servers #
  57. ###############
  58. for SERVER_ID in $(seq 0 $(( $NUM_SERVERS - 1 )) )
  59. do
  60. ###############
  61. # Read config #
  62. ###############
  63. while read line
  64. do
  65. if echo $line | grep -F = &>/dev/null
  66. then
  67. varname=$(echo "$line" | cut -d '=' -f 1)
  68. cfg[$varname]=$(echo "$line" | cut -d '=' -f 2-)
  69. fi
  70. done < ${CONFIG_PATH}/server_${SERVER_ID}.cfg
  71. echo "=== Server #${SERVER_ID} ==="
  72. echo "Server ID: ${cfg[id_path]}"
  73. echo "Device: ${cfg[device]}"
  74. echo "Bloom block ids: ${cfg[block_ids]}"
  75. echo "Host maddr: ${cfg[maddr]}"
  76. echo ""
  77. ##############
  78. # Run server #
  79. ##############
  80. 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]}
  81. done
  82. #####################
  83. # Kill initial peer #
  84. #####################
  85. sleep 10
  86. pkill -f hivemind-dht # TODO: kill only particular pids of hivemind-dht
  87. rm tmp.out