#!/usr/bin/env bash # opencode-ornith15-122b-tf-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 # TensorFold admits memory from min(MemAvailable, the GPU's free memory), and on the GB10's unified memory the GPU's # free memory leaves out the page cache: drop the weight files' cached pages first (posix_fadvise DONTNEED needs no # privileges for files we can read). python3 -I - <<'EVICT' import os for dp, _, fs in os.walk("/weights", followlinks=True): for f in fs: try: fd = os.open(os.path.join(dp, f), os.O_RDONLY) os.posix_fadvise(fd, 0, 0, os.POSIX_FADV_DONTNEED) os.close(fd) except OSError: pass EVICT echo '{"phase":"loading","detail":"TensorFold: loading Ornith-1.5-122B"}' >> "$M64_STATUS" # The LLM: MiaAI-Lab's Ornith-1.5-122B recipe (as the ornith15-122b-tensorfold-gb10 capsule), on loopback. export TENSORFOLD_CUDA_KERNELS=native TENSORFOLD_MEMORY_RESERVE_GIB=10 TENSORFOLD_NO_UPDATE_CHECK=1 HF_HUB_OFFLINE=1 export TENSORFOLD_MAX_IMAGES=50 TENSORFOLD_IMAGE_TOKENS=16384 TENSORFOLD_VIDEO_TOKENS=16384 export TENSORFOLD_VISION_WORKSPACE_MIB=2048 export CUDA_CACHE_PATH=/scratch/cache/nv mkdir -p "$CUDA_CACHE_PATH" tensorfold-native serve /weights/model \ --name ornith-1.5-122b --host 127.0.0.1 --port 9000 \ --context 262144 --parallel 4 --max-tokens 32768 \ --temperature 0.6 --top-p 0.95 --top-k 20 \ --thinking \ --drafter /weights/draft \ --kv-cache fp8 \ --vision --vision-max-images 50 --vision-max-videos 4 --vision-image-tokens 16384 & VLLM_PID=$! export AGENT_PROVIDER=local-vllm AGENT_MODEL=ornith-1.5-122b # 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 TensorFold engine 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 TensorFold exited"}' >> "$M64_STATUS" kill -TERM $$ ) & exec /opt/gateway/bin/python3 /capsule/agent_gateway.py