m64_e761fc6b57c3 / start.sh
67 lines, 3.3 KBraw
1#!/usr/bin/env bash2# opencode-qwen4-35b-fp8-gb10 entrypoint. Runs inside the container; takes no arguments.3# opencode serve on 0.0.0.0:4096, then the control gateway on $M64_PORT. Port 4096 is4# [runtime.app]: m64 exposes it (the full opencode web UI and API) on a second front5# port. 0.0.0.0 is inside the container: only the gate can reach its internal network.6set -eu78echo '{"phase":"loading","detail":"vLLM: loading Qwen4-35B-A3B FP8"}' >> "$M64_STATUS"9mkdir -p /scratch/cache10export HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 VLLM_NO_USAGE_STATS=1 DO_NOT_TRACK=111export XDG_CACHE_HOME=/scratch/cache VLLM_CACHE_ROOT=/scratch/cache/vllm TRITON_CACHE_DIR=/scratch/cache/triton12export VLLM_USE_RUST_FRONTEND=113# Loading the 60 GB checkpoint from a NAS takes about 10 minutes, past the default 600 s the frontend waits for the engine.14export VLLM_ENGINE_READY_TIMEOUT_S=360015# The checkpoint comes in two artifact mounts: one model directory of links.16M=/scratch/model17mkdir -p "$M"18for part in /weights/part1 /weights/part2; do19 (cd "$part" && find . -type f -o -type l) | while read -r f; do20 mkdir -p "$M/$(dirname "$f")"; ln -sfn "$part/${f#./}" "$M/${f#./}"21 done22done23# The LLM: vLLM's Qwen4-35B-A3B recipe (as the qwen4-35b-a3b-fp8-gb10 capsule), on loopback.24vllm serve "$M" --host 127.0.0.1 --port 9000 \25 --served-model-name qwen4-35b-a3b \26 --trust-remote-code \27 --tensor-parallel-size 1 \28 --max-model-len 262144 \29 --gpu-memory-utilization 0.75 \30 --max-num-seqs 4 \31 --kv-cache-dtype fp8 \32 --attention-config.indexer_kv_dtype fp8 \33 --disable-flashinfer-autotune \34 --enable-prefix-caching \35 --enable-auto-tool-choice \36 --tool-call-parser qwen4 \37 --reasoning-parser qwen4 \38 --speculative-config '{"method":"mtp","num_speculative_tokens":3,"index_share_for_mtp_iteration":true}' &39VLLM_PID=$!40export AGENT_PROVIDER=local-vllm AGENT_MODEL=qwen4-35b-a3b4142# HOME is the run's /scratch: opencode's DB, caches and every session dir go with the run.43export HOME=/scratch/home44export WORK_DIR=/scratch/work45mkdir -p "$HOME" "$WORK_DIR/sessions"46# Packages opencode installs on first start, warmed at build time (at run time there is no47# network unless the run is granted some).48cp -rn /opt/opencode-capsule/. "$HOME/"4950export OPENCODE_CONFIG=/capsule/opencode.json51# opencode is a Bun binary; its provider is the local vLLM on 127.0.0.1 (NO_PROXY), so nothing52# goes through the m64 gate unless the agent's own tools reach out (and the run allows it).53# Run from $WORK_DIR: the web UI's (and `opencode attach`'s) project is the run's scratch54# workspace. The gateway still gives each of its sessions a directory under sessions/.55cd "$WORK_DIR"56opencode serve --hostname 0.0.0.0 --port 4096 --pure &57OPENCODE_PID=$!5859# If opencode dies, take the container down so m64 reports the error. $$ is the gateway60# after the exec below. The gateway never reaps opencode, so a dead opencode lingers as a61# zombie (state Z): test the state, not just whether the pid exists.62alive() { [ -r "/proc/$1/stat" ] && [ "$(cut -d')' -f2 "/proc/$1/stat" | cut -d' ' -f2)" != Z ]; }63( while alive "$OPENCODE_PID" && alive "$VLLM_PID"; do sleep 5; done64 echo '{"phase":"error","detail":"opencode or vLLM exited"}' >> "$M64_STATUS"65 kill -TERM $$ ) &6667exec python3 /capsule/agent_gateway.py