motif64

m64_7bd84a9e1959 / start.sh

61 lines, 3.3 KBraw
1#!/usr/bin/env bash2# pi-qwen38fn-llamacpp-gb10 entrypoint. Runs inside the container; takes no arguments.3#   127.0.0.1:8080     llama-server (llama.cpp v1.0.0), Qwen3.8-Flash-Next IQ3_S, 262144-token context, pictures on4#   127.0.0.1:4096     cli_shim.py: `pi -p --mode json` once per prompt5#   0.0.0.0:$M64_PORT  agent_gateway.py: the agent.session API6# The engine is started exactly as the qwen38-flash-next-llamacpp-gb10 capsule starts it;7# the GGUF shards are mounted read-only under /weights; nothing is fetched at runtime.8set -eu9QUANT=${QUANT:-IQ3_S}10CONTEXT=${CONTEXT:-262144}11VISION=${VISION:-on}12status() { printf '{"phase":"%s","detail":"%s"}\n' "$1" "$2" >> "$M64_STATUS"; }13status loading "loading $QUANT into memory (about 84 GB from disk on a cold start)"14# HOME and the harness's state live in this run's /scratch.15export HOME=/scratch/home XDG_STATE_HOME=/scratch/state XDG_CONFIG_HOME=/scratch/config16mkdir -p "$HOME" "$XDG_STATE_HOME" "$XDG_CONFIG_HOME"1718# llama-server, started exactly as the qwen38-flash-next-llamacpp-gb10 capsule starts it: shard 1 (the weights)19# memory-mapped and offloaded whole, shard 2 (the 29 GB PLE n-gram table) read lazily from the page cache,20# the model's own sampling (the GGUF's general.sampling values), pictures at >= 1024 tokens each.21W=/weights/qwen38fn22S1=$(ls "$W/$QUANT"/*-00001-of-00002.gguf)23S2=$(ls "$W/$QUANT"/*-00002-of-00002.gguf)24SERVED=qwen3.8-flash-next-iq3_s-llamacpp25args=(-m "$S1" --ple "$S2" --alias "$SERVED"26      --host 127.0.0.1 --port 808027      -c "$CONTEXT" -np "${PARALLEL:-1}" -ngl 999 -fa on28      -ctk q8_0 -ctv q8_0 -b 2048 -ub 204829      -lm mmap --lazy-mode on30      --temp 1.0 --top-k 20 --top-p 0.95 --min-p 031      --jinja --no-ui --metrics)32if [ "$VISION" = on ]; then args+=(--mmproj "$W/mmproj-Qwen3.8-Flash-Next-BF16.gguf" --image-min-tokens 1024); fi33/opt/llama/bin/llama-server "${args[@]}" &34LLAMA=$!35until curl -sf http://127.0.0.1:8080/health >/dev/null; do36  kill -0 $LLAMA 2>/dev/null || { status error "llama-server exited during load"; exit 1; }37  sleep 238done3940# The harness: pi's HOME and every session directory live in this run's /scratch.41export WORK_DIR=/scratch/work SHIM_HOMES=/scratch/homes42mkdir -p "$WORK_DIR/sessions" "$SHIM_HOMES"43export AGENT_HARNESS=pi44export AGENT_HARNESS_TITLE="pi coding agent 0.73.1 (badlogic/pi-mono)"45export AGENT_MODEL="$SERVED" UPSTREAM_MODEL="$SERVED"46export AGENT_CONTEXT=$CONTEXT AGENT_VISION=147# The airbench checkup harness's settings at this window (see cli_shim.py).48export AGENT_MAX_OUT=$(( CONTEXT >= 262144 ? 32768 : CONTEXT / 8 )) AGENT_COMPACTION_RESERVE=$(( CONTEXT / 4 ))49export LLM_BASE_URL=http://127.0.0.1:8080/v150export RELAY_URL=http://127.0.0.1:8080        # the gateway's health check: llama-server's /health51export NODE_USE_ENV_PROXY=1                   # web access, if granted, goes through the m64 gate52/opt/gateway/bin/python3 -u /capsule/cli_shim.py &53SHIM_PID=$!5455# If the shim or llama-server dies, take the container down so m64 reports the error ($$ is the gateway after exec).56alive() { [ -r "/proc/$1/stat" ] && [ "$(cut -d')' -f2 "/proc/$1/stat" | cut -d' ' -f2)" != Z ]; }57( while alive "$SHIM_PID" && curl -sf -o /dev/null http://127.0.0.1:8080/v1/models; do sleep 10; done58  echo '{"phase":"error","detail":"llama-server or the pi shim exited"}' >> "$M64_STATUS"59  kill -TERM $$ ) &6061exec /opt/gateway/bin/python3 /capsule/agent_gateway.py