#!/usr/bin/env bash # opencode-qwen4-35b-fp8-gb10 entrypoint. Runs inside the container; takes no arguments. # opencode serve on 0.0.0.0:4096, then the control gateway on $M64_PORT. Port 4096 is # [runtime.app]: m64 exposes it (the full opencode web UI and API) on a second front # port. 0.0.0.0 is inside the container: only the gate can reach its internal network. set -eu echo '{"phase":"loading","detail":"vLLM: loading Qwen4-35B-A3B FP8"}' >> "$M64_STATUS" mkdir -p /scratch/cache export HF_HUB_OFFLINE=1 TRANSFORMERS_OFFLINE=1 VLLM_NO_USAGE_STATS=1 DO_NOT_TRACK=1 export XDG_CACHE_HOME=/scratch/cache VLLM_CACHE_ROOT=/scratch/cache/vllm TRITON_CACHE_DIR=/scratch/cache/triton export VLLM_USE_RUST_FRONTEND=1 # Loading the 60 GB checkpoint from a NAS takes about 10 minutes, past the default 600 s the frontend waits for the engine. export VLLM_ENGINE_READY_TIMEOUT_S=3600 # The checkpoint comes in two artifact mounts: one model directory of links. M=/scratch/model mkdir -p "$M" for part in /weights/part1 /weights/part2; do (cd "$part" && find . -type f -o -type l) | while read -r f; do mkdir -p "$M/$(dirname "$f")"; ln -sfn "$part/${f#./}" "$M/${f#./}" done done # The LLM: vLLM's Qwen4-35B-A3B recipe (as the qwen4-35b-a3b-fp8-gb10 capsule), on loopback. vllm serve "$M" --host 127.0.0.1 --port 9000 \ --served-model-name qwen4-35b-a3b \ --trust-remote-code \ --tensor-parallel-size 1 \ --max-model-len 262144 \ --gpu-memory-utilization 0.75 \ --max-num-seqs 4 \ --kv-cache-dtype fp8 \ --attention-config.indexer_kv_dtype fp8 \ --disable-flashinfer-autotune \ --enable-prefix-caching \ --enable-auto-tool-choice \ --tool-call-parser qwen4 \ --reasoning-parser qwen4 \ --speculative-config '{"method":"mtp","num_speculative_tokens":3,"index_share_for_mtp_iteration":true}' & VLLM_PID=$! export AGENT_PROVIDER=local-vllm AGENT_MODEL=qwen4-35b-a3b # HOME is the run's /scratch: opencode's DB, caches and every session dir go with the run. export HOME=/scratch/home export WORK_DIR=/scratch/work mkdir -p "$HOME" "$WORK_DIR/sessions" # Packages opencode installs on first start, warmed at build time (at run time there is no # network unless the run is granted some). cp -rn /opt/opencode-capsule/. "$HOME/" export OPENCODE_CONFIG=/capsule/opencode.json # opencode is a Bun binary; its provider is the local vLLM on 127.0.0.1 (NO_PROXY), so nothing # goes through the m64 gate unless the agent's own tools reach out (and the run allows it). # Run from $WORK_DIR: the web UI's (and `opencode attach`'s) project is the run's scratch # workspace. The gateway still gives each of its sessions a directory under sessions/. cd "$WORK_DIR" opencode serve --hostname 0.0.0.0 --port 4096 --pure & OPENCODE_PID=$! # If opencode dies, take the container down so m64 reports the error. $$ is the gateway # after the exec below. The gateway never reaps opencode, so a dead opencode lingers as a # zombie (state Z): test the state, not just whether the pid exists. alive() { [ -r "/proc/$1/stat" ] && [ "$(cut -d')' -f2 "/proc/$1/stat" | cut -d' ' -f2)" != Z ]; } ( while alive "$OPENCODE_PID" && alive "$VLLM_PID"; do sleep 5; done echo '{"phase":"error","detail":"opencode or vLLM exited"}' >> "$M64_STATUS" kill -TERM $$ ) & exec python3 /capsule/agent_gateway.py