motif64

m64_610762301be1 / start.sh

65 lines, 3.2 KBraw
1#!/usr/bin/env bash2# opencode-nemotron35bolt-tf-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 -eu78# TensorFold admits memory from min(MemAvailable, the GPU's free memory), and on the GB10's unified memory the GPU's9# free memory leaves out the page cache: drop the weight files' cached pages first (posix_fadvise DONTNEED needs no10# privileges for files we can read).11python3 -I - <<'EVICT'12import os13for dp, _, fs in os.walk("/weights", followlinks=True):14    for f in fs:15        try:16            fd = os.open(os.path.join(dp, f), os.O_RDONLY)17            os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED)18            os.close(fd)19        except OSError:20            pass21EVICT2223echo '{"phase":"loading","detail":"TensorFold: loading Nemotron 3.5 Bolt"}' >> "$M64_STATUS"24# The LLM: MiaAI-Lab's Nemotron 3.5 Bolt recipe (as the nemotron35-bolt-tensorfold-gb10 capsule), on loopback.25export TENSORFOLD_MEMORY_RESERVE_GIB=10 TENSORFOLD_NO_UPDATE_CHECK=1 HF_HUB_OFFLINE=126export BOLT_KV=bf16 BOLT_KV_PIN=0 BOLT_SSM_LAZY=1 BOLT_DRAFT_Q8=1 BOLT_NV4_FP4=127export BOLT_DRAFT=/weights/draft28export CUDA_CACHE_PATH=/scratch/cache/nv29mkdir -p "$CUDA_CACHE_PATH"30tensorfold-native serve /weights/model \31    --name nemotron-3.5-bolt --host 127.0.0.1 --port 9000 \32    --context 262144 --parallel 16 --max-tokens 32768 \33    --temperature 1.0 --top-p 0.95 --prompt-cache-gib 8 \34    --thinking \35    --vision --vision-max-images 64 --vision-max-videos 4 \36    --vision-image-tokens 262144 --vision-video-tokens 131072 &37VLLM_PID=$!38export AGENT_PROVIDER=local-vllm AGENT_MODEL=nemotron-3.5-bolt3940# HOME is the run's /scratch: opencode's DB, caches and every session dir go with the run.41export HOME=/scratch/home42export WORK_DIR=/scratch/work43mkdir -p "$HOME" "$WORK_DIR/sessions"44# Packages opencode installs on first start, warmed at build time (at run time there is no45# network unless the run is granted some).46cp -rn /opt/opencode-capsule/. "$HOME/"4748export OPENCODE_CONFIG=/capsule/opencode.json49# opencode is a Bun binary; its provider is the local TensorFold engine on 127.0.0.1 (NO_PROXY), so nothing50# goes through the m64 gate unless the agent's own tools reach out (and the run allows it).51# Run from $WORK_DIR: the web UI's (and `opencode attach`'s) project is the run's scratch52# workspace. The gateway still gives each of its sessions a directory under sessions/.53cd "$WORK_DIR"54opencode serve --hostname 0.0.0.0 --port 4096 --pure &55OPENCODE_PID=$!5657# If opencode dies, take the container down so m64 reports the error. $$ is the gateway58# after the exec below. The gateway never reaps opencode, so a dead opencode lingers as a59# zombie (state Z): test the state, not just whether the pid exists.60alive() { [ -r "/proc/$1/stat" ] && [ "$(cut -d')' -f2 "/proc/$1/stat" | cut -d' ' -f2)" != Z ]; }61( while alive "$OPENCODE_PID" && alive "$VLLM_PID"; do sleep 5; done62  echo '{"phase":"error","detail":"opencode or TensorFold exited"}' >> "$M64_STATUS"63  kill -TERM $$ ) &6465exec /opt/gateway/bin/python3 /capsule/agent_gateway.py