dimamachine

Untitled

Jul 8th, 2025
433
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.44 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. set -euo pipefail
  4.  
  5. # General arguments
  6. ROOT=$PWD
  7.  
  8. # GenRL Swarm version to use
  9. GENRL_TAG="v0.1.1"
  10.  
  11. export IDENTITY_PATH
  12. export GENSYN_RESET_CONFIG
  13. export CONNECT_TO_TESTNET=true
  14. export ORG_ID
  15. export HF_HUB_DOWNLOAD_TIMEOUT=120 # 2 minutes
  16. export SWARM_CONTRACT="0xFaD7C5e93f28257429569B854151A1B8DCD404c2"
  17. export HUGGINGFACE_ACCESS_TOKEN="None"
  18. export WANDB_MODE=disabled
  19.  
  20. # Path to an RSA private key. If this path does not exist, a new key pair will be created.
  21. # Remove this file if you want a new PeerID.
  22. DEFAULT_IDENTITY_PATH="$ROOT"/swarm.pem
  23. IDENTITY_PATH=${IDENTITY_PATH:-$DEFAULT_IDENTITY_PATH}
  24.  
  25. DOCKER=${DOCKER:-""}
  26. GENSYN_RESET_CONFIG=${GENSYN_RESET_CONFIG:-""}
  27.  
  28. # Bit of a workaround for the non-root docker container.
  29. if [ -n "$DOCKER" ]; then
  30. volumes=(
  31. /home/gensyn/rl_swarm/modal-login/temp-data
  32. /home/gensyn/rl_swarm/keys
  33. /home/gensyn/rl_swarm/configs
  34. /home/gensyn/rl_swarm/logs
  35. )
  36.  
  37. for volume in ${volumes[@]}; do
  38. sudo chown -R 1001:1001 $volume
  39. done
  40. fi
  41.  
  42. # Will ignore any visible GPUs if set.
  43. CPU_ONLY=${CPU_ONLY:-""}
  44.  
  45. # Set if successfully parsed from modal-login/temp-data/userData.json.
  46. ORG_ID=${ORG_ID:-""}
  47.  
  48. GREEN_TEXT="\033[32m"
  49. BLUE_TEXT="\033[34m"
  50. RED_TEXT="\033[31m"
  51. RESET_TEXT="\033[0m"
  52.  
  53. echo_green() {
  54. echo -e "$GREEN_TEXT$1$RESET_TEXT"
  55. }
  56.  
  57. echo_blue() {
  58. echo -e "$BLUE_TEXT$1$RESET_TEXT"
  59. }
  60.  
  61. echo_red() {
  62. echo -e "$RED_TEXT$1$RESET_TEXT"
  63. }
  64.  
  65. ROOT_DIR="$(cd $(dirname ${BASH_SOURCE[0]}) && pwd)"
  66.  
  67. # Function to clean up the server process upon exit
  68. cleanup() {
  69. echo_green ">> Shutting down trainer..."
  70.  
  71. # Remove modal credentials if they exist
  72. #rm -r $ROOT_DIR/modal-login/temp-data/*.json 2> /dev/null || true
  73.  
  74. # Kill all processes belonging to this script's process group
  75. kill -- -$$ || true
  76.  
  77. exit 0
  78. }
  79.  
  80. errnotify() {
  81. echo_red ">> An error was detected while running rl-swarm. See $ROOT/logs for full logs."
  82. }
  83.  
  84. trap cleanup EXIT
  85. trap errnotify ERR
  86.  
  87. echo -e "\033[38;5;224m"
  88. cat << "EOF"
  89. ██████ ██ ███████ ██ ██ █████ ██████ ███ ███
  90. ██ ██ ██ ██ ██ ██ ██ ██ ██ ██ ████ ████
  91. ██████ ██ █████ ███████ ██ █ ██ ███████ ██████ ██ ████ ██
  92. ██ ██ ██ ██ ██ ███ ██ ██ ██ ██ ██ ██ ██ ██
  93. ██ ██ ███████ ███████ ███ ███ ██ ██ ██ ██ ██ ██
  94.  
  95. From Gensyn
  96.  
  97. EOF
  98.  
  99. # Create logs directory if it doesn't exist
  100. mkdir -p "$ROOT/logs"
  101.  
  102. if [ "$CONNECT_TO_TESTNET" = true ]; then
  103. # Run modal_login server.
  104. echo "Please login to create an Ethereum Server Wallet"
  105. cd modal-login
  106. # Check if the yarn command exists; if not, install Yarn.
  107.  
  108. # Node.js + NVM setup
  109. if ! command -v node > /dev/null 2>&1; then
  110. echo "Node.js not found. Installing NVM and latest Node.js..."
  111. export NVM_DIR="$HOME/.nvm"
  112. if [ ! -d "$NVM_DIR" ]; then
  113. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  114. fi
  115. [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
  116. [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
  117. nvm install node
  118. else
  119. echo "Node.js is already installed: $(node -v)"
  120. fi
  121.  
  122. if ! command -v yarn > /dev/null 2>&1; then
  123. # Detect Ubuntu (including WSL Ubuntu) and install Yarn accordingly
  124. if grep -qi "ubuntu" /etc/os-release 2> /dev/null || uname -r | grep -qi "microsoft"; then
  125. echo "Detected Ubuntu or WSL Ubuntu. Installing Yarn via apt..."
  126. curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | sudo apt-key add -
  127. echo "deb https://dl.yarnpkg.com/debian/ stable main" | sudo tee /etc/apt/sources.list.d/yarn.list
  128. sudo apt update && sudo apt install -y yarn
  129. else
  130. echo "Yarn not found. Installing Yarn globally with npm (no profile edits)…"
  131. # This lands in $NVM_DIR/versions/node/<ver>/bin which is already on PATH
  132. npm install -g --silent yarn
  133. fi
  134. fi
  135.  
  136. ENV_FILE="$ROOT"/modal-login/.env
  137. if [[ "$OSTYPE" == "darwin"* ]]; then
  138. # macOS version
  139. sed -i '' "3s/.*/SMART_CONTRACT_ADDRESS=$SWARM_CONTRACT/" "$ENV_FILE"
  140. else
  141. # Linux version
  142. sed -i "3s/.*/SMART_CONTRACT_ADDRESS=$SWARM_CONTRACT/" "$ENV_FILE"
  143. fi
  144.  
  145.  
  146. # Docker image already builds it, no need to again.
  147. if [ -z "$DOCKER" ]; then
  148. yarn install --immutable
  149. echo "Building server"
  150. yarn build > "$ROOT/logs/yarn.log" 2>&1
  151. fi
  152. yarn start >> "$ROOT/logs/yarn.log" 2>&1 & # Run in background and log output
  153.  
  154. SERVER_PID=$! # Store the process ID
  155. echo "Started server process: $SERVER_PID"
  156. sleep 5
  157.  
  158. # Try to open the URL in the default browser
  159. if [ -z "$DOCKER" ]; then
  160. if open http://localhost:3000 2> /dev/null; then
  161. echo_green ">> Successfully opened http://localhost:3000 in your default browser."
  162. else
  163. echo ">> Failed to open http://localhost:3000. Please open it manually."
  164. fi
  165. else
  166. echo_green ">> Please open http://localhost:3000 in your host browser."
  167. fi
  168.  
  169. cd ..
  170.  
  171. echo_green ">> Waiting for modal userData.json to be created..."
  172. while [ ! -f "modal-login/temp-data/userData.json" ]; do
  173. sleep 5 # Wait for 5 seconds before checking again
  174. done
  175. echo "Found userData.json. Proceeding..."
  176.  
  177. ORG_ID=$(awk 'BEGIN { FS = "\"" } !/^[ \t]*[{}]/ { print $(NF - 1); exit }' modal-login/temp-data/userData.json)
  178. echo "Your ORG_ID is set to: $ORG_ID"
  179.  
  180. # Wait until the API key is activated by the client
  181. echo "Waiting for API key to become activated..."
  182. while true; do
  183. STATUS=$(curl -s "http://localhost:3000/api/get-api-key-status?orgId=$ORG_ID")
  184. if [[ "$STATUS" == "activated" ]]; then
  185. echo "API key is activated! Proceeding..."
  186. break
  187. else
  188. echo "Waiting for API key to be activated..."
  189. sleep 5
  190. fi
  191. done
  192. fi
  193.  
  194. echo_green ">> Getting requirements..."
  195. pip install --upgrade pip
  196.  
  197. # echo_green ">> Installing GenRL..."
  198. pip install gensyn-genrl==0.1.4
  199. pip install reasoning-gym>=0.1.20 # for reasoning gym env
  200. pip install trl # for grpo config, will be deprecated soon
  201. pip install hivemind@git+https://github.com/learning-at-home/hivemind@4d5c41495be082490ea44cce4e9dd58f9926bb4e # We need the latest, 1.1.11 is broken
  202.  
  203.  
  204. if [ ! -d "$ROOT/configs" ]; then
  205. mkdir "$ROOT/configs"
  206. fi
  207. if [ -f "$ROOT/configs/rg-swarm.yaml" ]; then
  208. # Use cmp -s for a silent comparison. If different, backup and copy.
  209. if ! cmp -s "$ROOT/rgym_exp/config/rg-swarm.yaml" "$ROOT/configs/rg-swarm.yaml"; then
  210. if [ -z "$GENSYN_RESET_CONFIG" ]; then
  211. echo_green ">> Found differences in rg-swarm.yaml. If you would like to reset to the default, set GENSYN_RESET_CONFIG to a non-empty value."
  212. else
  213. echo_green ">> Found differences in rg-swarm.yaml. Backing up existing config."
  214. mv "$ROOT/configs/rg-swarm.yaml" "$ROOT/configs/rg-swarm.yaml.bak"
  215. cp "$ROOT/rgym_exp/config/rg-swarm.yaml" "$ROOT/configs/rg-swarm.yaml"
  216. fi
  217. fi
  218. else
  219. # If the config doesn't exist, just copy it.
  220. cp "$ROOT/rgym_exp/config/rg-swarm.yaml" "$ROOT/configs/rg-swarm.yaml"
  221. fi
  222.  
  223. if [ -n "$DOCKER" ]; then
  224. # Make it easier to edit the configs on Linux systems.
  225. sudo chmod -R 0777 /home/gensyn/rl_swarm/configs
  226. fi
  227.  
  228. echo_green ">> Done!"
  229.  
  230. HF_TOKEN=${HF_TOKEN:-""}
  231. if [ -n "${HF_TOKEN}" ]; then
  232. HUGGINGFACE_ACCESS_TOKEN=${HF_TOKEN}
  233. else
  234. yn="N"
  235. HUGGINGFACE_ACCESS_TOKEN="None"
  236. fi
  237.  
  238. MODEL_NAME="Gensyn/Qwen2.5-0.5B-Instruct"
  239. export MODEL_NAME
  240. echo_green ">> Using model: $MODEL_NAME"
  241.  
  242. echo_green ">> Good luck in the swarm!"
  243. echo_blue ">> And remember to star the repo on GitHub! --> https://github.com/gensyn-ai/rl-swarm"
  244.  
  245. python -m rgym_exp.runner.swarm_launcher \
  246. --config-path "$ROOT/rgym_exp/config" \
  247. --config-name "rg-swarm.yaml"
  248.  
  249. wait # Keep script running until Ctrl+C
Advertisement
Add Comment
Please, Sign In to add comment