mirror of
https://github.com/hasso5703/alzeo.git
synced 2026-12-06 04:44:19 +01:00
The flash's abliterated checkpoint is 136 GB like the stock one (205 of its 206 shards are the same size), the Flash-Next install's download is the checkpoint and its 16 GB image, and an image pruned by mistake is re-pulled in 15 to 16 GB, not 30. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
3120 lines
199 KiB
Bash
Executable File
3120 lines
199 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Qwen3.8 serving stack on DGX Spark (GB10): 27B (SGLang+DFlash2) or Flash-Next
|
|
# 176B (SGLang+NEXTN, PLE table mmap-served from NVMe). Systemd, hardened.
|
|
# Idempotent: safe to re-run at any time (uses local caches when present).
|
|
# Everything is PINNED to versions validated on this hardware (the 27B image on
|
|
# 2026-09-17, everything else on 2026-09-11); override with env vars if you want
|
|
# to try newer builds (see --help). Since v1.14 BOTH lanes serve an OFFICIAL
|
|
# SGLang image with nothing added and this script builds nothing by default: the
|
|
# flash lane crossed over in v1.8, the 27B lane followed once the two reasons it
|
|
# had stayed behind were measured rather than restated (see the IMAGE pin below).
|
|
# The flash lane's old overlay files stay in flash-sglang/ as the record of what
|
|
# upstream replaced; nothing builds them since v1.18.7 (see OVERLAY_FLASH below).
|
|
set -euo pipefail
|
|
trap 'printf "\n\033[1;31mInstall failed at line %s (command: %s).\033[0m\nRe-running ./install.sh is safe: completed steps are skipped.\n" "$LINENO" "$BASH_COMMAND" >&2' ERR
|
|
|
|
# die() is the first thing this file defines, not something down at the steps:
|
|
# the refusal below is the first thing that can reject an invocation, and
|
|
# calling a function the shell has not seen yet printed "command not found" and
|
|
# exited through the ERR trap, losing the message that names the problem
|
|
# (tests/test_install_preflight.py pins that failure mode on the port checks).
|
|
die() { printf '\n\033[1;31mERROR:\033[0m %s\n' "$*" >&2; exit 1; }
|
|
|
|
# ── The first wall: this installer does not run as root ──────────────────────
|
|
# Everything it writes is addressed from $HOME, and the units it renders carry
|
|
# those paths plus User=$(id -un). Put sudo in front and $HOME is /root: the
|
|
# config dir becomes /root/.config/qwen38 with a BRAND NEW API key, the engine
|
|
# unit points --api-key at that file, and every client reading
|
|
# ~/.config/qwen38/api-key gets 401 from an engine that is otherwise perfectly
|
|
# healthy. Nothing fails loudly, which is what makes it expensive: on the
|
|
# reference box, 2026-09-13, `curl .../get.sh | sudo bash` installed, started,
|
|
# served, and answered a key nobody had; it took a read of the sudo audit log
|
|
# to see why. This installer calls sudo itself, for the privileged steps and
|
|
# for nothing else, so there is never a reason to put sudo in front of it.
|
|
# (id -u rather than $EUID: the refusal is testable that way, and a PATH that
|
|
# can lie about id could edit this file anyway.)
|
|
if [ "$(id -u)" = "0" ]; then
|
|
if [ -n "${SUDO_USER:-}" ]; then
|
|
# || true, and it is load bearing: getent exits 2 on an unknown user, and
|
|
# under set -e + pipefail that killed this very refusal through the ERR
|
|
# trap, printing "Install failed at line ..." instead of the message. A
|
|
# refusal that cannot survive its own lookup is not a refusal.
|
|
SUDO_HOME="$(getent passwd "$SUDO_USER" 2>/dev/null | cut -d: -f6 || true)"
|
|
die "do not put sudo in front of this installer.
|
|
|
|
you ran : sudo ... (your login is $SUDO_USER)
|
|
run instead : curl -fsSL https://raw.githubusercontent.com/hasso5703/dgx-spark-qwen38/main/get.sh | bash
|
|
or locally : ./install.sh (it calls sudo itself, for the steps that need it)
|
|
|
|
Under sudo, HOME is /root: the API key, the chat template and the compile cache
|
|
land in /root/.config/qwen38 and the units point there. The engine then installs,
|
|
starts and serves normally with a key nobody has, and every client reading
|
|
${SUDO_HOME:-/home/$SUDO_USER}/.config/qwen38/api-key gets 401 from it."
|
|
fi
|
|
[ "${ALLOW_ROOT:-0}" = "1" ] || die "this installer runs as the user who will use the box, not as root.
|
|
|
|
Everything it writes is addressed from \$HOME (~/.config/qwen38), and the units it
|
|
renders carry that path plus User=$(id -un). As root that is /root, which is not
|
|
where your clients, your cockpit or your opencode config look.
|
|
|
|
log in as that user and run it there
|
|
or, if this box genuinely has no other user: ALLOW_ROOT=1 ./install.sh"
|
|
fi
|
|
|
|
# Remember which knobs the operator set explicitly on THIS invocation, before
|
|
# the defaults below fill them in: an explicit env var beats the installed
|
|
# unit, which beats the defaults (see the convergence block further down).
|
|
_ENV_MODEL_CHOICE="${MODEL_CHOICE:-}"; _ENV_MODEL_REV="${MODEL_REV:-}"
|
|
_ENV_PORT="${PORT:-}"; _ENV_HF_CACHE="${HF_CACHE:-}"
|
|
_ENV_CONTEXT_MODE="${CONTEXT_MODE:-}"; _ENV_PROXY_PORT="${PROXY_PORT:-}"
|
|
_ENV_ENGINE_BIND="${ENGINE_BIND:-}"; _ENV_PROXY_BIND="${PROXY_BIND:-}"
|
|
_ENV_PLE_DIR="${PLE_DIR:-}"; FLASH_TIER_ENV="${FLASH_TIER:-}"
|
|
_ENV_SPEC_TOKEN_MAP_SIZE="${SPEC_TOKEN_MAP_SIZE:-}"; _ENV_FLASH_REPLAYSSM_SPEC="${FLASH_REPLAYSSM_SPEC:-}"
|
|
_ENV_DRAFT2_REPO="${DRAFT2_REPO:-}"; _ENV_DRAFT2_REV="${DRAFT2_REV:-}"
|
|
_ENV_DRAFT2_QUANT="${DRAFT2_QUANT:-}"; _ENV_DRAFT2_TOKENS="${DRAFT2_TOKENS:-}"
|
|
# A run installs the text lane that does not serve as well, beside the one it serves: it
|
|
# starts this script again for that lane, with QWEN38_SECONDARY naming it (27b or flash).
|
|
# That run converges on that lane's own installed choices, installs its unit without
|
|
# enabling it, starts nothing, and leaves the proxy, the boot lane, opencode, the cockpit
|
|
# and the side lanes to the run that started it.
|
|
SECONDARY="${QWEN38_SECONDARY:-}"
|
|
case "$SECONDARY" in
|
|
""|27b|flash) ;;
|
|
*) echo "ERROR: QWEN38_SECONDARY names a text lane, 27b or flash (got: $SECONDARY)" >&2; exit 1 ;;
|
|
esac
|
|
# The other text lane installed on demand beside the lane that serves (the run that serves asks
|
|
# for it when that lane is not prepared): its unit (and the flash lane's launcher) only, with no
|
|
# image, no checkpoint, no template, no draft vocabulary, and no room taken for them. Its first
|
|
# Load from the cockpit prepares it (prepare-lane.sh), checking the room for what it fetches,
|
|
# and that Load's switch writes its template (and the 27B's 1M configs).
|
|
UNITS_ONLY=0
|
|
if [ "${QWEN38_UNITS_ONLY:-0}" = 1 ]; then
|
|
case "$SECONDARY" in
|
|
flash|27b) UNITS_ONLY=1 ;;
|
|
*) echo "ERROR: QWEN38_UNITS_ONLY is for the text lane installed beside another (QWEN38_SECONDARY=flash or 27b)" >&2; exit 1 ;;
|
|
esac
|
|
fi
|
|
|
|
# ── Pinned, validated versions (override via env if you know what you do) ──
|
|
# The 27B lane's image, and since v1.14 it is the official release, served
|
|
# directly with no overlay built on top of it. Until v1.13 this lane built its
|
|
# own image (the 2026-08-15 base plus eight sha256-verified files) for two
|
|
# reasons, and both were retired by measurement on 2026-09-17 rather than by
|
|
# assumption:
|
|
# - DFlash2 itself, merged upstream 2026-08-19 (sglang#35371) together with
|
|
# the quantized target lm_head the candidate selector projects through
|
|
# (sglang#35496). Both are in v0.5.19: diffed file by file against the
|
|
# overlay, not one function of it is missing upstream, and upstream carries
|
|
# about ten this box never had.
|
|
# - The mrope fix (sglang#34446, "the fused Qwen3.5 RoPE kernel discards mrope
|
|
# height and width", merged 2026-08-30), whose failure mode is silent image
|
|
# corruption. v0.5.19 is built after it: checked in the image, its
|
|
# fused_qk_rmsnorm_rope_gate.py carries mrope_axis_map, same as the overlay.
|
|
# The sm_121 objection that kept this lane off the release is retired too, and it
|
|
# was never a departure: v0.5.19 reports arch_list up to sm_120 and ships
|
|
# sgl_kernel variants for sm90 and sm100 only, but SO DOES the image this lane
|
|
# served before it, byte for byte (15301320 and 14711496). GB10 loads the sm100
|
|
# cubin either way.
|
|
# Measured on the box, same flags, same probes, 2026-09-17: greedy median 71.4
|
|
# against 69.8 tok/s, acceptance 4.29 against 4.09, conc-check 40/40 serial and
|
|
# 160/160 at concurrency 8 on both, needle retrieval exact at 300,108 prompt
|
|
# tokens on both (514 s against 493 s, the one point where the release is
|
|
# behind). The KV pool needs the fraction moved from 0.70 to 0.76 to match, for
|
|
# the reason written at CONTEXT_MODE below.
|
|
# v1.23.0 moved the lane from v0.5.19 to v0.5.21 (2026-10-01), the release the cookbook's
|
|
# DGX Spark recipe now names (lmsysorg/sglang:latest), for sglang#37818: on v0.5.19 a DFlash
|
|
# verify that crosses a 256-token Mamba tracking boundary saved no checkpoint, so a turn
|
|
# that reused a generated answer from the prefix cache resumed from a stale linear state
|
|
# (largest log-probability shift among the first token's five likeliest candidates, against
|
|
# a full recompute: 3.25 nats, median of 16 documents; 0.54 on v0.5.21).
|
|
# Measured on the box, same flags, same probes, 2026-10-09: prefill log-probabilities
|
|
# identical bit for bit (30 texts of 1,024 tokens), GSM8K 248 and 247 of 250, needle exact
|
|
# at 299,901 tokens, conc-check 40/40 and 160/160 on both, pool 872,414 to 878,687 on three
|
|
# boots (854,123 to 888,628 on four v0.5.19 boots). v0.5.21 refuses --cuda-graph-max-bs
|
|
# as ambiguous; the units say --cuda-graph-max-bs-decode, which v0.5.19 resolves to the
|
|
# same settings, so IMAGE= with the v0.5.19 digest still rolls back (booted that way on
|
|
# the box: the 18 production checks pass). cuBLAS and PyTorch are the same in both.
|
|
IMAGE="${IMAGE:-lmsysorg/sglang@sha256:b1259f3ea3275f66237c498ea388919729018bc9f01c3d638391e06e2cf3f469}" # = lmsysorg/sglang:v0.5.21, 2026-10-01
|
|
# Target model choice: "stock" (validated censored base, default) or "uncensored"
|
|
# (huihui-ai abliteration re-quantized with the identical RadixArk modelopt
|
|
# NVFP4 recipe: same architecture, chat template, MTP + vision, ~22 GB).
|
|
STOCK_REPO="RadixArk/Qwen3.8-27B-NVFP4"
|
|
STOCK_REV="52d1adc5f38aa5ebf099c29ed7025ba34cfbb854"
|
|
# Qwen's own FP8 release: the quality reference of the 27B lane. Weights are 30.9 GB
|
|
# against 21 GB for NVFP4, which SGLang takes out of the KV pool: measured on the
|
|
# reference box, the same 1m unit reports 863,398 tokens on NVFP4 and 771,139 on
|
|
# FP8, so about 92,000 fewer (an earlier note here extrapolated 200,000 from
|
|
# 20,000 tokens per GB; the measurement is the number to trust).
|
|
# Decode is bandwidth bound on GB10, so it is also slower. No flag changes: SGLang reads
|
|
# the scheme from the checkpoint's own config.
|
|
FP8_REPO="Qwen/Qwen3.8-27B-FP8"
|
|
FP8_REV="017b9c7af6b5689d5dd426a76e0bc077eb5ca20a"
|
|
# The abliterated weights in Qwen's own FP8 format: same packager as the NVFP4
|
|
# uncensored target above, same fp8 e4m3 scheme as Qwen's official release (which this
|
|
# repo already serves), and lm_head is left out of the quantization, which is what keeps
|
|
# an FP8 checkpoint loadable by SGLang. Verified against the official FP8: 66 weight
|
|
# files, not one hash in common, so the abliteration is real and not a rename.
|
|
UNCFP8_REPO="edp1096/Huihui-Qwen3.8-27B-abliterated-FP8"
|
|
UNCFP8_REV="603028a116e50e57baeda318eff6181be4ce5876"
|
|
UNC_REPO="edp1096/Huihui-RadixArk-Qwen3.8-27B-abliterated-NVFP4"
|
|
UNC_REV="21565d389fe573a32c1c425e0c7ade204ddb2263"
|
|
# Third target: Qwen3.8-Flash-Next (176B hybrid MoE, 6B active) in NVFP4 on
|
|
# SGLang (same engine as the 27B pair), single box. The official image cannot
|
|
# fit it on a GB10 as shipped; the locally built two-file overlay mmaps the 51B
|
|
# N-gram (PLE) table from NVMe and unblocks QSA decode on sm_121 (see
|
|
# flash-sglang/ATTRIBUTION.md). Same service surface: port, API key, keepalive
|
|
# proxy, opencode wiring, and (v1.5) working prefix caching, vision and the
|
|
# Anthropic endpoint. Serving flags validated on the reference box 2026-08-28.
|
|
FLASH_REPO="RadixArk/Qwen3.8-Flash-Next-NVFP4"
|
|
FLASH_REV="7b719225242aacd3dbd3f9407468c2ee9a9d2594"
|
|
# Fifth checkpoint of the flash lane: NVIDIA's own ModelOpt MIXED_PRECISION
|
|
# export of the same model (NVFP4 routed experts, FP8 N-gram table, FP8
|
|
# block-scaled MTP experts). On one box its smaller fp8 draft leaves a much
|
|
# larger KV pool than the RadixArk export at the same pins (upstream measured
|
|
# 174k tokens against 93k with MTP). It needs the mixed-precision loader of
|
|
# sglang#38121, which the image below has and the older qwen38flashnext tag
|
|
# does not, and it must NOT be passed --quantization (it resolves to
|
|
# modelopt_mixed on its own) while --moe-runner-backend has to be pinned to
|
|
# flashinfer_cutlass, because the mixed-precision auto-default picks
|
|
# flashinfer_trtllm on GB10 and the NVFP4 MoE method rejects it at autotune.
|
|
FLASH_NVDA_REPO="nvidia/Qwen3.8-Flash-Next-NVFP4"
|
|
FLASH_NVDA_REV="fc694b54fb0174e0913e6adf86691ef85a4ead47"
|
|
# Sixth checkpoint of the flash lane: the abliterated build of the same model, in
|
|
# the same tree. Chosen on evidence rather than on popularity: of the abliterated
|
|
# Flash-Next exports published for this architecture, this one has 206 shards
|
|
# with the same names as RadixArk's and 205 of them byte-identical in size, plus
|
|
# the same index, the same hf_quant_config and the same chat template, so it is
|
|
# an abliteration OF the export this lane already serves and every serving flag
|
|
# transfers unchanged. It declares library_name sglang, keeps the MTP head and
|
|
# stays multimodal. The alternative with more downloads
|
|
# (orcarouter/Qwen3.8-Flash-Next-Uncensored-NVFP4) was rejected here: 18 shards,
|
|
# 170.9 GiB, no hf_quant_config and a separate model-mtp.safetensors, so a
|
|
# different packaging and a different loader path, none of it validated on this
|
|
# recipe. The Mia/Keys splice was rejected for a harder reason: it is built on
|
|
# the vLLM tree (architecture Qwen3_8FlashNextForConditionalGeneration,
|
|
# model_type qwen3_8_flash_next) and SGLang registers only
|
|
# Qwen4ExpForConditionalGeneration, with zero mentions of the other name
|
|
# anywhere in the image, so it cannot be served here at all.
|
|
FLASH_UNC_REPO="dealignai/Qwen3.8-Flash-Next-ABLITERATED-NVFP4"
|
|
FLASH_UNC_REV="be794b990578ef3031eccf9f28e675a289a09ee9"
|
|
# The flash lane's image. Since v1.8 this is the image the cookbook points DGX
|
|
# Spark at: the qwen4-main-squashed build, which carries the file-backed PLE
|
|
# table backend (sglang#37068, replacing this repo's mmap overlay), the merged
|
|
# KDA QSA sm_121 decode kernel (sglang#36845, replacing the vendored copy), the
|
|
# router fix for the GB10 MTP output collapse (sglang#36811 via #38308/#38290,
|
|
# which is the root cause of the wall of "!" the proxy learned to detect in
|
|
# v1.6), and the mixed-precision loader (sglang#38121).
|
|
FLASH_IMAGE="${FLASH_IMAGE:-lmsysorg/sglang@sha256:3e79541d1e2a6818979c4aa9ca1fa63d6961d7bc50120867953ea6baaf1d8f62}" # = lmsysorg/sglang:nightly-cu134-20261011-53295c6, measured 2026-10-12 on this box against 6caf0ff, same target and tier: logprobs bit-identical on 30 fixed texts (NLL 1.6229 both), GSM8K 247 vs 248 of 250, needle 120k/200k 2/2 with identical replies, greedy decode median 46.6/49.6 vs 44.3/46.9 tok/s, serving c4 output 61.0 vs 58.0 tok/s with a tighter p99, pool +1.9% (boot noise), every client green (SDK, Node, Bun, LiteLLM, 4 agents; one isolated Hermes truncation retested 3/3). The previous pin was 6caf0ff (nightly-cu134-20260928, 2026-09-28); an update untags it like any retired pin (unpin_stale below), so a docker image prune reclaims it.
|
|
# Backing store for the flash target's file-backed 47.7 GiB PLE table. The
|
|
# server rewrites it on every boot (~10 min from a fresh sparse file, ~55 min
|
|
# over a populated one), so the launcher deletes the previous file first.
|
|
PLE_DIR="${PLE_DIR:-$HOME/flashnext-ple}"
|
|
# Resident-set budget for the table's mapping (SGLANG_QWEN4_PLE_FILE_RSS_BUDGET_GB,
|
|
# upstream default 8 GiB, 0 disables). A row fault maps in a whole page-cache
|
|
# folio, so the mapping's RSS climbs towards 47.7 GiB while a token reads a few
|
|
# KB of it; on unified memory that is the same pool the KV cache is sized from,
|
|
# which is why upstream trims it. This is the knob behind the pool lottery this
|
|
# repo pinned --max-total-tokens for in v1.6.2.
|
|
PLE_RSS_BUDGET_GB="${PLE_RSS_BUDGET_GB:-8}"
|
|
MODEL_CHOICE="${MODEL_CHOICE:-stock}"
|
|
case "$MODEL_CHOICE" in
|
|
stock) MODEL_REPO="$STOCK_REPO"; MODEL_REV="${MODEL_REV:-$STOCK_REV}" ;;
|
|
uncensored) MODEL_REPO="$UNC_REPO"; MODEL_REV="${MODEL_REV:-$UNC_REV}" ;;
|
|
fp8) MODEL_REPO="$FP8_REPO"; MODEL_REV="${MODEL_REV:-$FP8_REV}" ;;
|
|
uncensored-fp8) MODEL_REPO="$UNCFP8_REPO"; MODEL_REV="${MODEL_REV:-$UNCFP8_REV}" ;;
|
|
flash) MODEL_REPO="$FLASH_REPO"; MODEL_REV="${MODEL_REV:-$FLASH_REV}" ;;
|
|
flash-nvda) MODEL_REPO="$FLASH_NVDA_REPO"; MODEL_REV="${MODEL_REV:-$FLASH_NVDA_REV}" ;;
|
|
flash-uncensored) MODEL_REPO="$FLASH_UNC_REPO"; MODEL_REV="${MODEL_REV:-$FLASH_UNC_REV}" ;;
|
|
*) printf 'ERROR: MODEL_CHOICE must be "stock", "uncensored", "fp8", "uncensored-fp8", "flash", "flash-nvda" or "flash-uncensored" (got: %s)\n' "$MODEL_CHOICE" >&2; exit 1 ;;
|
|
esac
|
|
# Which flags the flash lane's checkpoint wants. The RadixArk export is plain
|
|
# NVFP4 and says so; NVIDIA's is a mixed-precision export that resolves its own
|
|
# scheme and needs the MoE runner pinned (see FLASH_NVDA_REPO above).
|
|
# Both the target's scheme and the DRAFT's belong to the checkpoint, not to the
|
|
# serving tier. RadixArk and its abliteration quantized only the routed experts,
|
|
# so their 31 in-checkpoint MTP tensors are BF16 and the draft must be told not
|
|
# to quantize them; NVIDIA's export ships FP8 block-scaled MTP experts and its
|
|
# verified cell passes no draft quantization at all, so forcing "unquant" there
|
|
# would load an fp8 head as if it were dense.
|
|
#
|
|
# A FUNCTION, and called again after the convergence block below, because that
|
|
# block can change MODEL_CHOICE (a plain ./install.sh on a flash box converges
|
|
# from the default "stock" to "flash"). Computed once, it kept the empty value
|
|
# the default had chosen and the rendered launcher lost --quantization
|
|
# modelopt_fp4 entirely: the engine then resolved its MoE runner to
|
|
# flashinfer_trtllm and died ten minutes into the boot with "Unsupported
|
|
# moe_runner_backend for NVFP4 MoE" (2026-09-08, on the reference box).
|
|
resolve_flash_checkpoint_args() {
|
|
case "$MODEL_CHOICE" in
|
|
flash|flash-uncensored)
|
|
FLASH_QUANT_ARGS="--quantization modelopt_fp4 --speculative-draft-model-quantization unquant " ;;
|
|
flash-nvda)
|
|
FLASH_QUANT_ARGS="--moe-runner-backend flashinfer_cutlass " ;;
|
|
*)
|
|
FLASH_QUANT_ARGS="" ;;
|
|
esac
|
|
}
|
|
resolve_flash_checkpoint_args
|
|
# Lane implied by the target model: the 27B pair and Flash-Next each have
|
|
# their own unit and serving image (both SGLang since v1.5), same port,
|
|
# never enabled together.
|
|
LANE=27b; UNIT_NAME="qwen38-sglang.service"
|
|
case "$MODEL_CHOICE" in
|
|
flash|flash-nvda|flash-uncensored) LANE=flash; UNIT_NAME="qwen38-flash.service" ;;
|
|
esac
|
|
# Serving tier of the flash lane. Every mamba state slot costs 0.206 GiB of the
|
|
# same pool the KV cache comes out of (measured here), and the hybrid GDN/QSA
|
|
# model reserves 5 slots per running request with extra_buffer, 4 with
|
|
# extra_buffer_lazy, so concurrency and the longest servable prompt trade against
|
|
# each other one for one:
|
|
# context 4 requests, 20 slots, MTP: KV pool 295,936 tokens, so a full
|
|
# 262,144-token prompt fits.
|
|
# concurrency 8 requests, 40 slots, 2 states per path, MTP: the default since
|
|
# 2026-09-30, measured on this box (~/flashtest-palier8,
|
|
# ~/flashtest-nightly2809): pool 477,056 tokens, so a full 262K
|
|
# prompt fits at 8 requests, bench median 46.9 tok/s single
|
|
# stream (vs 46.2 without the per-path cap), canaries 4/4,
|
|
# needle 120k/200k 2/2, prefix cache 99.9% on a repeated prefix.
|
|
# The per-path cap halves the state each speculative path holds,
|
|
# which is what makes 8 requests fit in 40 slots.
|
|
# throughput 24 requests, 96 lazy slots, no speculation: the cookbook's
|
|
# high-throughput cell, 83 tok/s of output at 24 upstream and a
|
|
# ~286k pool, at 15.9 tok/s single stream.
|
|
FLASH_TIER="${FLASH_TIER:-concurrency}"
|
|
# MTP verify intermediates on a fixed ring instead of per-request state slots
|
|
# (the cookbook's EAGLE row on SM120/SM121). Measured on this box 2026-09-12,
|
|
# context tier, same target: pool 463,936 -> 557,312 (+20%, above the previous
|
|
# boot range), decode neutral (42.4 vs 43.1 greedy median, mixed per-probe
|
|
# directions inside the documented uptime drift), canaries 4/4, no corruption.
|
|
# Refused with the throughput tier, which runs no speculation. On unless
|
|
# asked: measured +20% pool on this box, decode neutral, canaries 4/4.
|
|
FLASH_REPLAYSSM_SPEC="${FLASH_REPLAYSSM_SPEC:-1}"
|
|
# Also a function, and for the same reason: the convergence block can adopt the
|
|
# tier the installed launcher is already serving.
|
|
resolve_flash_tier_args() {
|
|
case "$FLASH_TIER" in
|
|
context)
|
|
FLASH_TIER_ARGS="--max-running-requests 4 --max-mamba-cache-size 20 --mamba-radix-cache-strategy extra_buffer --speculative-algorithm NEXTN --speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4" ;;
|
|
concurrency)
|
|
FLASH_TIER_ARGS="--max-running-requests 8 --max-mamba-cache-size 40 --mamba-max-states-per-path 2 --mamba-radix-cache-strategy extra_buffer --speculative-algorithm NEXTN --speculative-num-steps 3 --speculative-eagle-topk 1 --speculative-num-draft-tokens 4" ;;
|
|
throughput)
|
|
FLASH_TIER_ARGS="--max-running-requests 24 --max-mamba-cache-size 96 --mamba-radix-cache-strategy extra_buffer_lazy" ;;
|
|
*) printf 'ERROR: FLASH_TIER must be "context", "concurrency" or "throughput" (got: %s)\n' "$FLASH_TIER" >&2; exit 1 ;;
|
|
esac
|
|
case "$FLASH_REPLAYSSM_SPEC" in
|
|
0|"") ;;
|
|
1)
|
|
# No speculation on throughput, so nowhere to apply it: say so and skip,
|
|
# instead of failing a convergent throughput reinstall on the new default.
|
|
case "$FLASH_TIER" in
|
|
throughput) echo "NOTE: FLASH_REPLAYSSM_SPEC=1 has no speculation to apply to on the throughput tier; ignored" ;;
|
|
*) FLASH_TIER_ARGS="$FLASH_TIER_ARGS --enable-linear-replayssm-spec" ;;
|
|
esac ;;
|
|
*) printf 'ERROR: FLASH_REPLAYSSM_SPEC must be 0 or 1 (got: %s)\n' "$FLASH_REPLAYSSM_SPEC" >&2; exit 1 ;;
|
|
esac
|
|
}
|
|
resolve_flash_tier_args
|
|
# The cookbook's verified value for both single-Spark cells. Lower it if your box
|
|
# runs co-tenants: the pools are sized from what the host has free at profiling.
|
|
FLASH_MEM_FRACTION="${FLASH_MEM_FRACTION:-0.85}"
|
|
# Reduced draft vocabulary, in token ids (0 = off). A speculative step's draft
|
|
# reads the model's lm_head in full, and at 248,320 x 2560 in BF16 that is
|
|
# 1.18 GiB read three times per MTP-3 engine step. SGLang can hand the draft a
|
|
# sliced head instead (--speculative-token-map): the target still verifies over
|
|
# the whole vocabulary, so this cannot change what the model is allowed to say.
|
|
# build-token-map.py writes the list; install.sh builds it inside the serving
|
|
# image, where the tokenizer version matches the served model by construction.
|
|
# The size is a measured choice, not a guess: see BENCHMARKS.md.
|
|
SPEC_TOKEN_MAP_SIZE="${SPEC_TOKEN_MAP_SIZE:-65536}"
|
|
# The file name carries the size, so a box that changes SPEC_TOKEN_MAP_SIZE
|
|
# builds a new map instead of serving the old one under a new intent. Defined
|
|
# here and not earlier on purpose: the first version of this line sat above the
|
|
# size it interpolates, and ${...:-0} turned that ordering bug into a silently
|
|
# mis-named file rather than an error.
|
|
TOKEN_MAP_NAME="token-map-${SPEC_TOKEN_MAP_SIZE}.pt"
|
|
# The DSpark drafter. Served up to v1.1; DFlash2 replaced it in v1.2 and no
|
|
# serving path has referenced it since, so it is no longer downloaded (it cost
|
|
# 6 GB and a few minutes on every 27B install). The pin stays so the cockpit's
|
|
# registry can still recognise a copy left on disk, and `git checkout v1.1 &&
|
|
# ./install.sh` fetches it through that release's own installer.
|
|
# RadixArk published a v2 of this draft on 2026-08-28 claiming +26% acceptance
|
|
# over v1 (3.43 aggregate over 64,675 prompts on their own card), which would
|
|
# put it level with DFlash2 on paper. Measured here on 2026-09-18, same box,
|
|
# same unit, only the drafter swapped (b9a5dbdf, DSPARK, gamma auto-inferred):
|
|
# greedy median 48.7 tok/s against DFlash2's 72.0, acceptance 3.49 against 4.29,
|
|
# conc-check clean on both. It does leave a larger pool (953,442 against
|
|
# 889,131) because its verify window is 8 rather than 16, and that does not come
|
|
# close to paying for a third of the throughput. The lane stays on DFlash2.
|
|
# shellcheck disable=SC2034 # read externally: dashboard/registry.py pairs DRAFT_REV
|
|
# with this repo id to classify a leftover DSpark copy, and uninstall.sh lists it.
|
|
DRAFT_REPO="RadixArk/Qwen3.8-27B-DSpark"
|
|
DRAFT_REV="${DRAFT_REV:-85ef153be924f17ce4bf62726954eeaa4a73e854}"
|
|
# The DFlash2 drafter the 27B lane serves. Since v1.9 this is maurienne-ai's
|
|
# calibrated NVFP4 build of the z-lab draft (3.53 GB BF16 -> 1.37 GB of VRAM,
|
|
# same acceptance once calibrated), served 16 tokens deep instead of 8.
|
|
# Measured on the reference box, same target, same flags otherwise:
|
|
# bench.sh greedy median 50 -> 65.3 tok/s (+30%), bench-matrix code 41 -> 40,
|
|
# tech-FR 26 -> 32, reasoning-FR 43.5 -> 49.5, prose unchanged, pool 357,706
|
|
# tokens, 0 corruption markers, 4 concurrent streams clean. The drafters are
|
|
# lossless by construction (the target verifies every drafted token), and the
|
|
# depth was swept, not guessed (D8 -> D16 alone is +19% pooled throughput).
|
|
# Rollback to the BF16 draft: DRAFT2_REPO=z-lab/Qwen3.8-27B-DFlash2
|
|
# DRAFT2_REV=50307d4c4cde6860d4eee73e2547cd786fe8e8a4 DRAFT2_QUANT=unquant
|
|
# DRAFT2_TOKENS=8 ./install.sh (then restart the unit).
|
|
DRAFT2_REPO="${DRAFT2_REPO:-maurienne-ai/Qwen3.8-27B-DFlash2-NVFP4-RTNcal}"
|
|
DRAFT2_REV="${DRAFT2_REV:-bd7a934213c47a9e7ef69eef36bb3325f47fd1f1}"
|
|
DRAFT2_QUANT="${DRAFT2_QUANT:-modelopt_fp4}"
|
|
DRAFT2_TOKENS="${DRAFT2_TOKENS:-16}"
|
|
# Context mode: "1m" (1,010,000 via YaRN static scaling, mem-fraction 0.76,
|
|
# plus the keepalive proxy for agent clients) or "native" (262144). Since
|
|
# v1.12.1 an unset CONTEXT_MODE means 1m on the 27B lane: it is the preset the
|
|
# reference box has served daily since 2026-08-22, and a stack whose headline
|
|
# window has to be asked for by name ships it off for almost everybody.
|
|
# Empty here means "not chosen yet". The default is resolved further down,
|
|
# once the lane, the flags and the installed unit are all known, because the
|
|
# two paths that cannot serve 1m (the flash lane and --no-service) have to
|
|
# fall back to native in silence rather than refuse a default nobody typed.
|
|
# The fraction is 0.76 since v1.14, and the number is the image's, not a taste.
|
|
# The official image sizes its static budget more conservatively than the
|
|
# locally built one this lane served before: at an identical 0.70 it came up
|
|
# with a 770,118-token pool against 906,524, while leaving 29.89 GB of GPU
|
|
# memory unused against 19.38. It was never short of memory, it just did not
|
|
# claim it. 0.76 hands the pool back (902,398 measured, inside the boot-to-boot
|
|
# spread this box shows on one image: 906,524 then 910,203) and still leaves a
|
|
# wider margin than the old pin did, 21.30 GB against 19.38.
|
|
# What bounds this number is the unified pool, NOT the container: --memory 100g
|
|
# is a host-RSS cap and the cgroup does not see CUDA unified allocations.
|
|
# Measured 2026-09-18 at 0.76 under a 5,623-token generation, the container held
|
|
# 7.15 GiB of its 100 GiB the whole way. Read the GPU-side headroom instead
|
|
# (available_gpu_mem after graph capture), which is what every number here is.
|
|
CONTEXT_MODE="${CONTEXT_MODE:-}"
|
|
case "$CONTEXT_MODE" in
|
|
native|1m|"") ;;
|
|
*) printf 'ERROR: CONTEXT_MODE must be "native" or "1m" (got: %s)\n' "$CONTEXT_MODE" >&2; exit 1 ;;
|
|
esac
|
|
if [ "$LANE" = "flash" ] && [ "$CONTEXT_MODE" = "1m" ]; then
|
|
printf 'ERROR: CONTEXT_MODE=1m is a 27B mode. Flash-Next serves its full native 262144 window\n' >&2
|
|
printf ' by default; a validated long-context mode for it may come in a later release.\n' >&2
|
|
exit 1
|
|
fi
|
|
# What actually gets served. Until v1.7 both lanes served a locally built image:
|
|
# the pinned official base plus sha256-verified overlay files, because no
|
|
# official image carried DFLASH2 or ran Flash-Next on one GB10. Both are
|
|
# upstream now, so both lanes serve the pinned official image directly and
|
|
# build nothing. The flash lane crossed over in v1.8; the 27B lane followed in
|
|
# v1.14, once the two things holding it back were measured rather than assumed
|
|
# (see the IMAGE pin above).
|
|
#
|
|
# OVERLAY_FLASH=1 used to rebuild the flash lane's old overlay image (v1.5 to v1.7)
|
|
# as its rollback, and serve it with the launcher of v1.8, which does not fit it:
|
|
# the overlay's model code keeps the 47.7 GiB PLE table in pinned host RAM unless
|
|
# SGLANG_QWEN4_PLE_MMAP_DIR is set, the launcher sets no such thing and passes
|
|
# --ple-offload-backend file (sglang#37068, newer than the overlay's base) instead,
|
|
# and it has none of the attention backends and sizes the overlay was validated
|
|
# with. Nothing had booted that pairing since v1.8 (found in review, 2026-09-24).
|
|
# The overlay, its launcher and its pins shipped together in v1.7.2, which is the
|
|
# rollback that holds together.
|
|
if [ "${OVERLAY_FLASH:-${OVERLAY:-0}}" = "1" ]; then
|
|
die "OVERLAY_FLASH=1 is retired: this release's flash launcher does not fit the overlay image, and the pair cannot boot. The overlay path shipped whole in v1.7.2 (git checkout v1.7.2 && ./install.sh); this release serves the official image (unset OVERLAY_FLASH)."
|
|
fi
|
|
# Every line below sits at column 0 and refers only to names defined above it,
|
|
# because run.sh and switch-model.sh read these assignments out of this file and
|
|
# eval them with nothing else bound.
|
|
SERVE_IMAGE="${SERVE_IMAGE:-$IMAGE}"
|
|
FLASH_SERVE_IMAGE="${FLASH_SERVE_IMAGE:-$FLASH_IMAGE}"
|
|
# opencode, the client this repo configures and serves in the cockpit's Agent tab, is
|
|
# pinned like everything else. Four things the repo does were read out of this
|
|
# version's own binary and checked against its behaviour: the compaction threshold
|
|
# oc-fit-limits.py sizes the limits for, the hidden 32,000-token output cap the oc
|
|
# launcher lifts (182,000 sent with the variable, 32,000 without, measured on a fake
|
|
# endpoint), the overflow phrases the proxy answers with so a refusal triggers a
|
|
# compaction (21 of 21 present), and --yolo / OPENCODE_PERMISSION for the Agent tab.
|
|
# 1.18.32 passed all of it against the 1.18.27 the repo was measured on (2026-09-23), and
|
|
# 1.18.35 against 1.18.32 (2026-10-10), which also masks the provider keys `opencode debug
|
|
# config` prints, where 1.18.32 printed this box's key in clear.
|
|
# Left alone, opencode installs its own patch releases, so two boxes installed a
|
|
# week apart run two versions. The sha256 is GitHub's own digest of the release asset
|
|
# opencode-linux-arm64.tar.gz. OPENCODE_PIN=0 keeps whatever opencode you have.
|
|
_ENV_OPENCODE_VERSION="${OPENCODE_VERSION:-}"
|
|
_ENV_OPENCODE_SHA256="${OPENCODE_SHA256:-}"
|
|
OPENCODE_VERSION="${OPENCODE_VERSION:-1.18.35}"
|
|
OPENCODE_SHA256="${OPENCODE_SHA256:-f7f2ba59ee8aa94d388f9696575a32d20e71c2ee48def9f80fc693a60fec6c72}"
|
|
OPENCODE_PIN="${OPENCODE_PIN:-1}"
|
|
PORT="${PORT:-30000}"
|
|
HF_CACHE="${HF_CACHE:-$HOME/.cache/huggingface}"
|
|
CONFIG_DIR="$HOME/.config/qwen38"
|
|
REPO_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
# the text lane the box comes back to, one record shared with switch-model.sh (lanes.sh)
|
|
# shellcheck source=lanes.sh
|
|
. "$REPO_DIR/lanes.sh"
|
|
|
|
NO_START=0
|
|
NO_SERVICE=0
|
|
NO_OPENCODE=0
|
|
WITH_OPENCODE=0
|
|
NO_COCKPIT=0
|
|
WITH_COCKPIT=0
|
|
WITH_IMAGE=0
|
|
NO_IMAGE=0
|
|
WITH_VIDEO=0
|
|
NO_VIDEO=0
|
|
WITH_FLASH=0
|
|
NO_FLASH=0
|
|
WITH_27B=0
|
|
NO_27B=0
|
|
WITH_KOLIBRI=0
|
|
NO_KOLIBRI=0
|
|
WITH_NEMOTRON=0
|
|
NO_NEMOTRON=0
|
|
WITH_NEMOTRON_SUPER=0
|
|
NO_NEMOTRON_SUPER=0
|
|
ALL_WEIGHTS=0
|
|
for arg in "$@"; do
|
|
case "$arg" in
|
|
--no-start) NO_START=1 ;;
|
|
--no-service) NO_SERVICE=1 ;;
|
|
--no-opencode) NO_OPENCODE=1 ;;
|
|
--with-opencode) WITH_OPENCODE=1 ;;
|
|
--no-cockpit) NO_COCKPIT=1 ;;
|
|
--with-cockpit) WITH_COCKPIT=1 ;;
|
|
--with-image) WITH_IMAGE=1 ;;
|
|
--no-image) NO_IMAGE=1 ;;
|
|
--with-video) WITH_VIDEO=1 ;;
|
|
--no-video) NO_VIDEO=1 ;;
|
|
--with-flash) WITH_FLASH=1 ;;
|
|
--no-flash) NO_FLASH=1 ;;
|
|
--with-27b) WITH_27B=1 ;;
|
|
--no-27b) NO_27B=1 ;;
|
|
--with-kolibri) WITH_KOLIBRI=1 ;;
|
|
--no-kolibri) NO_KOLIBRI=1 ;;
|
|
--with-nemotron) WITH_NEMOTRON=1 ;;
|
|
--no-nemotron) NO_NEMOTRON=1 ;;
|
|
--with-nemotron-super) WITH_NEMOTRON_SUPER=1 ;;
|
|
--no-nemotron-super) NO_NEMOTRON_SUPER=1 ;;
|
|
--all-weights) ALL_WEIGHTS=1 ;;
|
|
--with-claude-warmup)
|
|
echo "NOTE: --with-claude-warmup was removed in v1.3 (the repo's client story moved to opencode)."
|
|
echo " The flag is ignored; an installed warmup drop-in from an earlier version is cleaned up." ;;
|
|
-h|--help)
|
|
cat <<'HLP'
|
|
Usage: ./install.sh [--no-start] [--no-service] [--no-opencode | --with-opencode]
|
|
[--no-cockpit | --with-cockpit] [--no-image | --with-image]
|
|
[--no-video | --with-video] [--no-flash | --with-flash]
|
|
[--no-27b | --with-27b] [--no-kolibri | --with-kolibri]
|
|
[--no-nemotron | --with-nemotron]
|
|
[--no-nemotron-super | --with-nemotron-super]
|
|
[--all-weights]
|
|
|
|
Run it as yourself. Never with sudo in front: it calls sudo itself for the
|
|
privileged steps, and under sudo every path it writes moves to /root (see the
|
|
refusal at the top of this file).
|
|
|
|
A plain run installs the box: the text lane MODEL_CHOICE names (the 27B by
|
|
default), which serves, the keepalive proxy with its typed decision endpoint,
|
|
the opencode wiring, the cockpit and its Agent view, and every other lane on
|
|
demand: a run puts in its units, and the first Load of each from the cockpit
|
|
prepares it as the user, with no sudo, and fetches its weights. That is the
|
|
other text lane (the flash beside the 27B, its image, checkpoint and PLE table,
|
|
223 GB; or the 27B beside a serving flash, its image, draft and checkpoint,
|
|
58), the image lane (46), the video lane (174), the Kolibri lane (Aleph
|
|
Alpha's Kolibri-1, on vLLM, 102), the Nemotron lane (NVIDIA's Nemotron 3.5
|
|
Bolt, on vLLM, 51) and the Nemotron Super lane (NVIDIA's Nemotron 3.5 Super VL
|
|
on vLLM, in the Nemotron lane's image: 77 beside it, else 102). The lane that
|
|
serves proves it serves before the run ends; on a new box the 27B takes 58 GB
|
|
of disk, about 39 GB of
|
|
downloads (about 6 to 7 minutes at 100 MB/s). A lane installed whole (--all-weights, --with-<lane>)
|
|
that does not fit on the disk is left out and named at the end, with the
|
|
command that adds it later. When it finishes it prints the
|
|
cockpit URL, and from there you start, stop, switch, watch and benchmark
|
|
without a terminal.
|
|
|
|
--no-start install everything but don't start the service now
|
|
--no-service no systemd, no sudo: just prepare one text lane (image,
|
|
checkpoints, key, template), then run it in the
|
|
foreground anytime with ./run.sh (Ctrl+C stops it)
|
|
--no-opencode skip the opencode integration (no generated config, no
|
|
oc launcher, and switch-model.sh leaves your opencode
|
|
default model alone). Remembered by later runs.
|
|
--with-opencode re-enable it after a --no-opencode
|
|
--no-cockpit skip the web cockpit and its Agent view (no dashboard
|
|
unit, no sudoers allowlist). Remembered by later runs.
|
|
--with-cockpit re-enable it after a --no-cockpit
|
|
--no-image leave the Qwen-Image 2.1 lane out (46 GB). Remembered
|
|
by later runs; a lane already installed stays in place,
|
|
not updated (./install-image.sh --uninstall removes it)
|
|
--with-image bring it back after a --no-image
|
|
--no-video leave the MiniMax-H3 video lane out (174 GB),
|
|
remembered the same way (./install-video.sh --uninstall)
|
|
--with-video bring it back after a --no-video
|
|
--no-flash leave the flash 176B lane out when it is not the one
|
|
serving (223 GB), remembered the same way
|
|
--with-flash bring it back after a --no-flash
|
|
--no-27b leave the 27B lane out when it is not the one serving
|
|
(58 GB), remembered the same way
|
|
--with-27b bring it back after a --no-27b
|
|
--no-kolibri leave the Kolibri-1 lane out (vLLM, 102 GB), remembered
|
|
the same way (./install-kolibri.sh --uninstall removes it)
|
|
--with-kolibri bring it back after a --no-kolibri
|
|
--no-nemotron leave the Nemotron 3.5 Bolt lane out (vLLM, 51 GB),
|
|
remembered the same way (./install-nemotron.sh --uninstall)
|
|
--with-nemotron bring it back after a --no-nemotron
|
|
--no-nemotron-super leave the Nemotron 3.5 Super VL lane out (vLLM, 102 GB),
|
|
remembered the same way (./install-nemotron-super.sh --uninstall)
|
|
--with-nemotron-super bring it back after a --no-nemotron-super
|
|
--all-weights install every lane whole now (the flash beside the 27B,
|
|
the image, video, Kolibri and both Nemotron lanes), runtime
|
|
and weights, about 731 GB of disk, and prove each new one
|
|
(without it, each is prepared at its first Load from
|
|
the cockpit; --with-<lane> does the same for that one
|
|
lane)
|
|
|
|
Re-running over an existing install keeps the operator's choices: the target
|
|
model (any of the seven), the context mode (native/1m), the flash serving tier,
|
|
the port, the HF cache location and the opencode on/off choice are read from
|
|
the installed unit or launcher (or the marker file) unless the env var or flag
|
|
is passed explicitly.
|
|
|
|
Env overrides (defaults are pinned to the versions validated on the reference
|
|
box, the 27B image on 2026-10-09):
|
|
IMAGE=lmsysorg/sglang:v0.5.21 the moving tag of the pinned digest, instead
|
|
of the digest itself (this run only: IMAGE
|
|
is not remembered, pass it on every run)
|
|
MODEL_REV=main use the latest target revision
|
|
DRAFT2_REV=main latest DFlash2 draft revision
|
|
DRAFT2_REPO=z-lab/Qwen3.8-27B-DFlash2 DRAFT2_REV=50307d4c4cde6860d4eee73e2547cd786fe8e8a4 DRAFT2_QUANT=unquant DRAFT2_TOKENS=8
|
|
roll the 27B lane back to the BF16 draft
|
|
at depth 8 (the default since v1.9 is the
|
|
calibrated NVFP4 draft at depth 16)
|
|
MODEL_CHOICE=uncensored serve the huihui-abliterated model
|
|
(edp1096 NVFP4) instead of the stock base
|
|
MODEL_CHOICE=fp8 serve Qwen's own FP8 release (30.9 GB, slower
|
|
decode; its 1M pool measured 881,895 tokens
|
|
against 887,797 for NVFP4, 2026-09-18)
|
|
MODEL_CHOICE=uncensored-fp8 the huihui abliteration in that same FP8 format
|
|
MODEL_CHOICE=flash serve Qwen3.8-Flash-Next (176B hybrid MoE,
|
|
NVFP4, SGLang engine, ~136 GB download; the
|
|
47.7 GiB N-gram table is served from a file
|
|
on NVMe, with prefix caching and vision)
|
|
MODEL_CHOICE=flash-uncensored the abliterated build of the same tree
|
|
(~136 GB): 205 of its 206 shards are
|
|
byte-identical in size to the stock export,
|
|
so every serving flag is the same one
|
|
MODEL_CHOICE=flash-nvda the same model from NVIDIA's own mixed-
|
|
precision export (~133 GB download), served
|
|
with no --quantization and a pinned MoE
|
|
runner; measured here as a tie with stock
|
|
SPEC_TOKEN_MAP_SIZE=0 flash: serve without the reduced draft
|
|
vocabulary (it is worth 14 to 25% of decode
|
|
and cannot change what the model may say)
|
|
FLASH_TIER=concurrency flash only: 8 concurrent requests with the
|
|
MTP head instead of 4 (a full 262K prompt
|
|
still fits their measured pool); "throughput"
|
|
is 24 without speculation
|
|
FLASH_REPLAYSSM_SPEC=0 flash only: keep MTP verify intermediates
|
|
in per-request state slots instead of the
|
|
fixed ring (measured +20% pool on this box,
|
|
decode neutral, canaries 4/4)
|
|
FLASH_MEM_FRACTION=0.85 flash only: static memory fraction
|
|
PLE_RSS_BUDGET_GB=8 flash only: resident-set budget of the
|
|
N-gram table's mapping (0 disables the trim)
|
|
PLE_DIR=~/flashnext-ple flash only: where the 47.7 GiB backing file
|
|
of the N-gram table lives
|
|
CONTEXT_MODE=native the 262144 window instead of the 1,010,000
|
|
one. Since v1.12.1 a 27B install serves 1m
|
|
by default (YaRN static scaling, README,
|
|
"The 1M context mode"); the flash lane and
|
|
--no-service are native either way, and a
|
|
re-run keeps whatever is already installed
|
|
PROXY_PORT=30001 keepalive proxy port (default: PORT+1)
|
|
SERVE_IMAGE=ref serving image for the 27B lane
|
|
FLASH_SERVE_IMAGE=ref serving image for the Flash-Next lane
|
|
HF_CACHE=/path HuggingFace cache location (~24 GB for a 27B
|
|
target and its draft, ~136 GB for flash)
|
|
PORT=30000 serving port
|
|
HLP
|
|
exit 0 ;;
|
|
*) printf 'Unknown flag: %s (see --help)\n' "$arg" >&2; exit 1 ;;
|
|
esac
|
|
done
|
|
|
|
# ── Converge on the operator's installed choices ──
|
|
# Re-running the installer (or the get.sh one-liner) must never silently reset
|
|
# a choice that is already serving: the target model (any of the seven targets),
|
|
# the port, and the HF cache location are read from the installed units and
|
|
# kept, unless the corresponding env var was passed explicitly on this
|
|
# invocation. Everything else (image digest, checkpoint revisions, launch
|
|
# flags) always follows the repo: that is what an upgrade is.
|
|
KEEP_MODEL_VERBATIM=0
|
|
SGL_UNIT_PATH="/etc/systemd/system/qwen38-sglang.service"
|
|
FLASH_UNIT_PATH="/etc/systemd/system/qwen38-flash.service"
|
|
KOLIBRI_UNIT_PATH="/etc/systemd/system/qwen38-kolibri.service"
|
|
NEMOTRON_UNIT_PATH="/etc/systemd/system/qwen38-nemotron.service"
|
|
NEMOTRON_SUPER_UNIT_PATH="/etc/systemd/system/qwen38-nemotron-super.service"
|
|
for _p in "$SGL_UNIT_PATH" "$FLASH_UNIT_PATH"; do
|
|
if [ -f "$_p" ] && [ ! -r "$_p" ]; then
|
|
echo "NOTE: an installed unit ($_p) exists but is not readable (pre-v1.2.3 installs used mode 600),"
|
|
echo " so its choices cannot be preserved automatically. If you had a custom PORT= or"
|
|
echo " MODEL_CHOICE=, pass them explicitly on this command."
|
|
fi
|
|
done
|
|
# Which interface the engine and the proxy answer on.
|
|
#
|
|
# THE ENGINE IS LOCALHOST-ONLY SINCE v1.17, and that is a changed default. It listened on
|
|
# every interface before, and the measurement that decided it: seven days of journal on
|
|
# the reference box, 581,479 requests to the engine, every single one from 127.0.0.1,
|
|
# while the machine was reached from a laptop and a phone on the cockpit port alone. An
|
|
# open port nobody uses would be an ordinary waste; this one is the port SGLang dies on
|
|
# rather than refuses (sglang#40076 and sglang#31597, both unfixed upstream, both refused
|
|
# at the proxy since v1.15.0). Leaving it open leaves a door beside the one with the lock.
|
|
#
|
|
# Nothing is lost by closing it, which is why the default could move at all: the proxy on
|
|
# PORT+1 is a full pass-through, every route the engine serves and the same OpenAI and
|
|
# Anthropic dialects, plus the guards. A client that pointed at :30000 from another
|
|
# machine points at :30001 and gets more, not less. ENGINE_BIND=0.0.0.0 restores the old
|
|
# behaviour for a box that wants it.
|
|
#
|
|
# The proxy's own default does NOT move: it is the door clients are told to use, the
|
|
# README has said so since v1.5, and it is the one that refuses what the engine cannot.
|
|
ENGINE_BIND="${ENGINE_BIND:-127.0.0.1}"
|
|
PROXY_BIND="${PROXY_BIND:-0.0.0.0}"
|
|
# Loopback or every interface, nothing between: the box reaches both ports itself on
|
|
# 127.0.0.1 (the proxy's UPSTREAM, the health checks and the smoke test, opencode's
|
|
# base_url, the cockpit), so a bind that leaves loopback out breaks all of them. The
|
|
# old check took any digits and dots, 300.1.1.1 and ... included (found in review,
|
|
# 2026-09-24). Called again once the installed binds are read back.
|
|
check_binds() {
|
|
local b
|
|
for b in "ENGINE_BIND=$ENGINE_BIND" "PROXY_BIND=$PROXY_BIND"; do
|
|
case "${b#*=}" in
|
|
127.0.0.1|0.0.0.0) ;;
|
|
*) printf 'ERROR: %s=%s: this box reaches that port itself on 127.0.0.1 (the proxy, the health checks, opencode), so it binds 127.0.0.1 (this machine only) or 0.0.0.0 (every interface: narrow it with a firewall)\n' "${b%%=*}" "${b#*=}" >&2
|
|
exit 1 ;;
|
|
esac
|
|
done
|
|
}
|
|
check_binds
|
|
|
|
# Which choice is installed? The flash unit wins only when it is the enabled
|
|
# one; a box can hold both unit files but only one engine serves the port.
|
|
# On the (hand-made) both-enabled state, the 27B unit is followed and a note
|
|
# is printed: predictable beats clever here.
|
|
INSTALLED_CHOICE=""
|
|
SGL_READABLE=0; FLASH_READABLE=0
|
|
[ -f "$SGL_UNIT_PATH" ] && [ -r "$SGL_UNIT_PATH" ] && SGL_READABLE=1
|
|
[ -f "$FLASH_UNIT_PATH" ] && [ -r "$FLASH_UNIT_PATH" ] && FLASH_READABLE=1
|
|
FLASH_ENABLED=0; SGL_ENABLED=0
|
|
systemctl is-enabled --quiet qwen38-flash.service 2>/dev/null && FLASH_ENABLED=1
|
|
systemctl is-enabled --quiet qwen38-sglang.service 2>/dev/null && SGL_ENABLED=1
|
|
# The image lane is a lane too, and when it is the one enabled at boot it was switched to
|
|
# on purpose. A plain re-run must keep that, the same promise it keeps for the target, the
|
|
# context mode and the port: without this it fell through to "27b" below, enabled the 27B
|
|
# unit beside the image one, and left two engines set to start at the next reboot, with
|
|
# only the order systemd happened to pull them in deciding which one came up.
|
|
IMAGE_BOOT=0
|
|
if [ -z "$SECONDARY" ] && systemctl is-enabled --quiet qwen38-image.service 2>/dev/null \
|
|
&& [ "$SGL_ENABLED" -eq 0 ] && [ "$FLASH_ENABLED" -eq 0 ]; then
|
|
if [ -n "$_ENV_MODEL_CHOICE" ]; then
|
|
# An explicit MODEL_CHOICE asks for a text lane: honour it, and the image lane leaves
|
|
# the boot below, where the text unit is enabled. Keeping the image lane here would
|
|
# answer "install flash" with "flash updated, not served", and exit 0.
|
|
echo "MODEL_CHOICE=$_ENV_MODEL_CHOICE given on a box booting the image lane: making that text lane the boot lane again."
|
|
else
|
|
IMAGE_BOOT=1
|
|
echo "The image lane is this box's boot lane: this run brings the text lane up to date"
|
|
echo "without making it the boot lane again. Switch back to text from the cockpit when you want it."
|
|
fi
|
|
fi
|
|
# The video lane is a lane too, under the same promise: a plain re-run on a box
|
|
# booting video must not enable a text unit beside it.
|
|
VIDEO_BOOT=0
|
|
if [ -z "$SECONDARY" ] && systemctl is-enabled --quiet qwen38-video.service 2>/dev/null \
|
|
&& [ "$SGL_ENABLED" -eq 0 ] && [ "$FLASH_ENABLED" -eq 0 ]; then
|
|
if [ -n "$_ENV_MODEL_CHOICE" ]; then
|
|
# An explicit MODEL_CHOICE asks for a text lane: honour it, and the video lane
|
|
# leaves the boot below, where the text unit is enabled.
|
|
echo "MODEL_CHOICE=$_ENV_MODEL_CHOICE given on a box booting the video lane: making that text lane the boot lane again."
|
|
else
|
|
VIDEO_BOOT=1
|
|
echo "The video lane is this box's boot lane: this run brings the text lane up to date"
|
|
echo "without making it the boot lane again. Switch back to text from the cockpit when you want it."
|
|
fi
|
|
fi
|
|
# The Kolibri lane is a lane of its own too (vLLM, its own unit and installer), under the
|
|
# same promise: a plain re-run on a box booting Kolibri must not enable a SGLang unit beside it.
|
|
KOLIBRI_BOOT=0
|
|
if [ -z "$SECONDARY" ] && systemctl is-enabled --quiet qwen38-kolibri.service 2>/dev/null \
|
|
&& [ "$SGL_ENABLED" -eq 0 ] && [ "$FLASH_ENABLED" -eq 0 ]; then
|
|
if [ -n "$_ENV_MODEL_CHOICE" ]; then
|
|
echo "MODEL_CHOICE=$_ENV_MODEL_CHOICE given on a box booting the Kolibri lane: making that text lane the boot lane again."
|
|
else
|
|
KOLIBRI_BOOT=1
|
|
echo "The Kolibri lane is this box's boot lane: this run brings the other lanes up to date"
|
|
echo "without making one of them the boot lane again. Switch from the cockpit when you want another."
|
|
fi
|
|
fi
|
|
# The Nemotron lane is one too (vLLM, its own unit and installer), under the same promise.
|
|
NEMOTRON_BOOT=0
|
|
if [ -z "$SECONDARY" ] && systemctl is-enabled --quiet qwen38-nemotron.service 2>/dev/null \
|
|
&& [ "$SGL_ENABLED" -eq 0 ] && [ "$FLASH_ENABLED" -eq 0 ]; then
|
|
if [ -n "$_ENV_MODEL_CHOICE" ]; then
|
|
echo "MODEL_CHOICE=$_ENV_MODEL_CHOICE given on a box booting the Nemotron lane: making that text lane the boot lane again."
|
|
else
|
|
NEMOTRON_BOOT=1
|
|
echo "The Nemotron lane is this box's boot lane: this run brings the other lanes up to date"
|
|
echo "without making one of them the boot lane again. Switch from the cockpit when you want another."
|
|
fi
|
|
fi
|
|
# And the Nemotron Super lane, under the same promise.
|
|
NEMOTRON_SUPER_BOOT=0
|
|
if [ -z "$SECONDARY" ] && systemctl is-enabled --quiet qwen38-nemotron-super.service 2>/dev/null \
|
|
&& [ "$SGL_ENABLED" -eq 0 ] && [ "$FLASH_ENABLED" -eq 0 ]; then
|
|
if [ -n "$_ENV_MODEL_CHOICE" ]; then
|
|
echo "MODEL_CHOICE=$_ENV_MODEL_CHOICE given on a box booting the Nemotron Super lane: making that text lane the boot lane again."
|
|
else
|
|
NEMOTRON_SUPER_BOOT=1
|
|
echo "The Nemotron Super lane is this box's boot lane: this run brings the other lanes up to date"
|
|
echo "without making one of them the boot lane again. Switch from the cockpit when you want another."
|
|
fi
|
|
fi
|
|
# Which text lane to bring up to date on that path. Both text units can be on disk with
|
|
# neither enabled, since a switch to a side lane disables both, so enablement cannot say which
|
|
# one was in use; switch-model.sh writes it down instead (lanes.sh: one record since v1.30, the
|
|
# links of a box switched before are read once), and without it the 27B lane is the fallback,
|
|
# the same one the code below picks when nothing is enabled.
|
|
text_lane_migrate
|
|
TEXT_LANE_LAST="$(text_lane_last)"
|
|
if [ "$FLASH_READABLE" -eq 1 ] && [ "$FLASH_ENABLED" -eq 1 ] && [ "$SGL_ENABLED" -eq 1 ]; then
|
|
echo "NOTE: both qwen38-sglang and qwen38-flash are enabled (only one can serve the port)."
|
|
echo " Following the 27B unit; run ./switch-model.sh to resolve this cleanly."
|
|
fi
|
|
if [ "$FLASH_READABLE" -eq 1 ] && [ "$FLASH_ENABLED" -eq 1 ] && [ "$SGL_ENABLED" -eq 0 ]; then
|
|
INSTALLED_CHOICE=flash
|
|
elif [ $((IMAGE_BOOT + VIDEO_BOOT + KOLIBRI_BOOT + NEMOTRON_BOOT + NEMOTRON_SUPER_BOOT)) -gt 0 ] && [ "$TEXT_LANE_LAST" = "qwen38-flash.service" ] \
|
|
&& [ "$FLASH_READABLE" -eq 1 ]; then
|
|
INSTALLED_CHOICE=flash # the text lane this box used before it switched to a side lane
|
|
elif [ "$SGL_READABLE" -eq 1 ]; then
|
|
INSTALLED_CHOICE=27b
|
|
elif [ "$FLASH_READABLE" -eq 1 ]; then
|
|
# flash unit present but not enabled and no sglang unit: still the only choice
|
|
INSTALLED_CHOICE=flash
|
|
fi
|
|
# The secondary run converges on its own lane's unit, whichever one is enabled: the
|
|
# lane its parent serves is, and the detection above follows that one. A lane not
|
|
# installed yet converges on nothing, and takes the target its parent passes.
|
|
if [ -n "$SECONDARY" ]; then
|
|
INSTALLED_CHOICE=""
|
|
if [ "$SECONDARY" = flash ] && [ "$FLASH_READABLE" -eq 1 ]; then INSTALLED_CHOICE=flash; fi
|
|
if [ "$SECONDARY" = 27b ] && [ "$SGL_READABLE" -eq 1 ]; then INSTALLED_CHOICE=27b; fi
|
|
fi
|
|
if [ "$INSTALLED_CHOICE" = "flash" ]; then
|
|
# Converge on the installed flash launch script (the unit only points at it;
|
|
# the engine flags and mounts live in $CONFIG_DIR/launch-flash.sh).
|
|
FLASH_LAUNCH="$CONFIG_DIR/launch-flash.sh"
|
|
CUR_REV=""; CUR_PORT=""; CUR_HF=""
|
|
if [ -r "$FLASH_LAUNCH" ]; then
|
|
CUR_REV="$(grep -oE -- '--revision [^ ]+' "$FLASH_LAUNCH" | head -1 | cut -d' ' -f2 || true)"
|
|
if grep -q 'sglang.launch_server' "$FLASH_LAUNCH"; then
|
|
# v1.5+ shape (SGLang, host networking): --port IS the host port.
|
|
CUR_PORT="$(grep -oE -- '--port [0-9]+' "$FLASH_LAUNCH" | head -1 | tr -dc '0-9' || true)"
|
|
CUR_HF="$(unit_hf_cache "$FLASH_LAUNCH")"
|
|
else
|
|
# v1.4 shape (vLLM, bridge networking): the host port is the -p mapping;
|
|
# its in-container --port 8000 must NOT be read as a host port. The
|
|
# upgrade regenerates the launcher on the new engine, keeping only
|
|
# port/HF/model choices.
|
|
CUR_PORT="$(grep -oE -- '-p [0-9]+:8000' "$FLASH_LAUNCH" | head -1 | grep -oE '^-p [0-9]+' | tr -dc '0-9' || true)"
|
|
CUR_HF="$(grep -oE -- '-v [^ :]+:/hf' "$FLASH_LAUNCH" | head -1 | sed -e 's/^-v //' -e 's|:/hf$||' || true)"
|
|
echo "NOTE: the installed flash lane is the v1.4 vLLM engine; this upgrade moves it to SGLang"
|
|
echo " (working prefix caching; see CHANGELOG v1.5). Port/cache/model choices are kept."
|
|
fi
|
|
CUR_PLE="$(grep -oE -- '-v [^ :]+:/ple' "$FLASH_LAUNCH" | head -1 | sed -e 's/^-v //' -e 's|:/ple$||' || true)"
|
|
CUR_MODEL="$(grep -oE -- '--model-path [^ ]+' "$FLASH_LAUNCH" | head -1 | cut -d' ' -f2 || true)"
|
|
# The tier lives in the launcher as the concurrency it pins, so a re-run
|
|
# without FLASH_TIER keeps the tier the box is serving.
|
|
if [ -z "${FLASH_TIER_ENV:-}" ]; then
|
|
for t in context concurrency throughput; do
|
|
case "$t" in
|
|
context) mrr=4 ;;
|
|
concurrency) mrr=8 ;;
|
|
throughput) mrr=24 ;;
|
|
esac
|
|
if grep -q -- "--max-running-requests $mrr" "$FLASH_LAUNCH" 2>/dev/null; then
|
|
FLASH_TIER="$t"
|
|
echo "Keeping the installed flash tier: $t. Set FLASH_TIER on the command line to change it."
|
|
fi
|
|
done
|
|
resolve_flash_tier_args
|
|
fi
|
|
# The two speculative-path knobs a box can turn off, read back like the tier: set to
|
|
# 0 on one run, both came back on at the next (found in review, 2026-09-24). A
|
|
# launcher that does not speculate carries neither whatever they were, and one
|
|
# rendered before a knob existed says nothing of it: those keep the defaults. The
|
|
# markers are comments of the template, since v1.8 and since v1.10.2.
|
|
if grep -q -- '--speculative-algorithm' "$FLASH_LAUNCH"; then
|
|
if [ -z "$_ENV_SPEC_TOKEN_MAP_SIZE" ] && grep -q 'Engine since v1.8' "$FLASH_LAUNCH"; then
|
|
CUR_MAP="$(grep -oE -- '--speculative-token-map /out/token-map-[0-9]+\.pt' "$FLASH_LAUNCH" | head -1 | sed -E 's/.*token-map-([0-9]+)\.pt/\1/' || true)"
|
|
if [ "${CUR_MAP:-0}" != "$SPEC_TOKEN_MAP_SIZE" ]; then
|
|
SPEC_TOKEN_MAP_SIZE="${CUR_MAP:-0}"; TOKEN_MAP_NAME="token-map-${SPEC_TOKEN_MAP_SIZE}.pt"
|
|
echo "Keeping the installed reduced draft vocabulary: SPEC_TOKEN_MAP_SIZE=$SPEC_TOKEN_MAP_SIZE. Pass SPEC_TOKEN_MAP_SIZE= to change."
|
|
fi
|
|
fi
|
|
if [ -z "$_ENV_FLASH_REPLAYSSM_SPEC" ] && [ "$FLASH_REPLAYSSM_SPEC" = "1" ] \
|
|
&& grep -q 'No --allow-auto-truncate' "$FLASH_LAUNCH" \
|
|
&& ! grep -q -- '--enable-linear-replayssm-spec' "$FLASH_LAUNCH"; then
|
|
FLASH_REPLAYSSM_SPEC=0; resolve_flash_tier_args
|
|
echo "Keeping the installed MTP verify state: FLASH_REPLAYSSM_SPEC=0. Pass FLASH_REPLAYSSM_SPEC=1 to change."
|
|
fi
|
|
fi
|
|
if [ -z "${_ENV_PLE_DIR:-}" ] && [ -n "$CUR_PLE" ] && [ "$CUR_PLE" != "$PLE_DIR" ]; then
|
|
PLE_DIR="$CUR_PLE"
|
|
echo "Keeping the installed PLE table location: $PLE_DIR. Pass PLE_DIR= to change."
|
|
fi
|
|
fi
|
|
if [ -z "$_ENV_MODEL_CHOICE" ] && [ "$LANE" != "flash" ]; then
|
|
MODEL_CHOICE=flash; MODEL_REPO="$FLASH_REPO"; MODEL_REV="${_ENV_MODEL_REV:-$FLASH_REV}"
|
|
if [ -n "${CUR_MODEL:-}" ] && [ "$CUR_MODEL" = "$FLASH_NVDA_REPO" ]; then
|
|
MODEL_CHOICE=flash-nvda; MODEL_REPO="$FLASH_NVDA_REPO"; MODEL_REV="${_ENV_MODEL_REV:-$FLASH_NVDA_REV}"
|
|
elif [ -n "${CUR_MODEL:-}" ] && [ "$CUR_MODEL" = "$FLASH_UNC_REPO" ]; then
|
|
MODEL_CHOICE=flash-uncensored; MODEL_REPO="$FLASH_UNC_REPO"; MODEL_REV="${_ENV_MODEL_REV:-$FLASH_UNC_REV}"
|
|
fi
|
|
LANE=flash; UNIT_NAME="qwen38-flash.service"
|
|
echo "Keeping the installed target model: $MODEL_CHOICE ($MODEL_REPO). Pass MODEL_CHOICE= to change."
|
|
fi
|
|
elif [ "$INSTALLED_CHOICE" = "27b" ]; then
|
|
UNIT_PATH="$SGL_UNIT_PATH"
|
|
CUR_MODEL="$(grep -oE -- '--model-path [^ ]+' "$UNIT_PATH" | head -1 | cut -d' ' -f2 || true)"
|
|
# The target's --revision (never matches --speculative-draft-model-revision:
|
|
# that flag has a single dash before "revision")
|
|
CUR_REV="$(grep -oE -- '--revision [^ ]+' "$UNIT_PATH" | head -1 | cut -d' ' -f2 || true)"
|
|
CUR_PORT="$(grep -oE -- '--port [0-9]+' "$UNIT_PATH" | head -1 | tr -dc '0-9' || true)"
|
|
CUR_HF="$(unit_hf_cache "$UNIT_PATH")"
|
|
if [ -z "$_ENV_MODEL_CHOICE" ] && [ -n "$CUR_MODEL" ] && [ "$CUR_MODEL" != "$MODEL_REPO" ]; then
|
|
case "$CUR_MODEL" in
|
|
"$STOCK_REPO") MODEL_CHOICE=stock; MODEL_REPO="$STOCK_REPO"; MODEL_REV="${_ENV_MODEL_REV:-$STOCK_REV}" ;;
|
|
"$UNC_REPO") MODEL_CHOICE=uncensored; MODEL_REPO="$UNC_REPO"; MODEL_REV="${_ENV_MODEL_REV:-$UNC_REV}" ;;
|
|
"$FP8_REPO") MODEL_CHOICE=fp8; MODEL_REPO="$FP8_REPO"; MODEL_REV="${_ENV_MODEL_REV:-$FP8_REV}" ;;
|
|
"$UNCFP8_REPO") MODEL_CHOICE=uncensored-fp8; MODEL_REPO="$UNCFP8_REPO"; MODEL_REV="${_ENV_MODEL_REV:-$UNCFP8_REV}" ;;
|
|
*) KEEP_MODEL_VERBATIM=1; MODEL_CHOICE=custom; MODEL_REPO="$CUR_MODEL" ;;
|
|
esac
|
|
LANE=27b; UNIT_NAME="qwen38-sglang.service"
|
|
if [ "$KEEP_MODEL_VERBATIM" -eq 1 ]; then
|
|
echo "NOTE: keeping the custom --model-path already installed ($CUR_MODEL)."
|
|
echo " Its download and template steps are skipped (it is already serving from cache)."
|
|
echo " Pass MODEL_CHOICE=stock, uncensored, fp8 or uncensored-fp8 to override."
|
|
else
|
|
echo "Keeping the installed target model: $MODEL_CHOICE ($MODEL_REPO). Pass MODEL_CHOICE= to change."
|
|
fi
|
|
fi
|
|
# Same promise for the drafter: a box rolled back to the BF16 draft via the
|
|
# env override keeps it across plain re-runs, the way MODEL_CHOICE is kept. Each of the
|
|
# four follows the unit unless it is passed: with any one of them passed, all four fell
|
|
# back to the defaults, so DRAFT2_TOKENS=8 on a box serving the BF16 draft moved it to the
|
|
# NVFP4 one without a word (found in review, 2026-09-24). The revision and the
|
|
# quantization belong to the repo, so they follow the unit only with its repo.
|
|
CUR_DRAFT="$(grep -oE -- '--speculative-draft-model-path [^ ]+' "$UNIT_PATH" | head -1 | cut -d' ' -f2 || true)"
|
|
CUR_DRAFT_REV="$(grep -oE -- '--speculative-draft-model-revision [^ ]+' "$UNIT_PATH" | head -1 | cut -d' ' -f2 || true)"
|
|
CUR_DRAFT_QUANT="$(grep -oE -- '--speculative-draft-model-quantization [^ ]+' "$UNIT_PATH" | head -1 | cut -d' ' -f2 || true)"
|
|
CUR_DRAFT_TOKENS="$(grep -oE -- '--speculative-num-draft-tokens [0-9]+' "$UNIT_PATH" | head -1 | tr -dc '0-9' || true)"
|
|
if [ -z "$_ENV_DRAFT2_REPO" ] && [ -n "$CUR_DRAFT" ] && [ "$CUR_DRAFT" != "$DRAFT2_REPO" ]; then
|
|
DEF_DRAFT2="DRAFT2_REPO=$DRAFT2_REPO DRAFT2_REV=$DRAFT2_REV DRAFT2_QUANT=$DRAFT2_QUANT DRAFT2_TOKENS=$DRAFT2_TOKENS"
|
|
DRAFT2_REPO="$CUR_DRAFT"
|
|
[ -z "$_ENV_DRAFT2_REV" ] && [ -n "$CUR_DRAFT_REV" ] && DRAFT2_REV="$CUR_DRAFT_REV"
|
|
[ -z "$_ENV_DRAFT2_QUANT" ] && [ -n "$CUR_DRAFT_QUANT" ] && DRAFT2_QUANT="$CUR_DRAFT_QUANT"
|
|
[ -z "$_ENV_DRAFT2_TOKENS" ] && [ -n "$CUR_DRAFT_TOKENS" ] && DRAFT2_TOKENS="$CUR_DRAFT_TOKENS"
|
|
echo "Keeping the installed drafter: $DRAFT2_REPO (D=$DRAFT2_TOKENS, $DRAFT2_QUANT). Pass DRAFT2_REPO= to change."
|
|
if [ "$CUR_DRAFT" = "z-lab/Qwen3.8-27B-DFlash2" ]; then
|
|
# The default of v1.2.3 to v1.8.6, and the documented rollback since: the unit
|
|
# cannot say which, so it is kept, and a box that was only ever updated never
|
|
# got v1.9's draft (found in review, 2026-09-24). Said here, with the way over.
|
|
echo "NOTE: that is the BF16 draft installs used before v1.9. The default since v1.9 drafts from a"
|
|
echo " calibrated NVFP4 head, measured +30% there on the reference box (lossless). To move to it:"
|
|
echo " $DEF_DRAFT2 ./install.sh"
|
|
fi
|
|
elif [ -z "$_ENV_DRAFT2_TOKENS" ] && [ -n "$CUR_DRAFT_TOKENS" ] && [ "$CUR_DRAFT_TOKENS" != "$DRAFT2_TOKENS" ]; then
|
|
DRAFT2_TOKENS="$CUR_DRAFT_TOKENS"
|
|
echo "Keeping the installed draft depth: D=$DRAFT2_TOKENS. Pass DRAFT2_TOKENS= to change."
|
|
fi
|
|
fi
|
|
if [ -n "$INSTALLED_CHOICE" ]; then
|
|
if [ -z "$_ENV_PORT" ] && [ -n "${CUR_PORT:-}" ] && [ "$CUR_PORT" != "$PORT" ]; then
|
|
PORT="$CUR_PORT"
|
|
echo "Keeping the installed port: :$PORT. Pass PORT= to change."
|
|
fi
|
|
if [ -z "$_ENV_HF_CACHE" ] && [ -n "${CUR_HF:-}" ] && [ "$CUR_HF" != "$HF_CACHE" ]; then
|
|
HF_CACHE="$CUR_HF"
|
|
echo "Keeping the installed HF cache location: $HF_CACHE. Pass HF_CACHE= to change."
|
|
fi
|
|
# The same promise the context mode gets, for the same reason: a box hardened to
|
|
# localhost must not be reopened by a plain update. An installed choice wins over a
|
|
# default, both ways.
|
|
if [ -z "${_ENV_ENGINE_BIND:-}" ]; then
|
|
# Read where the engine's --host really is: the 27B unit, or the flash launcher (its
|
|
# unit only points at the script). This read $UNIT_PATH, which only the 27B branch
|
|
# sets, so every re-run of a flash box printed "UNIT_PATH: unbound variable" and put
|
|
# the engine back on 127.0.0.1 over the box's own choice (found in review, 2026-09-24).
|
|
if [ "$INSTALLED_CHOICE" = "flash" ]; then BIND_FROM="$FLASH_LAUNCH"; else BIND_FROM="$UNIT_PATH"; fi
|
|
CUR_BIND="$(grep -oE -- '--host [0-9.]+' "$BIND_FROM" 2>/dev/null | head -1 | cut -d' ' -f2 || true)"
|
|
if [ -n "$CUR_BIND" ] && [ "$CUR_BIND" != "$ENGINE_BIND" ]; then
|
|
ENGINE_BIND="$CUR_BIND"
|
|
echo "Keeping the installed engine bind: $ENGINE_BIND. Pass ENGINE_BIND= to change."
|
|
fi
|
|
fi
|
|
# The unit name, not $KEEPALIVE_UNIT: that variable is set 700 lines below this block.
|
|
if [ -z "${_ENV_PROXY_BIND:-}" ] && [ -r "/etc/systemd/system/qwen38-keepalive.service" ]; then
|
|
CUR_PBIND="$(grep -oE -- 'PROXY_BIND=[0-9.]+' "/etc/systemd/system/qwen38-keepalive.service" | head -1 | cut -d= -f2 || true)"
|
|
if [ -n "$CUR_PBIND" ] && [ "$CUR_PBIND" != "$PROXY_BIND" ]; then
|
|
PROXY_BIND="$CUR_PBIND"
|
|
echo "Keeping the installed proxy bind: $PROXY_BIND. Pass PROXY_BIND= to change."
|
|
fi
|
|
fi
|
|
check_binds
|
|
if [ "$INSTALLED_CHOICE" = "27b" ] && [ "$LANE" != "flash" ] && [ -z "$_ENV_CONTEXT_MODE" ]; then
|
|
if grep -q -- '--context-length 1010000' "$SGL_UNIT_PATH"; then
|
|
CONTEXT_MODE=1m
|
|
echo "Keeping the installed context mode: 1m. Pass CONTEXT_MODE=native to change."
|
|
elif [ -z "$CONTEXT_MODE" ]; then
|
|
# The other direction, and since v1.12.1 it has to exist: with 1m as the
|
|
# default, a plain re-run on a box installed native would patch YaRN into
|
|
# its cached configs and move its memory fraction, which is not what an
|
|
# update means. An installed choice wins over a default, both ways.
|
|
CONTEXT_MODE=native
|
|
echo "Keeping the installed context mode: native. Pass CONTEXT_MODE=1m to change."
|
|
fi
|
|
fi
|
|
fi
|
|
# (die() is defined at the top of this file, above the root wall that is now the
|
|
# first refusal to call it. It moved out of the steps in v1.10.2 because of the
|
|
# port refusals below: a function defined under a call that fires printed
|
|
# "command not found" and lost the message. tests/test_install_preflight.py
|
|
# pins that, tests/test_install_root_refusal.py pins the wall.)
|
|
|
|
# PORT feeds the arithmetic below, so it is validated before it is used.
|
|
[[ "$PORT" =~ ^[0-9]+$ ]] || die "PORT must be a number (got '$PORT')"
|
|
if [ -z "$_ENV_PROXY_PORT" ] && [ -r "/etc/systemd/system/qwen38-keepalive.service" ]; then
|
|
CUR_PROXY="$(grep -oE 'keepalive-proxy\.py [0-9]+' /etc/systemd/system/qwen38-keepalive.service | head -1 | tr -dc '0-9' || true)"
|
|
[ -n "${CUR_PROXY:-}" ] && PROXY_PORT="$CUR_PROXY"
|
|
fi
|
|
PROXY_PORT="${PROXY_PORT:-$((PORT+1))}"
|
|
|
|
# A non-number dies here with its name on it, and the engine and its proxy may
|
|
# never share one (each check would see "its" port free, then both services
|
|
# would fight over the same socket at runtime).
|
|
[[ "$PROXY_PORT" =~ ^[0-9]+$ ]] || die "PROXY_PORT must be a number (got '$PROXY_PORT')"
|
|
[ "$PORT" != "$PROXY_PORT" ] || die "PORT and PROXY_PORT are both $PORT: the engine and its keepalive proxy cannot share a port"
|
|
|
|
if [ "$NO_SERVICE" -eq 1 ] && [ "$NO_START" -eq 1 ]; then
|
|
printf -- '--no-start controls the systemd service; with --no-service there is no service (drop one flag)\n' >&2; exit 1
|
|
fi
|
|
if [ "$NO_OPENCODE" -eq 1 ] && [ "$WITH_OPENCODE" -eq 1 ]; then
|
|
printf -- '--no-opencode and --with-opencode contradict each other (drop one flag)\n' >&2; exit 1
|
|
fi
|
|
# The opencode on/off choice persists like the other choices: a marker file in
|
|
# CONFIG_DIR, written by --no-opencode, removed by --with-opencode. The switch
|
|
# script and the cockpit read the same marker.
|
|
OC_OFF_MARK="$CONFIG_DIR/opencode.off"
|
|
OPENCODE=1
|
|
if [ "$NO_OPENCODE" -eq 1 ]; then
|
|
OPENCODE=0
|
|
elif [ "$WITH_OPENCODE" -eq 0 ] && [ -f "$OC_OFF_MARK" ]; then
|
|
OPENCODE=0
|
|
echo "Keeping the opencode integration off (your earlier --no-opencode). Pass --with-opencode to re-enable."
|
|
fi
|
|
# Before anything is pulled or downloaded: this was refused at step 7, after the image,
|
|
# the checkpoints and the engine's configs (found in review, 2026-09-24).
|
|
if [ "$OPENCODE" -eq 1 ] && [ -n "$_ENV_OPENCODE_VERSION" ] && [ -z "$_ENV_OPENCODE_SHA256" ]; then
|
|
die "OPENCODE_VERSION=$OPENCODE_VERSION needs OPENCODE_SHA256 too (GitHub's digest of opencode-linux-arm64.tar.gz for that release): a version with no checksum is not a pin"
|
|
fi
|
|
# A secondary run installs the lane it was started for, and nothing else.
|
|
if [ -n "$SECONDARY" ] && [ "$LANE" != "$SECONDARY" ]; then
|
|
die "internal error: a run for the $SECONDARY lane resolved the $LANE lane (MODEL_CHOICE=$MODEL_CHOICE). Please open an issue with this line."
|
|
fi
|
|
# The same refusal as the one near the top, once the lane is final: without
|
|
# MODEL_CHOICE that one reads LANE before the convergence has moved it to the
|
|
# installed flash lane, and step 6 then patched YaRN into the flash checkpoint's
|
|
# config.json in the shared HF cache (found in review, 2026-09-24).
|
|
if [ "$LANE" = "flash" ] && [ "$CONTEXT_MODE" = "1m" ]; then
|
|
printf 'ERROR: CONTEXT_MODE=1m is a 27B mode, and this box serves the flash lane. Flash-Next serves\n' >&2
|
|
printf ' its full native 262144 window. Drop CONTEXT_MODE, or pass a 27B MODEL_CHOICE with it.\n' >&2
|
|
exit 1
|
|
fi
|
|
# The default context mode, resolved here because everything it depends on (the
|
|
# lane, --no-service, and what the installed unit already says) is only known
|
|
# now. An explicit CONTEXT_MODE still refuses the combinations it cannot serve,
|
|
# a few lines below; a default must never refuse anything.
|
|
if [ -z "$CONTEXT_MODE" ]; then
|
|
if [ "$LANE" = "flash" ]; then
|
|
CONTEXT_MODE=native
|
|
elif [ "$NO_SERVICE" -eq 1 ]; then
|
|
CONTEXT_MODE=native
|
|
echo "--no-service installs the native 262144 window (1m needs the keepalive proxy service)."
|
|
else
|
|
CONTEXT_MODE=1m
|
|
echo "Context mode: 1m (1,010,000 tokens). Pass CONTEXT_MODE=native for the 262144 window."
|
|
fi
|
|
fi
|
|
|
|
if [ "$NO_COCKPIT" -eq 1 ] && [ "$WITH_COCKPIT" -eq 1 ]; then
|
|
printf -- '--no-cockpit and --with-cockpit contradict each other (drop one flag)\n' >&2; exit 1
|
|
fi
|
|
# The same for the image lane: both were taken, and --no-image won silently at the end of
|
|
# the install (found in review, 2026-09-24).
|
|
if [ "$NO_IMAGE" -eq 1 ] && [ "$WITH_IMAGE" -eq 1 ]; then
|
|
printf -- '--no-image and --with-image contradict each other (drop one flag)\n' >&2; exit 1
|
|
fi
|
|
# The same for the video lane and the two text lanes.
|
|
if [ "$NO_VIDEO" -eq 1 ] && [ "$WITH_VIDEO" -eq 1 ]; then
|
|
printf -- '--no-video and --with-video contradict each other (drop one flag)\n' >&2; exit 1
|
|
fi
|
|
if [ "$NO_FLASH" -eq 1 ] && [ "$WITH_FLASH" -eq 1 ]; then
|
|
printf -- '--no-flash and --with-flash contradict each other (drop one flag)\n' >&2; exit 1
|
|
fi
|
|
if [ "$NO_27B" -eq 1 ] && [ "$WITH_27B" -eq 1 ]; then
|
|
printf -- '--no-27b and --with-27b contradict each other (drop one flag)\n' >&2; exit 1
|
|
fi
|
|
if [ "$NO_KOLIBRI" -eq 1 ] && [ "$WITH_KOLIBRI" -eq 1 ]; then
|
|
printf -- '--no-kolibri and --with-kolibri contradict each other (drop one flag)\n' >&2; exit 1
|
|
fi
|
|
if [ "$NO_NEMOTRON" -eq 1 ] && [ "$WITH_NEMOTRON" -eq 1 ]; then
|
|
printf -- '--no-nemotron and --with-nemotron contradict each other (drop one flag)\n' >&2; exit 1
|
|
fi
|
|
if [ "$NO_NEMOTRON_SUPER" -eq 1 ] && [ "$WITH_NEMOTRON_SUPER" -eq 1 ]; then
|
|
printf -- '--no-nemotron-super and --with-nemotron-super contradict each other (drop one flag)\n' >&2; exit 1
|
|
fi
|
|
|
|
# --no-start and --no-service both return before the image step, so the flag would be
|
|
# accepted and silently do nothing. Say so here rather than at the end of a long install.
|
|
if [ "$WITH_IMAGE" -eq 1 ] && { [ "$NO_START" -eq 1 ] || [ "$NO_SERVICE" -eq 1 ]; }; then
|
|
printf -- '--with-image needs the full install: it installs a systemd unit and proves it serves.\n' >&2
|
|
printf -- 'Run ./install.sh without --no-start/--no-service, or ./install-image.sh on its own.\n' >&2
|
|
exit 1
|
|
fi
|
|
if [ "$WITH_VIDEO" -eq 1 ] && { [ "$NO_START" -eq 1 ] || [ "$NO_SERVICE" -eq 1 ]; }; then
|
|
printf -- '--with-video needs the full install: it installs a systemd unit and proves it serves.\n' >&2
|
|
printf -- 'Run ./install.sh without --no-start/--no-service, or ./install-video.sh on its own.\n' >&2
|
|
exit 1
|
|
fi
|
|
if [ "$WITH_KOLIBRI" -eq 1 ] && { [ "$NO_START" -eq 1 ] || [ "$NO_SERVICE" -eq 1 ]; }; then
|
|
printf -- '--with-kolibri needs the full install: it installs a systemd unit and proves it serves.\n' >&2
|
|
printf -- 'Run ./install.sh without --no-start/--no-service, or ./install-kolibri.sh on its own.\n' >&2
|
|
exit 1
|
|
fi
|
|
if [ "$WITH_NEMOTRON" -eq 1 ] && { [ "$NO_START" -eq 1 ] || [ "$NO_SERVICE" -eq 1 ]; }; then
|
|
printf -- '--with-nemotron needs the full install: it installs a systemd unit and proves it serves.\n' >&2
|
|
printf -- 'Run ./install.sh without --no-start/--no-service, or ./install-nemotron.sh on its own.\n' >&2
|
|
exit 1
|
|
fi
|
|
if [ "$WITH_NEMOTRON_SUPER" -eq 1 ] && { [ "$NO_START" -eq 1 ] || [ "$NO_SERVICE" -eq 1 ]; }; then
|
|
printf -- '--with-nemotron-super needs the full install: it installs a systemd unit and proves it serves.\n' >&2
|
|
printf -- 'Run ./install.sh without --no-start/--no-service, or ./install-nemotron-super.sh on its own.\n' >&2
|
|
exit 1
|
|
fi
|
|
# the same for the whole box: --no-service did none of it, --no-start the other text lane alone
|
|
# (found in review, 2026-10-15)
|
|
if [ "$ALL_WEIGHTS" -eq 1 ] && { [ "$NO_START" -eq 1 ] || [ "$NO_SERVICE" -eq 1 ]; }; then
|
|
printf -- '--all-weights needs the full install: it installs every lane whole and proves each it builds.\n' >&2
|
|
printf -- 'Run ./install.sh --all-weights without --no-start/--no-service.\n' >&2
|
|
exit 1
|
|
fi
|
|
# Since v1.12 the cockpit is part of a plain install: the one-liner has to leave
|
|
# a box you can open and drive, not a box plus a second command to find in a
|
|
# README. The choice persists exactly like the opencode one, in a marker file,
|
|
# so --no-cockpit is not quietly undone by the next upgrade.
|
|
CK_OFF_MARK="$CONFIG_DIR/cockpit.off"
|
|
COCKPIT=1
|
|
if [ "$NO_COCKPIT" -eq 1 ]; then
|
|
COCKPIT=0
|
|
mkdir -p "$CONFIG_DIR"
|
|
[ -f "$CK_OFF_MARK" ] || printf 'disabled with ./install.sh --no-cockpit on %s\n' "$(date -u +%Y-%m-%dT%H:%MZ)" > "$CK_OFF_MARK"
|
|
elif [ "$WITH_COCKPIT" -eq 1 ]; then
|
|
rm -f "$CK_OFF_MARK"
|
|
elif [ -f "$CK_OFF_MARK" ]; then
|
|
COCKPIT=0
|
|
echo "Keeping the cockpit off (your earlier --no-cockpit). Pass --with-cockpit to re-enable."
|
|
fi
|
|
# --no-service means no systemd at all, and the cockpit is a systemd unit.
|
|
[ "$NO_SERVICE" -eq 1 ] && COCKPIT=0
|
|
# Since v1.20 a plain run installs every lane: the text lane MODEL_CHOICE names serves,
|
|
# the other text lane is installed beside it, ready to load, and so are the image and
|
|
# the video lanes. Each one can be left out, and that choice persists like the
|
|
# cockpit's, in a marker file: --no-<lane> writes it, --with-<lane> removes it. A lane
|
|
# already on the box when it is left out stays where it is, and is no longer updated.
|
|
lane_wanted(){ # $1 lane (image, video, flash, 27b), $2 --no-$1 given, $3 --with-$1 given: sets WANT
|
|
local mark="$CONFIG_DIR/$1.off"
|
|
WANT=1
|
|
if [ "$2" -eq 1 ]; then
|
|
WANT=0
|
|
mkdir -p "$CONFIG_DIR"
|
|
[ -f "$mark" ] || printf 'left out with ./install.sh --no-%s on %s\n' "$1" "$(date -u +%Y-%m-%dT%H:%MZ)" > "$mark"
|
|
elif [ "$3" -eq 1 ]; then
|
|
rm -f "$mark"
|
|
elif [ -f "$mark" ]; then
|
|
WANT=0
|
|
echo "Leaving the $1 lane out (your earlier --no-$1). Pass --with-$1 to bring it back."
|
|
fi
|
|
}
|
|
WANT_IMAGE=0; WANT_VIDEO=0; WANT_FLASH=0; WANT_27B=0; WANT_KOLIBRI=0; WANT_NEMOTRON=0; WANT_NEMOTRON_SUPER=0
|
|
if [ -z "$SECONDARY" ]; then
|
|
lane_wanted image "$NO_IMAGE" "$WITH_IMAGE"; WANT_IMAGE="$WANT"
|
|
lane_wanted video "$NO_VIDEO" "$WITH_VIDEO"; WANT_VIDEO="$WANT"
|
|
lane_wanted flash "$NO_FLASH" "$WITH_FLASH"; WANT_FLASH="$WANT"
|
|
lane_wanted 27b "$NO_27B" "$WITH_27B"; WANT_27B="$WANT"
|
|
lane_wanted kolibri "$NO_KOLIBRI" "$WITH_KOLIBRI"; WANT_KOLIBRI="$WANT"
|
|
lane_wanted nemotron "$NO_NEMOTRON" "$WITH_NEMOTRON"; WANT_NEMOTRON="$WANT"
|
|
lane_wanted nemotron-super "$NO_NEMOTRON_SUPER" "$WITH_NEMOTRON_SUPER"; WANT_NEMOTRON_SUPER="$WANT"
|
|
fi
|
|
|
|
# The image, video, Kolibri and Nemotron lanes are installed on demand: a run puts in their units
|
|
# (--units-only, what needs root), and the cockpit's first Load of each builds its runtime
|
|
# as the user (--prepare) and fetches its weights (its switch). A lane already prepared
|
|
# (its runtime on the box, as on every box installed before this) is updated whole, as
|
|
# before; --all-weights, or a lane asked for by name (--with-<lane>), is installed whole now
|
|
# and proved when it is new. A lane counts as on the box once its runtime is begun: its venv
|
|
# for the image and video lanes, the image its unit names for Kolibri (tagged once built), and for
|
|
# a Nemotron lane that image with its own checkpoint (the image is the two lanes').
|
|
# The venv alone, not the note of its wheel: a lane installed whole before that note existed
|
|
# (v1.24.0 for the image lane, v1.25.0 for the video lane) has none and was given its units
|
|
# only, its runtime left as it was (found in review, 2026-10-15); a first Load that stopped
|
|
# on the way is finished by the update. The cockpit reads the note, which the installer writes
|
|
# once the whole runtime is in, to build what a Load needs first (dashboard/cockpit.py).
|
|
side_lane_dir(){ # $1 image|video: the folder its unit runs in
|
|
local unit="/etc/systemd/system/qwen38-$1.service" dir
|
|
dir="$({ grep -m1 -E '^WorkingDirectory=' "$unit" 2>/dev/null || true; } | cut -d= -f2-)"
|
|
echo "${dir:-$HOME/.local/share/qwen38-$1}"
|
|
}
|
|
side_kolibri_image(){
|
|
local img
|
|
img="$({ grep -m1 -oE 'qwen38-kolibri:[^ ]+' "$KOLIBRI_UNIT_PATH" 2>/dev/null || true; })"
|
|
[ -n "$img" ] && docker image inspect "$img" >/dev/null 2>&1
|
|
}
|
|
# A Nemotron lane is begun once its own first Load began: its image, and its own checkpoint in the
|
|
# cache its unit mounts. The two lanes run one image (install-nemotron-super.sh says why), built by
|
|
# either one's first Load, and the image alone called the other lane begun too: the next update
|
|
# installed that one whole, 77 GB of Super VL fetched on a box that had only loaded Bolt (found in
|
|
# review, 2026-10-16).
|
|
side_nemotron_begun(){ # $1 the lane's unit
|
|
local img repo hf
|
|
img="$({ grep -m1 -oE 'qwen38-nemotron:[^ ]+' "$1" 2>/dev/null || true; })"
|
|
{ [ -n "$img" ] && docker image inspect "$img" >/dev/null 2>&1; } || return 1
|
|
repo="$({ grep -m1 -oE '[^ ]+ --revision [0-9a-f]{40}' "$1" 2>/dev/null || true; } | cut -d' ' -f1)"
|
|
hf="$(unit_hf_cache "$1")"
|
|
[ -n "$repo" ] && [ -n "$hf" ] && [ -d "$hf/hub/models--${repo//\//--}" ]
|
|
}
|
|
side_begun(){ # $1 lane (image, video, kolibri, nemotron, nemotron-super)
|
|
case "$1" in
|
|
image|video) [ -x "$(side_lane_dir "$1")/venv/bin/python" ] ;;
|
|
kolibri) side_kolibri_image ;;
|
|
nemotron) side_nemotron_begun "$NEMOTRON_UNIT_PATH" ;;
|
|
nemotron-super) side_nemotron_begun "$NEMOTRON_SUPER_UNIT_PATH" ;;
|
|
*) return 1 ;;
|
|
esac
|
|
}
|
|
# The other text lane, installed beside the lane that serves, is on demand too: an update builds
|
|
# it whole only when it is installed as its launcher (flash) or unit (27B) names it, the image
|
|
# it runs on the box, the draft vocabulary the flash launcher waits for when it waits for one,
|
|
# the 27B's DFlash2 draft, and the checkpoint it serves whole in the cache it mounts (every box
|
|
# installed before this is). An update builds a lane whole on that target: the image alone read
|
|
# as prepared, and a first Load of flash-nvda stopped after its pull was finished on the default;
|
|
# with the vocabulary, a Load stopped before its switch (the page closed, then an update) still
|
|
# was, a checkpoint of 135 GB nobody chose, and a 27B Load of fp8 stopped in its download was
|
|
# finished on stock (found in review, 2026-10-15).
|
|
text_lane_prepared(){ # $1 flash|27b
|
|
local f img map model rev hf
|
|
if [ "$1" = flash ]; then f="$CONFIG_DIR/launch-flash.sh"; else f="$SGL_UNIT_PATH"; fi
|
|
img="$(engine_image "$f")"
|
|
if [ -z "$img" ] || ! docker image inspect "$img" >/dev/null 2>&1; then return 1; fi
|
|
if [ "$1" = flash ]; then
|
|
map="$({ grep -m1 -oE '\[ -s "[^"]+" \] && TIER\+=\(--speculative-token-map' "$f" 2>/dev/null || true; } | head -1 | cut -d'"' -f2)"
|
|
[ -z "$map" ] || [ -s "$map" ] || return 1
|
|
else
|
|
draft_in_cache "$f" || return 1
|
|
fi
|
|
model="$({ grep -m1 -oE -- '--model-path [^ ]+' "$f" 2>/dev/null || true; } | head -1 | cut -d' ' -f2)"
|
|
rev="$({ grep -m1 -oE -- '--revision [^ ]+' "$f" 2>/dev/null || true; } | head -1 | cut -d' ' -f2)"
|
|
hf="$(unit_hf_cache "$f")"
|
|
[ -n "$model" ] && ckpt_cached "${hf:-$HF_CACHE}/hub/models--${model//\//--}" "${rev:-main}"
|
|
}
|
|
side_mode(){ # $1 lane, $2 --with-<lane> given: the installer's option for this run
|
|
if [ "$ALL_WEIGHTS" -eq 1 ] || [ "$2" -eq 1 ] || side_begun "$1"; then echo --no-smoke; else echo --units-only; fi
|
|
}
|
|
|
|
if [ "$NO_SERVICE" -eq 1 ] && [ "$CONTEXT_MODE" = "1m" ]; then
|
|
if [ -z "$_ENV_CONTEXT_MODE" ]; then
|
|
# The 1m came from the installed unit, not from the operator: say so. The refusal
|
|
# named a CONTEXT_MODE nobody had set (found in review, 2026-09-24). It stays a
|
|
# refusal: a native --no-service install restores the configs that unit reads, and it
|
|
# would crash at its next start.
|
|
printf -- 'The installed 27B unit serves the 1M window, and --no-service installs the native 262144 one for\n./run.sh: the checkpoint configs would no longer match that unit, which would crash at its next start.\nDrop --no-service to update the service (it keeps 1m), or pass CONTEXT_MODE=native to move this box\nto native (then run a plain ./install.sh, so the unit follows).\n' >&2; exit 1
|
|
fi
|
|
printf -- 'CONTEXT_MODE=1m needs the systemd path (keepalive proxy service); ./run.sh serves the native config only.\nEither drop --no-service, or pass CONTEXT_MODE=native explicitly.\n' >&2; exit 1
|
|
fi
|
|
if [ "$NO_SERVICE" -eq 1 ] && [ "$LANE" = "flash" ]; then
|
|
printf -- 'The flash targets are service-only in this release (the lane was validated as a systemd unit).\nDrop --no-service, or install one of the 27B targets for the foreground ./run.sh path.\n' >&2; exit 1
|
|
fi
|
|
|
|
step() { printf '\n\033[1;36m── %s%s\033[0m\n' "${SECONDARY:+${SECONDARY/27b/27B} lane, }" "$*"; }
|
|
# True (0) when a service has to be restarted to run what is on disk: it is not running,
|
|
# or it started before the last change of one of the files it reads. The files are only
|
|
# rewritten when their content changes (cmp before install), so a date that moved is a
|
|
# change. A run that changed nothing restarted the proxy, cutting every request in flight
|
|
# through it, even with the engine kept (found in review, 2026-09-24).
|
|
# stale_since: in lanes.sh (sourced above), with the lanes' own freshness check
|
|
# (die() is defined above, before the port validations that call it first.)
|
|
|
|
step "1/10 Preflight checks"
|
|
[ "$(uname -m)" = "aarch64" ] || die "This setup targets GB10 (aarch64). Detected: $(uname -m)."
|
|
# These paths are written into the units and the flash launcher: inside a quoted
|
|
# `bash -c` line, in a docker `-v src:dst`, and in systemd's own syntax, where % is a
|
|
# specifier. A space, a colon, a quote, a $ or a % in one was accepted and broke the
|
|
# unit it went into, seen only when that failed to start (found in review, 2026-09-24).
|
|
for _p in "HOME=$HOME" "HF_CACHE=$HF_CACHE" "PLE_DIR=$PLE_DIR"; do
|
|
case "${_p#*=}" in
|
|
/*) case "${_p#*=}" in *[!A-Za-z0-9._/+@-]*) die "${_p%%=*}=${_p#*=}: the units this installs cannot carry that path. Use an absolute path of letters, digits and . _ / + @ - only." ;; esac ;;
|
|
*) die "${_p%%=*}=${_p#*=}: an absolute path is needed (the units carry it as it is)." ;;
|
|
esac
|
|
done
|
|
unset _p
|
|
command -v nvidia-smi >/dev/null || die "nvidia-smi not found. Is the NVIDIA driver stack installed? (stock on DGX OS)"
|
|
# nvidia-smi says what is wrong when it cannot reach the driver, and exits non-zero:
|
|
# inside a bare $(...) under set -e that ended the install with only "Install failed at
|
|
# line N", its own explanation captured into a variable nobody printed (found in review,
|
|
# 2026-09-24).
|
|
if ! GPU_OUT="$(nvidia-smi --query-gpu=name --format=csv,noheader 2>&1)"; then
|
|
die "nvidia-smi cannot reach the GPU: $(printf '%s' "$GPU_OUT" | tr '\n' ' ' | cut -c1-300). The NVIDIA driver is probably not loaded; after a kernel or driver update, a reboot loads it ('nvidia-smi' alone shows the same error)."
|
|
fi
|
|
GPU_NAME="$(printf '%s\n' "$GPU_OUT" | head -1)"
|
|
echo "GPU: $GPU_NAME"
|
|
case "$GPU_NAME" in *GB10*) ;; *) echo "WARNING: expected GB10, found '$GPU_NAME'. Continuing, but this config was only validated on GB10 (memory sizing may not fit other GPUs)." ;; esac
|
|
command -v docker >/dev/null || die "docker not found. Install Docker + NVIDIA Container Toolkit (stock on DGX OS)."
|
|
command -v python3 >/dev/null || die "python3 not found on the host (needed for the template patcher; stock on DGX OS)."
|
|
command -v ss >/dev/null || die "ss not found (iproute2, stock on DGX OS): the preflight cannot check the ports without it."
|
|
docker info >/dev/null 2>&1 || die "Cannot talk to the docker daemon. Fix: sudo usermod -aG docker \$USER && re-login (or run with a user in the docker group)."
|
|
# /proc/meminfo, not `free`: free(1) localizes its row labels (issue #3)
|
|
TOTAL_GB=$(awk '/^MemTotal/{print int($2/1048576)}' /proc/meminfo)
|
|
[ "$TOTAL_GB" -ge 110 ] || die "This config needs a ~121 GB unified-memory machine; found ${TOTAL_GB} GB."
|
|
# Measured where the weights actually land: HF_CACHE may live on another disk,
|
|
# and then free space under $HOME says nothing (the error message used to send
|
|
# people there while measuring here).
|
|
mkdir -p "$HF_CACHE" 2>/dev/null || true
|
|
# `|| true` inside: a df that fails (a path it cannot reach) under pipefail ended the
|
|
# install at this line, and the "found unknown GB" below never said why (found in review,
|
|
# 2026-09-24).
|
|
FREE_DISK_GB=$({ df -BG --output=avail "$HF_CACHE" 2>/dev/null || true; } | tail -1 | tr -dc '0-9')
|
|
# Fresh installs need ~45 GiB for the 27B stack (checkpoints + caches) and ~180 GiB for
|
|
# Flash-Next (its NVFP4 checkpoint alone is 136 GB), plus ~50 GiB for the flash lane's
|
|
# PLE table where PLE_DIR lands; what the cache already holds comes off (below). These
|
|
# checks count GiB, as df -BG does; the README's "Requirements" gives the same numbers in
|
|
# GB, rounded up (tests/test_docs_facts.py converts them): keep the two together.
|
|
# The room a pull takes at its peak, counted for both of Docker's image stores: the classic one
|
|
# keeps a layer's download until it is unpacked, the containerd one (the default of Docker 29
|
|
# on a new install) keeps every download beside what it unpacked. In GiB as df -BG rounds them
|
|
# up: ceil(peak x 1.02) + 1. Measured from the registry and on the reference box (2026-10-15):
|
|
# the 27B's image is 33.7 GB unpacked and 14.8 GB to download, 45.1 GiB at the peak; the flash
|
|
# lane's 34.4 GB and 15.3 GB, 46.3 GiB. It asked for 40 and 35, which a pull on a disk with just
|
|
# that free outgrew in either store (found in review, 2026-10-15).
|
|
NEED_GB=45; DOCKER_NEED_GB=48; IMG_LABEL="31 GB Docker image"
|
|
if [ "$LANE" = "flash" ]; then
|
|
NEED_GB=180; DOCKER_NEED_GB=49; IMG_LABEL="32 GB Docker image"
|
|
fi
|
|
# What is left to download, not what a checkpoint weighs. huggingface_hub creates the
|
|
# snapshot folder before the first byte of the first file (file_download.py, 1.31.0), so a
|
|
# folder there said nothing, and a flash download interrupted at 74 GB of 124 was checked
|
|
# against 10 on its resume (found in review, 2026-09-24). A snapshot is cached when every
|
|
# shard its index names is in it, since a file appears there only once its blob is whole;
|
|
# otherwise what the cache already holds for this repo comes off the need (lanes.sh ckpt_cached,
|
|
# which the switch and a first Load read through ckpt_room_gb).
|
|
HF_REPO_CACHE="$HF_CACHE/hub/models--${MODEL_REPO//\//--}"
|
|
if ckpt_cached "$HF_REPO_CACHE" "$MODEL_REV"; then
|
|
NEED_GB=10
|
|
else
|
|
HAVE_B="$({ du -s --apparent-size -B1 "$HF_REPO_CACHE/blobs" 2>/dev/null || true; } | cut -f1)"
|
|
NEED_GB=$((NEED_GB - ${HAVE_B:-0} / 1073741824)); [ "$NEED_GB" -ge 10 ] || NEED_GB=10 # floor: never under the need
|
|
fi
|
|
PLE_OWN_DEV=""
|
|
if [ "$LANE" = "flash" ] && [ "$UNITS_ONLY" -eq 0 ] && ! ls "$PLE_DIR"/ple_table_*.bin >/dev/null 2>&1; then
|
|
# The 47.7 GiB sparse backing file is written on every boot, in PLE_DIR; the space
|
|
# has to be there whether or not a previous boot left one behind, and on that disk:
|
|
# it was counted against HF_CACHE's, which says nothing when PLE_DIR is elsewhere.
|
|
PLE_PARENT="$PLE_DIR"; while [ ! -e "$PLE_PARENT" ]; do PLE_PARENT="$(dirname "$PLE_PARENT")"; done
|
|
if [ "$(stat -L -c %d "$PLE_PARENT")" = "$(stat -L -c %d "$HF_CACHE")" ]; then
|
|
NEED_GB=$((NEED_GB + 50))
|
|
else
|
|
PLE_OWN_DEV="$(stat -L -c %d "$PLE_PARENT")"
|
|
PLE_FREE_GB="$({ df -BG --output=avail "$PLE_PARENT" 2>/dev/null || true; } | tail -1 | tr -dc '0-9')"
|
|
[ -n "$PLE_FREE_GB" ] && [ "$PLE_FREE_GB" -ge 50 ] || die "Need ~50 GB free under PLE_DIR=$PLE_DIR for the flash lane's PLE table (47.7 GiB, written at every boot); found ${PLE_FREE_GB:-unknown} GB. Free some space or set PLE_DIR to another disk."
|
|
fi
|
|
fi
|
|
# A lane installed on demand takes no room now: its first Load checks the room for what it
|
|
# fetches (prepare-lane.sh, then its switch).
|
|
[ "$UNITS_ONLY" -eq 0 ] || NEED_GB=0
|
|
[ -n "$FREE_DISK_GB" ] && [ "$FREE_DISK_GB" -ge "$NEED_GB" ] || die "Need ~${NEED_GB} GB free for the checkpoints and caches under $HF_CACHE; found ${FREE_DISK_GB:-unknown} GB. Free some space or set HF_CACHE to another disk."
|
|
DOCKER_ROOT=$(docker info --format '{{.DockerRootDir}}' 2>/dev/null || echo /var/lib/docker)
|
|
DOCKER_FREE_GB=$({ df -BG --output=avail "$DOCKER_ROOT" 2>/dev/null || true; } | tail -1 | tr -dc '0-9')
|
|
# What step 2 pulls, decided here because the room it needs depends on it.
|
|
if [ "$LANE" = "flash" ]; then
|
|
PULL_TARGET="$FLASH_IMAGE"
|
|
else
|
|
PULL_TARGET="$IMAGE"
|
|
fi
|
|
# An image already here needs no room for itself, only the container's: an update
|
|
# on a box with 36 GB free was refused for want of 40, with the image in place and
|
|
# nothing to download (reference box, 2026-09-23).
|
|
if docker image inspect "$PULL_TARGET" >/dev/null 2>&1; then
|
|
DOCKER_NEED_GB=5; IMG_LABEL="container (its image is already here)"
|
|
fi
|
|
[ "$UNITS_ONLY" -eq 0 ] || DOCKER_NEED_GB=0
|
|
[ "${DOCKER_FREE_GB:-0}" -ge "$DOCKER_NEED_GB" ] || die "Need ~${DOCKER_NEED_GB} GB free on $DOCKER_ROOT for the $IMG_LABEL; found ${DOCKER_FREE_GB:-?} GB (docker images live there, not under \$HOME)."
|
|
# One disk for both, as on the reference box: the two needs add up there. Checked apart,
|
|
# 45 GB free passed a first 27B install that needs 45 for the checkpoints and 40 for the
|
|
# image on that same disk (found in review, 2026-09-24).
|
|
HF_DEV="$(stat -L -c %d "$HF_CACHE" 2>/dev/null || true)"; DOCKER_DEV="$(stat -L -c %d "$DOCKER_ROOT" 2>/dev/null || true)"
|
|
if [ -n "$HF_DEV" ] && [ "$HF_DEV" = "$DOCKER_DEV" ]; then
|
|
BOTH_GB=$((NEED_GB + DOCKER_NEED_GB))
|
|
[ "${FREE_DISK_GB:-0}" -ge "$BOTH_GB" ] || die "Need ~${BOTH_GB} GB free on the disk that holds both $HF_CACHE and $DOCKER_ROOT (${NEED_GB} for the checkpoints and caches, ${DOCKER_NEED_GB} for the $IMG_LABEL); found ${FREE_DISK_GB:-unknown} GB. Free some space, or set HF_CACHE to another disk."
|
|
fi
|
|
# The PLE table and the image on one disk that is not the cache's (the cache on a disk of its
|
|
# own): their needs add up there too. Checked apart, 60 GB free passed both (found in review,
|
|
# 2026-10-15).
|
|
if [ -n "$PLE_OWN_DEV" ] && [ "$PLE_OWN_DEV" = "$DOCKER_DEV" ]; then
|
|
PLE_BOTH_GB=$((50 + DOCKER_NEED_GB))
|
|
[ "${DOCKER_FREE_GB:-0}" -ge "$PLE_BOTH_GB" ] || die "Need ~${PLE_BOTH_GB} GB free on the disk that holds both PLE_DIR=$PLE_DIR and $DOCKER_ROOT (50 for the flash lane's PLE table, ${DOCKER_NEED_GB} for the $IMG_LABEL); found ${DOCKER_FREE_GB:-unknown} GB. Free some space or set PLE_DIR to another disk."
|
|
fi
|
|
# A secondary run shares the port with the lane its parent serves, which holds it by
|
|
# design: the parent checked both ports, and owns the proxy.
|
|
if [ -z "$SECONDARY" ] && ss -tlnH 2>/dev/null | awk '{print $4}' | grep -q ":$PORT\$"; then
|
|
# The port may be held by either of OUR engines: same-engine reinstall
|
|
# (converge) or a cross-engine switch (the old engine is stopped at step 9).
|
|
if docker inspect qwen38-sglang --format '{{join .Args " "}}' 2>/dev/null | grep -qE -- "--port ${PORT}(\s|$)"; then
|
|
echo "Note: qwen38-sglang is already running on :$PORT, installing over it ($([ "$LANE" = flash ] && echo 'lane switch at the final step' || echo 'converging config'))."
|
|
elif docker inspect qwen38-flash --format '{{join .Args " "}}' 2>/dev/null | grep -qE -- "--port ${PORT}(\s|$)" \
|
|
|| docker inspect qwen38-flash --format '{{json .HostConfig.PortBindings}}' 2>/dev/null | grep -q "\"${PORT}\""; then
|
|
echo "Note: qwen38-flash is already running on :$PORT, installing over it ($([ "$LANE" = 27b ] && echo 'lane switch at the final step' || echo 'converging config'))."
|
|
elif docker inspect qwen38-kolibri --format '{{join .Args " "}}' 2>/dev/null | grep -qE -- "--port ${PORT}(\s|$)"; then
|
|
echo "Note: the Kolibri lane is serving on :$PORT; this run updates the lanes beside it."
|
|
elif docker inspect qwen38-nemotron --format '{{join .Args " "}}' 2>/dev/null | grep -qE -- "--port ${PORT}(\s|$)"; then
|
|
echo "Note: the Nemotron lane is serving on :$PORT; this run updates the lanes beside it."
|
|
elif docker inspect qwen38-nemotron-super --format '{{join .Args " "}}' 2>/dev/null | grep -qE -- "--port ${PORT}(\s|$)"; then
|
|
echo "Note: the Nemotron Super lane is serving on :$PORT; this run updates the lanes beside it."
|
|
else
|
|
die "Port $PORT is already in use by another program (see: ss -tlnp | grep :$PORT). Free it, or install with PORT=<other> ./install.sh"
|
|
fi
|
|
fi
|
|
if [ -z "$SECONDARY" ] && [ "$NO_SERVICE" -eq 0 ] && ss -tlnH 2>/dev/null | awk '{print $4}' | grep -q ":$PROXY_PORT\$"; then
|
|
# Ours only if the proxy that runs is the one on that port: a running proxy made ANY
|
|
# busy PROXY_PORT pass, another program's included, which then kept the new unit from
|
|
# binding (found in review, 2026-09-24).
|
|
KA_PORT_NOW="$(grep -oE 'keepalive-proxy\.py [0-9]+' /etc/systemd/system/qwen38-keepalive.service 2>/dev/null | head -1 | tr -dc '0-9' || true)"
|
|
if [ "$KA_PORT_NOW" = "$PROXY_PORT" ] && systemctl is-active --quiet qwen38-keepalive 2>/dev/null; then
|
|
echo "Note: the keepalive proxy is already running on :$PROXY_PORT, re-installing over it."
|
|
else
|
|
die "Port $PROXY_PORT (keepalive proxy) is already in use by another program. Free it, or install with PROXY_PORT=<other>"
|
|
fi
|
|
fi
|
|
# sudo is needed from step 8 on, and it is asked for here, before the downloads rather
|
|
# than after them: `sudo -n` alone never prompts, and a fresh box where sudo wants a
|
|
# password (DGX OS does) died at step 8 after ~20 min of pulls (found in review,
|
|
# 2026-09-24). With a terminal sudo asks now; without one (a background run) `sudo -v`
|
|
# fails at once, and refusing now costs nothing where refusing at step 8 cost the pulls.
|
|
if [ "$NO_SERVICE" -eq 0 ] && ! sudo -n true 2>/dev/null; then
|
|
echo "sudo is needed from step 8 on (systemd units); it asks for your password now, before the downloads."
|
|
sudo -v || die "sudo could not be used here: run 'sudo -v' in this terminal, then re-run ./install.sh"
|
|
fi
|
|
echo "OK (aarch64, ${TOTAL_GB} GB RAM, ${FREE_DISK_GB} GB free)"
|
|
|
|
if [ "$UNITS_ONLY" -eq 1 ]; then
|
|
if [ "$LANE" = "flash" ]; then step "2/10 The Flash-Next image: pulled at the lane's first Load (~16 GB to download, 35 GB on disk)"
|
|
else step "2/10 The SGLang image: pulled at the lane's first Load (~15 GB to download)"; fi
|
|
PULLED_IMAGE="$PULL_TARGET"
|
|
elif [ "$LANE" = "flash" ]; then
|
|
step "2/10 Pulling the official SGLang Flash-Next image (~16 GB to download, 35 GB on disk, one-time, resumable)"
|
|
docker pull "$PULL_TARGET" || die "docker pull failed. Causes: no internet, Docker Hub rate limit (retry in a few minutes or 'docker login'), or the pinned digest was removed upstream: try FLASH_IMAGE=lmsysorg/sglang:dev-qwen38-next-local ./install.sh"
|
|
PULLED_IMAGE="$PULL_TARGET"
|
|
else
|
|
step "2/10 Pulling the SGLang image (~15 GB to download, 34 GB on disk, one-time, resumable)"
|
|
docker pull "$PULL_TARGET" || die "docker pull failed. Causes: no internet, Docker Hub rate limit (retry in a few minutes or 'docker login'), or the pinned digest was removed upstream: try IMAGE=lmsysorg/sglang:v0.5.21 ./install.sh, the moving tag of the same release"
|
|
PULLED_IMAGE="$PULL_TARGET"
|
|
fi
|
|
# pin_tag, the local tag a digest pull needs to survive a docker image prune: in lanes.sh
|
|
# (sourced above), which prepare-lane.sh shares for a lane prepared at its first Load.
|
|
# A pin that moves leaves its tag behind, and the tag keeps the retired image out of every
|
|
# prune: 30 to 39 GB per release that bumps a pin (found in review, 2026-09-24). Once the
|
|
# lane's current pin is here and tagged, the lane's other tags go, unless a container still
|
|
# uses their image; the image is then merely dangling, and the usual prune reclaims it.
|
|
unpin_stale() { # $1 lane, $2 the image the lane is pinned to now
|
|
local cur tag id
|
|
cur="$(docker image inspect "$2" --format '{{.Id}}' 2>/dev/null)" || return 0
|
|
docker images --no-trunc --format '{{.Repository}}:{{.Tag}} {{.ID}}' qwen38-pinned 2>/dev/null \
|
|
| while read -r tag id; do
|
|
case "$tag" in "qwen38-pinned:$1-"*) ;; *) continue ;; esac
|
|
if [ "$id" = "$cur" ] || [ -n "$(docker ps -aq --filter "ancestor=$id" 2>/dev/null)" ]; then
|
|
continue
|
|
fi
|
|
if docker rmi "$tag" >/dev/null 2>&1; then
|
|
echo "untagged $tag, a pin this release no longer uses: a docker image prune can reclaim it"
|
|
fi
|
|
done
|
|
}
|
|
pin_tag "$LANE" "$PULLED_IMAGE"
|
|
if [ "$LANE" = "flash" ]; then pin_tag 27b "$IMAGE"; else pin_tag flash "$FLASH_IMAGE"; fi
|
|
unpin_stale "$LANE" "$PULLED_IMAGE" || true
|
|
if [ "$LANE" = "flash" ]; then unpin_stale 27b "$IMAGE" || true; else unpin_stale flash "$FLASH_IMAGE" || true; fi
|
|
|
|
if [ "$UNITS_ONLY" -eq 1 ]; then
|
|
step "3/10 The GPU from a container: seen by the run that serves (this lane's image comes later)"
|
|
else
|
|
step "3/10 Verifying the container can see the GPU"
|
|
# --entrypoint: the image ships NVIDIA's own entrypoint script
|
|
# (/opt/nvidia/nvidia_entrypoint.sh), which prints a banner and runs its argument;
|
|
# overriding it is what makes this a plain nvidia-smi call with plain output.
|
|
GPU_SEEN="$(docker run --rm --gpus all --entrypoint nvidia-smi "$PULLED_IMAGE" -L 2>/dev/null | grep -m1 '^GPU' || true)"
|
|
[ -n "$GPU_SEEN" ] \
|
|
|| die "'docker run --gpus all' cannot see the GPU (no GPU line from nvidia-smi -L in the container). The NVIDIA Container Toolkit is missing or unconfigured. Fix: sudo nvidia-ctk runtime configure --runtime=docker && sudo systemctl restart docker"
|
|
echo "OK, container sees: $GPU_SEEN"
|
|
fi
|
|
|
|
if [ "$UNITS_ONLY" -eq 1 ]; then
|
|
if [ "$LANE" = "flash" ]; then step "4/10 The Flash-Next checkpoint: fetched at the lane's first Load (~136 GB)"
|
|
else step "4/10 The checkpoints (the target and its DFlash2 draft): fetched at the lane's first Load (~24 GB, ~33 for an FP8 target)"; fi
|
|
elif [ "$LANE" = "flash" ]; then
|
|
step "4/10 Downloading the Flash-Next checkpoint (~136 GB, one-time, reuses/resumes any local copy)"
|
|
echo "This is the big one: at 100 MB/s it takes ~25 min. Interrupting is safe, re-running resumes."
|
|
else
|
|
step "4/10 Downloading checkpoints (~24 GB, ~33 for an FP8 target, one-time, reuses/resumes any local copy)"
|
|
fi
|
|
mkdir -p "$HF_CACHE" "$CONFIG_DIR/sglang-cache"
|
|
# A kept custom model is already serving from this cache: skip its download.
|
|
DL_MODEL_REPO="$MODEL_REPO"
|
|
[ "$KEEP_MODEL_VERBATIM" -eq 1 ] && DL_MODEL_REPO=""
|
|
# Flash has no separate draft checkpoints: its MTP head ships inside the
|
|
# target checkpoint itself. Empty repo vars are skipped by the downloader.
|
|
DL_DRAFT2_REPO="$DRAFT2_REPO"
|
|
if [ "$LANE" = "flash" ]; then DL_DRAFT2_REPO=""; fi
|
|
# Unauthenticated downloads get throttled by the Hub (measured: a fresh-cache
|
|
# pull stalled at 3.3 GB). A token in $HF_CACHE/token is picked up through the
|
|
# mount; HF_TOKEN in the environment is passed through as well.
|
|
DL_TOKEN_ARGS=()
|
|
# by name: docker takes the value from its own environment, so the token is not in the
|
|
# docker client's argv, which any local user can read in /proc (found in review, 2026-09-24)
|
|
if [ -n "${HF_TOKEN:-}" ]; then export HF_TOKEN; DL_TOKEN_ARGS=(-e HF_TOKEN); fi
|
|
# HF_HUB_DISABLE_XET: the hub library's Xet transfer backend stalled silently
|
|
# during the release campaign (ESTAB socket, zero bytes, forever; 0-8 MB/s
|
|
# when moving at all) while the classic CDN path measured 89 MB/s on the same
|
|
# box, same second. HF_HUB_DOWNLOAD_TIMEOUT turns any remaining silent stall
|
|
# into a ReadTimeout that the retry loop below resumes from.
|
|
# ckpt-fetch.py, the one fetch of every lane's checkpoint, in the pinned image (resumed
|
|
# attempts, each keeping every file already whole; the Xet exception the flash checkpoint's
|
|
# 53.7 GB n-gram table needs; the byte count, when hf-progress.py is there to mount: a bind of
|
|
# a missing file makes docker create a root-owned directory in its place). A pinned-sha
|
|
# download writes no refs/main, and serving with HF_HUB_OFFLINE=1 (the 1m unit) resolves
|
|
# "main" through it and would fail on a fresh machine: --refs-main fill writes it where it is
|
|
# missing and never moves one the box serves.
|
|
[ -f "$REPO_DIR/ckpt-fetch.py" ] || die "ckpt-fetch.py is missing next to install.sh: run it from the repository."
|
|
DL_PROGRESS_ARGS=()
|
|
[ -f "$REPO_DIR/hf-progress.py" ] && DL_PROGRESS_ARGS=(-v "$REPO_DIR/hf-progress.py:/opt/qwen38/hf-progress.py:ro")
|
|
dl_fetch(){ # $1 repo, $2 revision; an empty repo is a kept custom model (already in cache) or flash's drafter (none)
|
|
[ -n "$1" ] || return 0
|
|
echo "── $1 @ $2"
|
|
docker run --rm --network host --user "$(id -u):$(id -g)" \
|
|
--entrypoint python3 \
|
|
-e HF_HOME=/hf -e HF_HUB_DOWNLOAD_TIMEOUT=30 -e HF_HUB_DISABLE_XET=1 \
|
|
"${DL_TOKEN_ARGS[@]}" "${DL_PROGRESS_ARGS[@]}" \
|
|
-v "$REPO_DIR/ckpt-fetch.py:/opt/qwen38/ckpt-fetch.py:ro" \
|
|
-v "$HF_CACHE":/hf \
|
|
"$PULLED_IMAGE" /opt/qwen38/ckpt-fetch.py "$1" "$2" --refs-main fill \
|
|
|| die "Checkpoint download failed. Causes: no internet, HuggingFace throttling of unauthenticated downloads (set HF_TOKEN=<your token>, or re-run: downloads resume), a pinned revision removed (try MODEL_REV=main DRAFT2_REV=main ./install.sh), or a permission error: if your $HF_CACHE contains root-owned files from other tools, fix with: sudo chown -R \$(id -u):\$(id -g) $HF_CACHE"
|
|
}
|
|
if [ "$UNITS_ONLY" -eq 1 ]; then
|
|
echo "no checkpoint now: the lane's first Load fetches it"
|
|
else
|
|
dl_fetch "$DL_MODEL_REPO" "$MODEL_REV"
|
|
dl_fetch "$DL_DRAFT2_REPO" "$DRAFT2_REV"
|
|
echo "checkpoints ready"
|
|
fi
|
|
|
|
# Say the image the unit will actually carry, not the pin it came from: those
|
|
# are the same thing on a default install and different the moment someone
|
|
# passes SERVE_IMAGE=, which is the one case where this line is the only
|
|
# on-screen confirmation that the override took.
|
|
LANE_SERVE_IMAGE="$([ "$LANE" = flash ] && echo "$FLASH_SERVE_IMAGE" || echo "$SERVE_IMAGE")"
|
|
LANE_PIN_IMAGE="$([ "$LANE" = flash ] && echo "$FLASH_IMAGE" || echo "$IMAGE")"
|
|
if [ "$LANE_SERVE_IMAGE" = "$LANE_PIN_IMAGE" ]; then
|
|
step "5/10 Serving image: the pinned official one, nothing to build"
|
|
echo "$LANE_SERVE_IMAGE"
|
|
else
|
|
step "5/10 Serving image: an operator override, nothing to build"
|
|
echo "$LANE_SERVE_IMAGE (SERVE_IMAGE=, instead of the pin $LANE_PIN_IMAGE)"
|
|
# Step 2 pulls the pin, never an override, and the overlay build that used to
|
|
# guarantee this tag existed is gone since v1.14. Without this check the
|
|
# install completes green, writes and enables the unit, and the engine then
|
|
# loops on an unpullable local tag for the full 20-minute health wait.
|
|
[ "$UNITS_ONLY" -eq 1 ] || docker image inspect "$LANE_SERVE_IMAGE" >/dev/null 2>&1 \
|
|
|| die "serving image not present: $LANE_SERVE_IMAGE. Nothing pulls an override, so build or pull it first, or drop SERVE_IMAGE= to serve the pin ($LANE_PIN_IMAGE)."
|
|
fi
|
|
|
|
# The reduced draft vocabulary (lanes.sh: flash_token_map says how and why).
|
|
if [ "$LANE" = "flash" ] && [ "${SPEC_TOKEN_MAP_SIZE:-0}" -gt 0 ] && [ "$UNITS_ONLY" -eq 0 ]; then
|
|
flash_token_map "$FLASH_IMAGE" "$HF_CACHE" "$MODEL_REPO" "$MODEL_REV" "$SPEC_TOKEN_MAP_SIZE" \
|
|
"Re-run ./install.sh after the checkpoint is in place to build and serve it." \
|
|
|| die "building the reduced draft vocabulary failed. It is an optimization, not a requirement: re-run with SPEC_TOKEN_MAP_SIZE=0 to serve without it, and please open an issue with the output above."
|
|
fi
|
|
|
|
# What the engine this run installs reads when it starts, as it stands before this run
|
|
# writes any of it, and whether the running engine already has exactly that. Step 9
|
|
# restarts the engine only when one of the two says otherwise: an update used to cost a
|
|
# full boot (8 min on the 27B, 12 on flash) even when it changed nothing the engine reads.
|
|
ENGINE_UNIT_PATH="$SGL_UNIT_PATH"; [ "$LANE" = "flash" ] && ENGINE_UNIT_PATH="$FLASH_UNIT_PATH"
|
|
ENGINE_CKPTS=("$MODEL_REPO@$MODEL_REV")
|
|
[ "$LANE" = "27b" ] && ENGINE_CKPTS+=("$DRAFT2_REPO@$DRAFT2_REV")
|
|
ENGINE_FP_BEFORE=""; ENGINE_RUNNING_IT="no: not installed yet"
|
|
if [ -f "$ENGINE_UNIT_PATH" ]; then
|
|
ENGINE_FP_BEFORE="$(python3 "$REPO_DIR/engine-inputs.py" fingerprint "$ENGINE_UNIT_PATH" "$CONFIG_DIR" "$HF_CACHE" "${ENGINE_CKPTS[@]}" 2>/dev/null || true)"
|
|
ENGINE_RUNNING_IT="$(python3 "$REPO_DIR/engine-inputs.py" running "$ENGINE_UNIT_PATH" "$CONFIG_DIR" "$HF_CACHE" "${ENGINE_CKPTS[@]}" 2>/dev/null || echo "no: could not tell")"
|
|
fi
|
|
|
|
step "6/10 API key + patched chat template"
|
|
if [ ! -s "$CONFIG_DIR/api-key" ]; then
|
|
# Subshell umask like install-agent.sh: with umask 022 the file would be
|
|
# born 644 and world-readable until the chmod below runs.
|
|
( umask 077 && head -c 24 /dev/urandom | base64 | tr -d '/+=' > "$CONFIG_DIR/api-key" ) \
|
|
|| die "could not write $CONFIG_DIR/api-key"
|
|
chmod 600 "$CONFIG_DIR/api-key"
|
|
echo "API key generated at $CONFIG_DIR/api-key"
|
|
else
|
|
echo "API key already present, keeping it"
|
|
fi
|
|
KEY="$(cat "$CONFIG_DIR/api-key")" # used by the step-9 smoke test
|
|
# The engine is handed its key in a file SGLang merges in memory, written by this script
|
|
# before every start (the units, the flash launcher, run.sh): as --api-key "$(cat ...)" it
|
|
# was in the argv of the docker client and of the server (found in review, 2026-09-24).
|
|
cmp -s "$REPO_DIR/engine-secrets.sh" "$CONFIG_DIR/engine-secrets.sh" \
|
|
|| install -m 755 "$REPO_DIR/engine-secrets.sh" "$CONFIG_DIR/engine-secrets.sh"
|
|
bash "$CONFIG_DIR/engine-secrets.sh" || die "could not write the engine's key file from $CONFIG_DIR/api-key (see above)"
|
|
# Every engine unit runs this before it starts (the last engine's GPU memory has to be back,
|
|
# see engine-preflight.sh), so it is in place before any unit that names it can start.
|
|
cmp -s "$REPO_DIR/engine-preflight.sh" "$CONFIG_DIR/engine-preflight.sh" \
|
|
|| install -m 755 "$REPO_DIR/engine-preflight.sh" "$CONFIG_DIR/engine-preflight.sh"
|
|
# One patched template per engine file name: the served template always follows
|
|
# the served model (both fixes: reasoning_effort normalization + mid-conversation
|
|
# system messages as <system-reminder> blocks; see patch-template.py).
|
|
TEMPLATE_OUT="$CONFIG_DIR/chat-template-sglang.jinja"
|
|
[ "$LANE" = "flash" ] && TEMPLATE_OUT="$CONFIG_DIR/chat-template-flashnext.jinja"
|
|
if [ "$KEEP_MODEL_VERBATIM" -eq 1 ]; then
|
|
[ -s "$TEMPLATE_OUT" ] \
|
|
|| die "custom model kept, but no patched template at $TEMPLATE_OUT. Pass MODEL_CHOICE=stock, uncensored, fp8 or uncensored-fp8 to regenerate it."
|
|
echo "custom target model kept: existing patched template left untouched"
|
|
elif [ "$UNITS_ONLY" -eq 1 ]; then
|
|
echo "the chat template comes from the checkpoint: the lane's first Load writes it (its switch)"
|
|
else
|
|
python3 "$REPO_DIR/patch-template.py" "$HF_CACHE" "$TEMPLATE_OUT" "$MODEL_REV" "$MODEL_REPO" \
|
|
|| die "Template patch failed (see message above). If the upstream template changed, please open an issue on this repo."
|
|
fi
|
|
# The checkpoint configs the context mode needs, YaRN patched in or restored. Written right
|
|
# before the unit that reads them, never at this step: a run that died between the two
|
|
# (the opencode download of step 7, a sudo that could no longer ask at step 8) left the
|
|
# installed unit of the old mode on configs of the new one, and a unit on configs of the
|
|
# other mode crashes at load, the next time systemd starts it (found in review,
|
|
# 2026-09-24). Called at step 8 just before the unit is installed, or at the end of step 7
|
|
# on a --no-service install, which writes no unit.
|
|
apply_context_configs(){
|
|
if [ "$UNITS_ONLY" -eq 1 ]; then
|
|
# no checkpoint yet: its preparation patches the draft's config, its switch the target's
|
|
[ "$LANE" = "27b" ] && echo "the checkpoints' configs for the $CONTEXT_MODE window: set at the lane's first Load"
|
|
return 0
|
|
fi
|
|
if [ "$CONTEXT_MODE" = "1m" ]; then
|
|
# Both configs must carry the YaRN patch (target AND draft, or the draft
|
|
# crashes at load). Idempotent; originals backed up as config.json.pre-yarn.
|
|
# A kept custom model has no known pin: its newest cached snapshot is patched.
|
|
if [ "$KEEP_MODEL_VERBATIM" -eq 1 ]; then
|
|
python3 "$REPO_DIR/patch-yarn.py" "$HF_CACHE" "$MODEL_REPO" || die "YaRN patch failed on the target model"
|
|
else
|
|
python3 "$REPO_DIR/patch-yarn.py" "$HF_CACHE" "$MODEL_REPO" "$MODEL_REV" || die "YaRN patch failed on the target model"
|
|
fi
|
|
python3 "$REPO_DIR/patch-yarn.py" "$HF_CACHE" "$DRAFT2_REPO" "$DRAFT2_REV" || die "YaRN patch failed on the DFlash2 draft"
|
|
else
|
|
# Coming home from 1m: a native server crashes at load on a YaRN-patched
|
|
# config (measured 2026-09-11: target context_length 1010000 against a
|
|
# derived 262144), so a native install restores the pre-YaRN originals.
|
|
# Refuses with a re-download fix-it when a config is patched but its backup
|
|
# is gone. Flash configs are never patched (1m is a 27B mode), so only the
|
|
# 27B lane restores.
|
|
#
|
|
# One combination leaves a box that boots into a crash, and it is quiet about
|
|
# it: --no-service returns at the end of step 7, so an installed 1m unit keeps
|
|
# asking for 1,010,000 from a config this restore just put back to 262,144,
|
|
# and the engine dies at load the next time systemd starts it. Seen here on
|
|
# 2026-09-18 while testing a native install against a 1m box's cache.
|
|
# ONLY --no-service. --no-start reaches step 8, renders the native template
|
|
# over that unit and enables it, so nothing is stranded there and warning
|
|
# about it would be a lie with two wrong remedies attached (caught in review
|
|
# the day this guard was written).
|
|
if [ "$LANE" = "27b" ] && [ "$NO_SERVICE" -eq 1 ] && [ -r "$SGL_UNIT_PATH" ]; then
|
|
_INSTALLED_CTX="$(grep -oE -- '--context-length [0-9]+' "$SGL_UNIT_PATH" 2>/dev/null | awk '{print $2}' | head -1 || true)"
|
|
if [ -n "$_INSTALLED_CTX" ] && [ "$_INSTALLED_CTX" -gt 262144 ]; then
|
|
echo "WARNING: the installed unit serves --context-length $_INSTALLED_CTX, and this native"
|
|
echo " install is about to restore the pre-YaRN configs it reads. --no-service writes"
|
|
echo " no unit, so that unit would crash at load the next time it starts."
|
|
echo " Either re-run without --no-service (the unit is rewritten native),"
|
|
echo " or put the box back with: CONTEXT_MODE=1m ./install.sh"
|
|
fi
|
|
fi
|
|
if [ "$LANE" = "27b" ]; then
|
|
if [ "$KEEP_MODEL_VERBATIM" -eq 1 ]; then
|
|
python3 "$REPO_DIR/patch-yarn.py" --restore "$HF_CACHE" "$MODEL_REPO" || die "YaRN restore failed on the kept model"
|
|
else
|
|
python3 "$REPO_DIR/patch-yarn.py" --restore "$HF_CACHE" "$MODEL_REPO" "$MODEL_REV" || die "YaRN restore failed on the target model"
|
|
fi
|
|
python3 "$REPO_DIR/patch-yarn.py" --restore "$HF_CACHE" "$DRAFT2_REPO" "$DRAFT2_REV" || die "YaRN restore failed on the DFlash2 draft"
|
|
fi
|
|
fi
|
|
}
|
|
|
|
|
|
# ── The other text lane, installed beside this one ─────────────────────────────
|
|
# Since v1.20 a run installs both text lanes: the one it serves, and the other one, ready
|
|
# to load from the cockpit. The other one is this same script, started again for that
|
|
# lane (QWEN38_SECONDARY above). Here, before step 7, so that opencode lists both lanes
|
|
# from the first run on. What is shared with the lane served here (the port, the HF
|
|
# cache, the binds) goes over explicitly; what belongs to one lane (its target, revision
|
|
# and context mode) does not: a MODEL_CHOICE given for this lane must not pick the other
|
|
# one's. A lane not installed yet gets its default target; one installed keeps its own.
|
|
SECOND_LANE=""; SECOND_UNIT=""; SECOND_FRESH=0; SECOND_NEW=0; SECOND_STATE=""; SECOND_UNITS=0
|
|
if [ -z "$SECONDARY" ] && [ "$NO_SERVICE" -eq 0 ]; then
|
|
if [ "$LANE" = "27b" ]; then
|
|
SECOND_LANE=flash; SECOND_UNIT=qwen38-flash.service; SECOND_WANT="$WANT_FLASH"; SECOND_TARGET=flash
|
|
else
|
|
SECOND_LANE=27b; SECOND_UNIT=qwen38-sglang.service; SECOND_WANT="$WANT_27B"; SECOND_TARGET=stock
|
|
fi
|
|
if [ "$SECOND_WANT" -eq 1 ]; then
|
|
[ -f "/etc/systemd/system/$SECOND_UNIT" ] || SECOND_FRESH=1
|
|
# new for the proofs at the end: no unit yet, or its units only (on demand, not prepared),
|
|
# which a run that builds it whole proves (--all-weights proved none of them, 2026-10-15)
|
|
SECOND_PREPARED=0; text_lane_prepared "$SECOND_LANE" && SECOND_PREPARED=1
|
|
SECOND_NEW="$SECOND_FRESH"; [ "$SECOND_PREPARED" -eq 1 ] || SECOND_NEW=1
|
|
step "The ${SECOND_LANE/27b/27B} lane, installed beside the ${LANE/27b/27B} lane (it serves when it is loaded)"
|
|
SECOND_ENV=()
|
|
[ "$SECOND_FRESH" -eq 1 ] && SECOND_ENV=(MODEL_CHOICE="$SECOND_TARGET")
|
|
# The other text lane on demand: its units only, unless it is prepared, asked for by name
|
|
# (--with-flash, --with-27b) or --all-weights; its first Load from the cockpit prepares it.
|
|
SECOND_UNITS=0
|
|
SECOND_NAMED="$WITH_FLASH"; [ "$SECOND_LANE" = 27b ] && SECOND_NAMED="$WITH_27B"
|
|
if [ "$ALL_WEIGHTS" -eq 0 ] && [ "$SECOND_NAMED" -eq 0 ] && [ "$SECOND_PREPARED" -eq 0 ]; then
|
|
SECOND_UNITS=1; SECOND_ENV+=(QWEN38_UNITS_ONLY=1)
|
|
fi
|
|
if env -u MODEL_CHOICE -u MODEL_REV -u CONTEXT_MODE -u RESTART_ENGINE \
|
|
QWEN38_SECONDARY="$SECOND_LANE" PORT="$PORT" HF_CACHE="$HF_CACHE" \
|
|
ENGINE_BIND="$ENGINE_BIND" PROXY_BIND="$PROXY_BIND" PROXY_PORT="$PROXY_PORT" \
|
|
${SECOND_ENV[@]+"${SECOND_ENV[@]}"} bash "$REPO_DIR/install.sh"; then
|
|
SECOND_STATE=installed; [ "$SECOND_UNITS" -eq 1 ] && SECOND_STATE=units
|
|
else
|
|
SECOND_STATE=failed
|
|
echo "NOTE: the ${SECOND_LANE/27b/27B} lane did not install (the lines above say why); the ${LANE/27b/27B} lane goes on."
|
|
fi
|
|
else
|
|
SECOND_STATE=off
|
|
fi
|
|
fi
|
|
|
|
if [ -n "$SECONDARY" ]; then
|
|
step "7/10 opencode: left to the run that serves, which lists this lane too"
|
|
elif [ "$OPENCODE" -eq 0 ]; then
|
|
step "7/10 opencode integration: off"
|
|
mkdir -p "$CONFIG_DIR"
|
|
[ -f "$OC_OFF_MARK" ] || printf 'disabled with ./install.sh --no-opencode on %s\n' "$(date -u +%Y-%m-%dT%H:%MZ)" > "$OC_OFF_MARK"
|
|
if grep -q 'dgx-spark-qwen38' "$HOME/.local/bin/oc" 2>/dev/null; then
|
|
rm -f "$HOME/.local/bin/oc"; echo "removed this repo's oc launcher"
|
|
fi
|
|
rm -f "$CONFIG_DIR/opencode.json"
|
|
echo "no generated config, no launcher; switch-model.sh leaves your opencode default model alone."
|
|
echo "Your own ~/.config/opencode/opencode.json is never touched either way. Re-enable: ./install.sh --with-opencode"
|
|
else
|
|
rm -f "$OC_OFF_MARK"
|
|
step "7/10 opencode provider config + oc launcher"
|
|
# What opencode-web reads, as it stands before this step writes any of it: the server is
|
|
# restarted at the end of the step only when one of them changed (see there). A file that
|
|
# is not there yet is part of the answer, not a failure: cat fails on a missing file, and
|
|
# under pipefail that failed the assignment, so set -e ended every first install here,
|
|
# where neither file exists yet (v1.18.7 on a box with nothing installed, 2026-09-30).
|
|
oc_configs_sum(){ { cat "$CONFIG_DIR/opencode.json" "$HOME/.config/opencode/opencode.json" 2>/dev/null || true; } | sha256sum; }
|
|
OC_SUM_BEFORE="$(oc_configs_sum)"
|
|
# ── opencode itself, at the pinned version (see the OPENCODE_VERSION pin) ─────────
|
|
# Absent: the release asset is downloaded, checked against its pinned sha256 and put
|
|
# where opencode's own installer puts it. Older in that place: replaced the same way.
|
|
# Older elsewhere (npm, brew, bun): opencode's own upgrader, which knows its method.
|
|
# Newer: kept, and said so, because going back a version can leave sessions a newer
|
|
# opencode wrote unreadable. None of it fails the install: opencode is one integration.
|
|
OC_HOME_BIN="$HOME/.opencode/bin/opencode"
|
|
OC_HOME_DIR="${OC_HOME_BIN%/opencode}"
|
|
oc_version(){ { "$1" --version 2>/dev/null || true; } | tail -1 | tr -d 'v[:space:]'; }
|
|
ver_lt(){ [ "$1" != "$2" ] && [ "$(printf '%s\n%s\n' "$1" "$2" | sort -V | head -1)" = "$1" ]; }
|
|
oc_fetch_pinned(){ # prints the cause of a failure; the caller says what it leaves behind
|
|
local tmp url="https://github.com/anomalyco/opencode/releases/download/v$OPENCODE_VERSION/opencode-linux-arm64.tar.gz"
|
|
tmp="$(mktemp -d)"
|
|
if ! curl -fsSL --retry 3 -m 600 -o "$tmp/oc.tar.gz" "$url"; then
|
|
rm -rf "$tmp"; echo "NOTE: could not download opencode $OPENCODE_VERSION ($url)"; return 1
|
|
fi
|
|
if ! printf '%s %s\n' "$OPENCODE_SHA256" "$tmp/oc.tar.gz" | sha256sum -c --quiet - >/dev/null 2>&1; then
|
|
rm -rf "$tmp"; echo "NOTE: the opencode $OPENCODE_VERSION download does not match its pinned sha256, so it was not installed"; return 1
|
|
fi
|
|
if ! tar -xzf "$tmp/oc.tar.gz" -C "$tmp" opencode; then
|
|
rm -rf "$tmp"; echo "NOTE: the opencode $OPENCODE_VERSION archive did not unpack"; return 1
|
|
fi
|
|
mkdir -p "$OC_HOME_DIR"
|
|
# a new file renamed over the old one: a server still running the old binary keeps it.
|
|
# Its failure is the function's: the rm after it made every run return 0, and a full
|
|
# disk read "installed" (found in review, 2026-09-24).
|
|
local placed=0
|
|
install -m 755 "$tmp/opencode" "$OC_HOME_BIN.new" && mv -f "$OC_HOME_BIN.new" "$OC_HOME_BIN" && placed=1
|
|
rm -rf "$tmp" "$OC_HOME_BIN.new"
|
|
[ "$placed" -eq 1 ] || { echo "NOTE: could not put opencode $OPENCODE_VERSION at $OC_HOME_BIN"; return 1; }
|
|
}
|
|
OC_FOUND="$(command -v opencode || true)"
|
|
OC_ON_PATH="$OC_FOUND" # what a shell of the user's finds, before the fallback below
|
|
[ -z "$OC_FOUND" ] && [ -x "$OC_HOME_BIN" ] && OC_FOUND="$OC_HOME_BIN"
|
|
OC_WAS_ABSENT=0; [ -z "$OC_FOUND" ] && OC_WAS_ABSENT=1
|
|
OC_HAVE=""; [ -n "$OC_FOUND" ] && OC_HAVE="$(oc_version "$OC_FOUND")"
|
|
if [ "$OPENCODE_PIN" != "1" ]; then
|
|
echo "opencode ${OC_HAVE:-not installed}: kept as it is (OPENCODE_PIN=$OPENCODE_PIN)"
|
|
elif [ "$OC_HAVE" = "$OPENCODE_VERSION" ]; then
|
|
echo "opencode $OC_HAVE: the version this repo tests"
|
|
elif [ -z "$OC_FOUND" ] || { [ "$OC_FOUND" -ef "$OC_HOME_BIN" ] && ver_lt "$OC_HAVE" "$OPENCODE_VERSION"; }; then
|
|
if [ -z "$OC_FOUND" ]; then
|
|
echo "opencode is not installed: installing $OPENCODE_VERSION (the release asset, checked against its pinned sha256)"
|
|
else
|
|
echo "opencode $OC_HAVE -> $OPENCODE_VERSION: replacing it with the release asset, checked against its pinned sha256"
|
|
fi
|
|
if oc_fetch_pinned; then
|
|
OC_FOUND="$OC_HOME_BIN"; OC_HAVE="$(oc_version "$OC_HOME_BIN")"
|
|
echo "opencode $OC_HAVE installed at $OC_HOME_BIN"
|
|
elif [ -z "$OC_FOUND" ]; then
|
|
echo " opencode is still not installed, and the Agent view and the oc launcher need it. Re-run ./install.sh"
|
|
echo " once GitHub is reachable, or install it from https://opencode.ai (this repo tests $OPENCODE_VERSION)."
|
|
else
|
|
echo " opencode stays at $OC_HAVE."
|
|
fi
|
|
elif ver_lt "$OC_HAVE" "$OPENCODE_VERSION"; then
|
|
echo "opencode $OC_HAVE -> $OPENCODE_VERSION through opencode's own upgrader ($OC_FOUND)"
|
|
"$OC_FOUND" upgrade "$OPENCODE_VERSION" </dev/null >/dev/null 2>&1 \
|
|
|| echo "NOTE: opencode upgrade $OPENCODE_VERSION failed; run it yourself"
|
|
OC_HAVE="$(oc_version "$OC_FOUND")"
|
|
else
|
|
echo "NOTE: opencode $OC_HAVE is newer than the $OPENCODE_VERSION this repo tests. Kept: going back"
|
|
echo " a version can leave sessions a newer opencode wrote unreadable. OPENCODE_PIN=0 silences this."
|
|
fi
|
|
if [ "$OPENCODE_PIN" = "1" ] && [ -n "$OC_HAVE" ] && ver_lt "$OC_HAVE" "$OPENCODE_VERSION"; then
|
|
echo "NOTE: opencode is still $OC_HAVE after the step above; oc and the Agent view keep running it"
|
|
fi
|
|
# The rest of this run (the Agent tab's unit, the oc launcher) finds opencode on PATH, and
|
|
# a first install puts it in the shell's PATH the way opencode's own installer does.
|
|
if [ -n "$OC_FOUND" ] && [ "$OC_FOUND" -ef "$OC_HOME_BIN" ]; then
|
|
case ":$PATH:" in *":$OC_HOME_DIR:"*) ;; *) export PATH="$OC_HOME_DIR:$PATH" ;; esac
|
|
# A shell the user opens later finds it only through a line: one this run installs,
|
|
# and one already here that is on no PATH (a v1.18.3 install skipped the line for a
|
|
# commented-out one, and an update never wrote it after). A commented-out line is no PATH.
|
|
if [ -z "$OC_ON_PATH" ] && ! grep -qsE '^[^#]*\.opencode/bin' "$HOME/.bashrc"; then
|
|
if [ "$OC_WAS_ABSENT" -eq 1 ]; then
|
|
printf '\n# opencode, installed by dgx-spark-qwen38 (%s)\nexport PATH="$HOME/.opencode/bin:$PATH"\n' "$OPENCODE_VERSION" >> "$HOME/.bashrc"
|
|
else
|
|
printf '\n# opencode, put on the PATH by dgx-spark-qwen38\nexport PATH="$HOME/.opencode/bin:$PATH"\n' >> "$HOME/.bashrc"
|
|
fi
|
|
echo "added ~/.opencode/bin to your PATH in ~/.bashrc (open a new shell, or: export PATH=\"\$HOME/.opencode/bin:\$PATH\")"
|
|
fi
|
|
fi
|
|
# A complete, ready-to-use opencode config (https://opencode.ai). The limits
|
|
# satisfy the serving window in BOTH modes, including when opencode's hidden
|
|
# 32000 output cap is lifted by the oc launcher below. The engine refuses any
|
|
# request whose prompt + max_tokens passes its window, and the prompt opencode
|
|
# sends can reach its compaction threshold plus one worst step (oc-limits.sh):
|
|
# native: 173000 - 20000 + 43863 + 64000 = 260863 <= 262144
|
|
# 1m: 700000 (compaction at 680000) + 200000 = 880000, against pools of
|
|
# 902,398 / 889,131 / 889,722 / 887,797 on v0.5.19 at 0.76 (2026-09-17
|
|
# and 18), a margin of 7,797 tokens over the worst; but the same image
|
|
# also booted to 854,123 and 873,429, and v0.5.21 to 872,414, 878,687
|
|
# and 877,859 (2026-10-09), where the pair does not fit. These
|
|
# static numbers are the starting point, not the contract: step 9
|
|
# runs oc-fit-limits.py against the pool the boot actually got and
|
|
# rewrites them (551,000 + 183,000 there). A box that skips that fit
|
|
# (--no-opencode, or the NOTE path when the engine is not up) keeps
|
|
# the static pair. The proxy does not refuse it: its guard is 92 % of
|
|
# the pool, and the largest prompt opencode sends with this pair, the
|
|
# compaction point plus one worst step (680,000 + 43,863 = 723,863),
|
|
# stays under it on every pool the lane booted to (832,993 the least). What
|
|
# does not fit is that prompt plus a whole answer: one that runs past
|
|
# about 109,000 tokens at the very end of a full session.
|
|
# Service installs point agent clients at the keepalive proxy (step 8): SGLang
|
|
# buffers tool-call arguments at any context length and agent CLIs abort
|
|
# silent streams. --no-service has no proxy: direct server port for ./run.sh.
|
|
# The key is referenced via {file:...}: no secret in the file.
|
|
# opencode limits per context mode: one table, in oc-limits.sh, because
|
|
# switch-model.sh has to write the same numbers and a second copy is how the two
|
|
# drift. See that script for why the numbers matter (a limit above what the lane
|
|
# serves turns a compaction into a 400 mid-session).
|
|
if [ "${LANE:-27b}" = "flash" ]; then
|
|
OC_SELECTOR="$FLASH_TIER"
|
|
else
|
|
OC_SELECTOR="$CONTEXT_MODE"
|
|
fi
|
|
# captured first: `read <<<"$(cmd)"` returns 0 whatever cmd returned, so this refusal
|
|
# never fired and a refused target died below under "returned no limits"
|
|
OC_ROW="$("$REPO_DIR/oc-limits.sh" "$MODEL_CHOICE" "$OC_SELECTOR")" \
|
|
|| die "oc-limits.sh refused MODEL_CHOICE=$MODEL_CHOICE with $OC_SELECTOR (repo bug: please open an issue)"
|
|
read -r OC_CTX OC_OUT OC_LABEL <<<"$OC_ROW"
|
|
[ -n "${OC_CTX:-}" ] && [ -n "${OC_OUT:-}" ] \
|
|
|| die "oc-limits.sh returned no limits for $MODEL_CHOICE/$OC_SELECTOR"
|
|
# The output CEILING is not this target's number: opencode sends
|
|
# max_tokens = min(limit.output, the ceiling), limit.output is what a switch
|
|
# rewrites, and a ceiling taken from the installed target survives the switch
|
|
# and cuts the next lane's turn in silence. So it is the table's maximum.
|
|
OC_OUT_CAP="$("$REPO_DIR/oc-limits.sh" --max-out)" \
|
|
|| die "oc-limits.sh --max-out failed (repo bug: please open an issue)"
|
|
[ "${OC_OUT_CAP:-0}" -ge "$OC_OUT" ] \
|
|
|| die "oc-limits.sh --max-out returned $OC_OUT_CAP, below this target's $OC_OUT"
|
|
OC_PORT="$PROXY_PORT"
|
|
[ "${NO_SERVICE:-0}" -eq 1 ] && OC_PORT="$PORT"
|
|
# end oc mode
|
|
# A provider appears in the picker only when its engine is installed on this
|
|
# box (nobody should be offered a model that nothing serves); the model being
|
|
# installed right now always appears. The default model is the one being
|
|
# installed. json.dump writes the file: no hand-escaping.
|
|
OC_27B=0; OC_FLASH=0; OC_KOLIBRI=0; OC_NEMOTRON=0; OC_NEMOTRON_SUPER=0
|
|
{ [ "$LANE" = "27b" ] || [ -f "$SGL_UNIT_PATH" ]; } && OC_27B=1
|
|
{ [ "$LANE" = "flash" ] || [ -f "$FLASH_UNIT_PATH" ]; } && OC_FLASH=1
|
|
# The Kolibri lane is installed at the end of a run (install-kolibri.sh): its provider comes
|
|
# with the first run that finds its unit, or with the first switch to it.
|
|
[ -f "$KOLIBRI_UNIT_PATH" ] && OC_KOLIBRI=1
|
|
OC_KOLIBRI_CTX=""; OC_KOLIBRI_OUT=""; OC_KOLIBRI_NAME=""
|
|
if [ "$OC_KOLIBRI" -eq 1 ]; then
|
|
OC_KOLIBRI_TARGET=kolibri
|
|
# the NVFP4 checkpoint as install-kolibri.sh pins it (it was written here a second time)
|
|
OC_KOLIBRI_NVFP4="$(sed -n 's/^KOLIBRI_NVFP4_REPO="\([^"]*\)"$/\1/p' "$REPO_DIR/install-kolibri.sh")"
|
|
[ -n "$OC_KOLIBRI_NVFP4" ] && grep -qs -- "$OC_KOLIBRI_NVFP4 --revision" "$KOLIBRI_UNIT_PATH" && OC_KOLIBRI_TARGET=kolibri-nvfp4
|
|
OC_KOLIBRI_PAIR="$("$REPO_DIR/oc-limits.sh" "$OC_KOLIBRI_TARGET")" \
|
|
|| die "oc-limits.sh refused $OC_KOLIBRI_TARGET (repo bug: please open an issue)"
|
|
OC_KOLIBRI_CTX="${OC_KOLIBRI_PAIR%% *}"; OC_KOLIBRI_OUT="$(echo "$OC_KOLIBRI_PAIR" | cut -d' ' -f2)"
|
|
OC_KOLIBRI_NAME="$(python3 "$REPO_DIR/oc-point-default.py" --label "$OC_KOLIBRI_TARGET" 262144 || true)"
|
|
fi
|
|
# The Nemotron lane, the same way: one checkpoint today, its provider with its unit.
|
|
[ -f "$NEMOTRON_UNIT_PATH" ] && OC_NEMOTRON=1
|
|
OC_NEMOTRON_CTX=""; OC_NEMOTRON_OUT=""; OC_NEMOTRON_NAME=""
|
|
if [ "$OC_NEMOTRON" -eq 1 ]; then
|
|
OC_NEMOTRON_PAIR="$("$REPO_DIR/oc-limits.sh" nemotron)" \
|
|
|| die "oc-limits.sh refused nemotron (repo bug: please open an issue)"
|
|
OC_NEMOTRON_CTX="${OC_NEMOTRON_PAIR%% *}"; OC_NEMOTRON_OUT="$(echo "$OC_NEMOTRON_PAIR" | cut -d' ' -f2)"
|
|
OC_NEMOTRON_NAME="$(python3 "$REPO_DIR/oc-point-default.py" --label nemotron 262144 || true)"
|
|
fi
|
|
# The Nemotron Super lane, its own provider (its own model and window) with its unit.
|
|
[ -f "$NEMOTRON_SUPER_UNIT_PATH" ] && OC_NEMOTRON_SUPER=1
|
|
OC_NEMOTRON_SUPER_CTX=""; OC_NEMOTRON_SUPER_OUT=""; OC_NEMOTRON_SUPER_NAME=""
|
|
if [ "$OC_NEMOTRON_SUPER" -eq 1 ]; then
|
|
OC_NEMOTRON_SUPER_PAIR="$("$REPO_DIR/oc-limits.sh" nemotron-super)" \
|
|
|| die "oc-limits.sh refused nemotron-super (repo bug: please open an issue)"
|
|
OC_NEMOTRON_SUPER_CTX="${OC_NEMOTRON_SUPER_PAIR%% *}"; OC_NEMOTRON_SUPER_OUT="$(echo "$OC_NEMOTRON_SUPER_PAIR" | cut -d' ' -f2)"
|
|
OC_NEMOTRON_SUPER_NAME="$(python3 "$REPO_DIR/oc-point-default.py" --label nemotron-super 1048576 || true)"
|
|
fi
|
|
# How much of a conversation survives a compaction verbatim, from the same table.
|
|
OC_KEEP="$("$REPO_DIR/oc-limits.sh" --preserve "$OC_CTX")" \
|
|
|| die "oc-limits.sh --preserve failed for $OC_CTX (repo bug: please open an issue)"
|
|
# On 1m the table gives bounds and the fit to the pool sets the pair (fitted() below and
|
|
# --keep-lower), so the compaction goes with the fitted pair too: sized from the bound here,
|
|
# it was set back at every run and the fit at the end set it again, two writes, two backups
|
|
# and two opencode-web restarts per update (seen on the reference box, 2026-09-25).
|
|
if [ "$CONTEXT_MODE" = "1m" ] && [ "$LANE" != "flash" ]; then
|
|
OC_FIT_CTX="$(python3 - "$CONFIG_DIR/opencode.json" "$OC_CTX" "$OC_OUT" <<'PY' 2>/dev/null || true
|
|
import json, sys
|
|
try:
|
|
lim = json.load(open(sys.argv[1]))["provider"]["qwen38"]["models"]["qwen3.8-27b"]["limit"]
|
|
c, o = int(lim["context"]), int(lim["output"])
|
|
if 0 < c <= int(sys.argv[2]) and 0 < o <= int(sys.argv[3]):
|
|
print(c)
|
|
except Exception:
|
|
pass
|
|
PY
|
|
)"
|
|
if [ -n "$OC_FIT_CTX" ]; then
|
|
OC_KEEP="$("$REPO_DIR/oc-limits.sh" --preserve "$OC_FIT_CTX")" \
|
|
|| die "oc-limits.sh --preserve failed for $OC_FIT_CTX (repo bug: please open an issue)"
|
|
fi
|
|
fi
|
|
# The Kolibri lane serving at boot: opencode's default is Kolibri (OC_POINT_* below), and the
|
|
# compaction block, global, goes with the default's window, as a switch to it sizes it. Sized
|
|
# from the Qwen lane, a 27B in 1M mode kept 132,000 verbatim against Kolibri's threshold of
|
|
# 185,000 (153,000 when this was found), and opencode compacted again every step or two (found in
|
|
# review, 2026-10-14).
|
|
if [ "$KOLIBRI_BOOT" -eq 1 ] && [ "$OC_KOLIBRI" -eq 1 ] && [ -n "$OC_KOLIBRI_CTX" ]; then
|
|
OC_KEEP="$("$REPO_DIR/oc-limits.sh" --preserve "$OC_KOLIBRI_CTX")" \
|
|
|| die "oc-limits.sh --preserve failed for $OC_KOLIBRI_CTX (repo bug: please open an issue)"
|
|
fi
|
|
if [ "$NEMOTRON_BOOT" -eq 1 ] && [ "$OC_NEMOTRON" -eq 1 ] && [ -n "$OC_NEMOTRON_CTX" ]; then
|
|
OC_KEEP="$("$REPO_DIR/oc-limits.sh" --preserve "$OC_NEMOTRON_CTX")" \
|
|
|| die "oc-limits.sh --preserve failed for $OC_NEMOTRON_CTX (repo bug: please open an issue)"
|
|
fi
|
|
if [ "$NEMOTRON_SUPER_BOOT" -eq 1 ] && [ "$OC_NEMOTRON_SUPER" -eq 1 ] && [ -n "$OC_NEMOTRON_SUPER_CTX" ]; then
|
|
OC_KEEP="$("$REPO_DIR/oc-limits.sh" --preserve "$OC_NEMOTRON_SUPER_CTX")" \
|
|
|| die "oc-limits.sh --preserve failed for $OC_NEMOTRON_SUPER_CTX (repo bug: please open an issue)"
|
|
fi
|
|
# The other engine's limits, for when both providers are present: the 27B block
|
|
# keeps its context-mode limits, flash always serves its native window. A flash install
|
|
# runs in native mode, so the 27B's own mode comes from its unit: taken from this run, a
|
|
# 1M 27B got the native 194048/64000, which oc and the Agent tab read first since they
|
|
# load this file over the user's (reference box, 2026-09-23).
|
|
OC_27B_MODE="$CONTEXT_MODE"
|
|
if [ "$LANE" = "flash" ]; then
|
|
OC_27B_MODE=native
|
|
if grep -qs -- '--context-length 1010000' "$SGL_UNIT_PATH"; then OC_27B_MODE=1m; fi
|
|
fi
|
|
# Its pair comes from the same table, for the checkpoint that unit serves: FP8 has its
|
|
# own 1M pair, and a copy of the numbers here had drifted from the table (it gave an FP8
|
|
# box 700000/200000; found in review, 2026-09-24).
|
|
OC_27B_CHOICE=stock
|
|
case "$(grep -oE -- '--model-path [^ ]+' "$SGL_UNIT_PATH" 2>/dev/null | head -1 | cut -d' ' -f2 || true)" in
|
|
"$FP8_REPO"|"$UNCFP8_REPO") OC_27B_CHOICE=fp8 ;;
|
|
esac
|
|
OC_27B_PAIR="$("$REPO_DIR/oc-limits.sh" "$OC_27B_CHOICE" "$OC_27B_MODE")" \
|
|
|| die "oc-limits.sh refused $OC_27B_CHOICE/$OC_27B_MODE (repo bug: please open an issue)"
|
|
OC_27B_CTX="${OC_27B_PAIR%% *}"; OC_27B_OUT="$(echo "$OC_27B_PAIR" | cut -d' ' -f2)"
|
|
# The lane that is not being installed keeps the name of the checkpoint its unit serves,
|
|
# from the same table as the served one. A flash install wrote the 27B entry a generic
|
|
# name, the next switch back renamed it, so the first update after every switch rewrote
|
|
# the file and restarted opencode-web for a name (the reference box, 2026-09-30).
|
|
OC_27B_TARGET=stock
|
|
case "$(grep -oE -- '--model-path [^ ]+' "$SGL_UNIT_PATH" 2>/dev/null | head -1 | cut -d' ' -f2 || true)" in
|
|
"$UNC_REPO") OC_27B_TARGET=uncensored ;;
|
|
"$FP8_REPO") OC_27B_TARGET=fp8 ;;
|
|
"$UNCFP8_REPO") OC_27B_TARGET=uncensored-fp8 ;;
|
|
esac
|
|
OC_27B_WINDOW=262144; [ "$OC_27B_MODE" = "1m" ] && OC_27B_WINDOW=1010000
|
|
OC_27B_NAME="$(python3 "$REPO_DIR/oc-point-default.py" --label "$OC_27B_TARGET" "$OC_27B_WINDOW" || true)"
|
|
OC_FLASH_TARGET=flash
|
|
case "$(grep -oE -- '--model-path [^ ]+' "$CONFIG_DIR/launch-flash.sh" 2>/dev/null | head -1 | cut -d' ' -f2 || true)" in
|
|
"$FLASH_UNC_REPO") OC_FLASH_TARGET=flash-uncensored ;;
|
|
"$FLASH_NVDA_REPO") OC_FLASH_TARGET=flash-nvda ;;
|
|
esac
|
|
OC_FLASH_NAME="$(python3 "$REPO_DIR/oc-point-default.py" --label "$OC_FLASH_TARGET" 262144 || true)"
|
|
# Its pair from the same table, for the tier its launcher runs, as the 27B's above. A copy
|
|
# here, 110000/32000 (the throughput tier's), cut the 205,000 window of the concurrency and
|
|
# context tiers to 110,000 at every run that served the 27B (the reference box, 2026-10-06).
|
|
OC_FLASH_CTX=""; OC_FLASH_OUT=""
|
|
if [ "$OC_FLASH" -eq 1 ] && [ "$LANE" != "flash" ]; then
|
|
OC_FLASH_PAIR="$("$REPO_DIR/oc-limits.sh" "$OC_FLASH_TARGET" --from "$CONFIG_DIR/launch-flash.sh")" \
|
|
|| die "oc-limits.sh refused $OC_FLASH_TARGET (repo bug: please open an issue)"
|
|
OC_FLASH_CTX="${OC_FLASH_PAIR%% *}"; OC_FLASH_OUT="$(echo "$OC_FLASH_PAIR" | cut -d' ' -f2)"
|
|
fi
|
|
# The served entry's name comes from the table oc-point-default.py applies below. The
|
|
# generator wrote a generic one that the call below then renamed, so the file was written
|
|
# twice at every run, and the rename now leaves a backup (found in review, 2026-09-24).
|
|
OC_WINDOW=262144; [ "$CONTEXT_MODE" = "1m" ] && OC_WINDOW=1010000
|
|
OC_SERVED_NAME="$(python3 "$REPO_DIR/oc-point-default.py" --label "$MODEL_CHOICE" "$OC_WINDOW")" \
|
|
|| die "oc-point-default.py --label failed (repo bug: please open an issue)"
|
|
OC_LANE="$LANE" OC_27B="$OC_27B" OC_FLASH="$OC_FLASH" OC_PORT="$OC_PORT" \
|
|
OC_CTX="$OC_CTX" OC_OUT="$OC_OUT" OC_LABEL="$OC_LABEL" OC_CONTEXT_MODE="$OC_27B_MODE" \
|
|
OC_27B_CTX="$OC_27B_CTX" OC_27B_OUT="$OC_27B_OUT" OC_SERVED_NAME="$OC_SERVED_NAME" \
|
|
OC_27B_NAME="$OC_27B_NAME" OC_FLASH_NAME="$OC_FLASH_NAME" \
|
|
OC_FLASH_CTX="$OC_FLASH_CTX" OC_FLASH_OUT="$OC_FLASH_OUT" \
|
|
OC_KOLIBRI="$OC_KOLIBRI" OC_KOLIBRI_CTX="$OC_KOLIBRI_CTX" OC_KOLIBRI_OUT="$OC_KOLIBRI_OUT" \
|
|
OC_KOLIBRI_NAME="$OC_KOLIBRI_NAME" OC_KOLIBRI_BOOT="$KOLIBRI_BOOT" OC_REPO_DIR="$REPO_DIR" \
|
|
OC_NEMOTRON="$OC_NEMOTRON" OC_NEMOTRON_CTX="$OC_NEMOTRON_CTX" OC_NEMOTRON_OUT="$OC_NEMOTRON_OUT" \
|
|
OC_NEMOTRON_NAME="$OC_NEMOTRON_NAME" OC_NEMOTRON_BOOT="$NEMOTRON_BOOT" \
|
|
OC_NEMOTRON_SUPER="$OC_NEMOTRON_SUPER" OC_NEMOTRON_SUPER_CTX="$OC_NEMOTRON_SUPER_CTX" OC_NEMOTRON_SUPER_OUT="$OC_NEMOTRON_SUPER_OUT" \
|
|
OC_NEMOTRON_SUPER_NAME="$OC_NEMOTRON_SUPER_NAME" OC_NEMOTRON_SUPER_BOOT="$NEMOTRON_SUPER_BOOT" \
|
|
OC_KEEP="$OC_KEEP" OC_PIN="$OPENCODE_PIN" \
|
|
OC_CONFIG_DIR="$CONFIG_DIR" python3 - <<'PYEOF' || die "could not write the opencode provider config"
|
|
import json
|
|
import os
|
|
|
|
cfg_dir = os.environ["OC_CONFIG_DIR"]
|
|
lane = os.environ["OC_LANE"]
|
|
# "lean" first: it is the level the patched template defaults to, so a picker
|
|
# that lists it first shows the level a client gets when it selects nothing.
|
|
# The three Qwen levels stay, unchanged, for anyone who wants them by name.
|
|
variants = {lvl: {"chat_template_kwargs": {"reasoning_effort": lvl}}
|
|
for lvl in ("lean", "low", "medium", "xhigh")}
|
|
key_ref = f"{{file:{cfg_dir}/api-key}}"
|
|
base_url = f"http://127.0.0.1:{os.environ['OC_PORT']}/v1"
|
|
# the name oc-point-default.py gives the served lane's entry, empty for a target it has none for
|
|
served_name = os.environ.get("OC_SERVED_NAME", "")
|
|
|
|
def prov(name, model_id, model_name, ctx, out):
|
|
return {
|
|
"npm": "@ai-sdk/openai-compatible",
|
|
"name": name,
|
|
"options": {"baseURL": base_url, "apiKey": key_ref},
|
|
"models": {model_id: {
|
|
"name": model_name,
|
|
"limit": {"context": ctx, "input": ctx, "output": out},
|
|
"variants": variants,
|
|
"attachment": True,
|
|
"modalities": {"input": ["text", "image"], "output": ["text"]},
|
|
}},
|
|
}
|
|
|
|
def fitted(provider, model_id, bound_ctx, bound_out):
|
|
"""The pair a fit to the engine's pool left here under the table's 1m bounds, if any.
|
|
On a 1m box the table only gives bounds and the fit (end of the install, or the
|
|
cockpit) sets the pair: writing the bounds over it made every 1m run write twice, the
|
|
bounds here and the fit at the end, with an opencode restart for each (found in
|
|
review, 2026-09-24)."""
|
|
try:
|
|
with open(f"{cfg_dir}/opencode.json") as f:
|
|
lim = json.load(f)["provider"][provider]["models"][model_id]["limit"]
|
|
c, o = int(lim["context"]), int(lim["output"])
|
|
except Exception:
|
|
return None
|
|
return (c, o) if 0 < c <= bound_ctx and 0 < o <= bound_out else None
|
|
|
|
providers = {}
|
|
if os.environ["OC_27B"] == "1":
|
|
if lane == "27b":
|
|
ctx, out, label = int(os.environ["OC_CTX"]), int(os.environ["OC_OUT"]), os.environ["OC_LABEL"]
|
|
else: # flash install on a box that also has the 27B unit: keep its own limits
|
|
ctx, out = int(os.environ["OC_27B_CTX"]), int(os.environ["OC_27B_OUT"])
|
|
label = "local, 1M" if os.environ["OC_CONTEXT_MODE"] == "1m" else "local"
|
|
if os.environ["OC_CONTEXT_MODE"] == "1m":
|
|
ctx, out = fitted("qwen38", "qwen3.8-27b", ctx, out) or (ctx, out)
|
|
providers["qwen38"] = prov("Qwen3.8-27B (DGX Spark)", "qwen3.8-27b",
|
|
lane == "27b" and served_name or os.environ.get("OC_27B_NAME")
|
|
or f"Qwen3.8-27B NVFP4+DFlash2 ({label})",
|
|
ctx, out)
|
|
if os.environ["OC_FLASH"] == "1":
|
|
# the flash lane's limits follow the pool math above (OC_CTX/OC_OUT); a 27B
|
|
# install that also lists flash takes the table's pair for the tier its launcher runs
|
|
fctx, fout = ((int(os.environ["OC_CTX"]), int(os.environ["OC_OUT"])) if lane == "flash"
|
|
else (int(os.environ["OC_FLASH_CTX"]), int(os.environ["OC_FLASH_OUT"])))
|
|
providers["flashnext"] = prov("Qwen3.8-Flash-Next (DGX Spark)", "qwen3.8-flash-next",
|
|
lane == "flash" and served_name or os.environ.get("OC_FLASH_NAME")
|
|
or "Qwen3.8-Flash-Next NVFP4+MTP (local, 262K)",
|
|
fctx, fout)
|
|
if os.environ.get("OC_KOLIBRI") == "1":
|
|
# one definition, shared with switch-model.sh (oc-kolibri.py says why)
|
|
import importlib.util
|
|
spec = importlib.util.spec_from_file_location("oc_kolibri", os.path.join(os.environ["OC_REPO_DIR"], "oc-kolibri.py"))
|
|
ock = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(ock)
|
|
providers["kolibri"] = ock.provider(base_url, f"{cfg_dir}/api-key",
|
|
int(os.environ["OC_KOLIBRI_CTX"]), int(os.environ["OC_KOLIBRI_OUT"]),
|
|
os.environ.get("OC_KOLIBRI_NAME") or "Kolibri-1 FP8 official (local, 262K)")
|
|
if os.environ.get("OC_NEMOTRON") == "1":
|
|
# one definition, shared with switch-model.sh (oc-nemotron.py says why)
|
|
import importlib.util
|
|
spec = importlib.util.spec_from_file_location("oc_nemotron", os.path.join(os.environ["OC_REPO_DIR"], "oc-nemotron.py"))
|
|
ocn = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(ocn)
|
|
providers["nemotron"] = ocn.provider(base_url, f"{cfg_dir}/api-key",
|
|
int(os.environ["OC_NEMOTRON_CTX"]), int(os.environ["OC_NEMOTRON_OUT"]),
|
|
os.environ.get("OC_NEMOTRON_NAME") or "Nemotron 3.5 Bolt (local, 262K)")
|
|
if os.environ.get("OC_NEMOTRON_SUPER") == "1":
|
|
import importlib.util
|
|
spec = importlib.util.spec_from_file_location("oc_nemotron", os.path.join(os.environ["OC_REPO_DIR"], "oc-nemotron.py"))
|
|
ocn = importlib.util.module_from_spec(spec)
|
|
spec.loader.exec_module(ocn)
|
|
providers["nemotron-super"] = ocn.provider(base_url, f"{cfg_dir}/api-key",
|
|
int(os.environ["OC_NEMOTRON_SUPER_CTX"]), int(os.environ["OC_NEMOTRON_SUPER_OUT"]),
|
|
os.environ.get("OC_NEMOTRON_SUPER_NAME") or "Nemotron 3.5 Super VL (local, 1M)",
|
|
"nemotron-super")
|
|
|
|
default = "flashnext/qwen3.8-flash-next" if lane == "flash" else "qwen38/qwen3.8-27b"
|
|
if os.environ.get("OC_KOLIBRI_BOOT") == "1" and "kolibri" in providers:
|
|
default = "kolibri/kolibri-1" # the lane this box serves stays opencode's default
|
|
if os.environ.get("OC_NEMOTRON_BOOT") == "1" and "nemotron" in providers:
|
|
default = "nemotron/nemotron-3.5-bolt"
|
|
if os.environ.get("OC_NEMOTRON_SUPER_BOOT") == "1" and "nemotron-super" in providers:
|
|
default = "nemotron-super/nemotron-3.5-super-vl"
|
|
# Compaction is global in opencode.json, not per-model, so it is sized from the
|
|
# INSTALLED target (oc-limits.sh --preserve) and rewritten by every install and
|
|
# switch. preserve_recent_tokens exists because opencode's own default clamps it
|
|
# at 15,000 whatever the window: on a 262K lane a compaction at 205,000 tokens
|
|
# would keep 15,000 and summarise the other 190,000, which is not using the
|
|
# window, it is refilling it from scratch. prune stays off: opencode's pruning
|
|
# swaps old tool output for a placeholder (past the most recent 40,000 tokens of
|
|
# it), which changes the history the engine cached, so the next turn recomputes
|
|
# everything after the first cleared output (2026-10-13: 232 of 527 tool parts
|
|
# cleared in a 410K-token session). Room is made by compaction instead.
|
|
doc = {"$schema": "https://opencode.ai/config.json", "provider": providers,
|
|
"compaction": {"preserve_recent_tokens": int(os.environ["OC_KEEP"]), "prune": False},
|
|
"model": default, "small_model": default}
|
|
# With the version pinned, opencode looks for no update at all: false, the JSON boolean
|
|
# (its schema takes a boolean or "notify", not the string "false"). With any other value
|
|
# 1.19's TUI checks every 10 minutes and, once it is on the newest 1.x, shows "/update to
|
|
# upgrade to OpenCode 2.0" on its home screen (1.18.35 announces 2.x as soon as GitHub's
|
|
# latest release is one), and OpenCode 2's server is not the 1.x `opencode serve` the
|
|
# Agent tab's relay is written for. Up to 1.18, unset meant opencode installed its own
|
|
# patch releases (see the OPENCODE_VERSION pin).
|
|
if os.environ.get("OC_PIN") == "1":
|
|
doc["autoupdate"] = False
|
|
# written only when it changes, so its date says when it last did: opencode-web is
|
|
# restarted below only for a config newer than it
|
|
text = json.dumps(doc, indent=2) + "\n"
|
|
try:
|
|
with open(f"{cfg_dir}/opencode.json") as f:
|
|
same = f.read() == text
|
|
except OSError:
|
|
same = False
|
|
if not same:
|
|
with open(f"{cfg_dir}/opencode.json", "w") as f:
|
|
f.write(text)
|
|
print(f"{'kept' if same else 'wrote'} {cfg_dir}/opencode.json (default {default}, "
|
|
f"providers: {', '.join(providers) or 'none'})")
|
|
PYEOF
|
|
echo "opencode limits: context $OC_CTX, output $OC_OUT, port $OC_PORT"
|
|
# opencode's threshold is limit.input - min(20,000, limit.output) (see oc-limits.sh)
|
|
echo " compaction fires at $((OC_CTX - (OC_OUT < 20000 ? OC_OUT : 20000))) tokens and keeps $OC_KEEP verbatim"
|
|
OC_USER_CFG="$HOME/.config/opencode/opencode.json"
|
|
# A box with no opencode config of its own gets this one. There is nothing to merge
|
|
# into and nothing of the user's to keep, and nothing else points opencode at the file
|
|
# above: without this, a first install left opencode, oc and the Agent tab with no
|
|
# provider for the model the box serves, and a printed cp command to find.
|
|
if [ ! -e "$OC_USER_CFG" ]; then
|
|
mkdir -p "$HOME/.config/opencode"
|
|
install -m 644 "$CONFIG_DIR/opencode.json" "$OC_USER_CFG"
|
|
echo " no opencode config yet: installed this repo's at $OC_USER_CFG"
|
|
elif ! grep -qsE '"(qwen38|flashnext|kolibri|nemotron|nemotron-super)"' "$OC_USER_CFG"; then
|
|
# the user's own config, with none of this repo's providers in it: theirs to merge
|
|
echo " your $OC_USER_CFG has no provider for this box: merge the \"qwen38\" (or \"flashnext\")"
|
|
echo " block from $CONFIG_DIR/opencode.json into it (docs/opencode.md)"
|
|
else
|
|
# A config set up for this box, by the copy above or by hand, lists the lanes the
|
|
# box had then. A lane installed since (the 27B first, the flash lane later) brings
|
|
# its provider in: without it the merges below find nothing to merge, and opencode
|
|
# sends the other lane's limits and label to the one that serves.
|
|
python3 "$REPO_DIR/oc-merge-limits.py" "$OC_USER_CFG" --add-providers "$CONFIG_DIR/opencode.json" || true
|
|
fi
|
|
# An existing opencode.json keeps the user's other providers, but its limits for
|
|
# THIS lane must follow the served engine (v1.5.2: a flash conversation allowed
|
|
# to grow to 226000 tokens outgrew the 159k KV pool and wedged the scheduler).
|
|
if [ -f "$OC_USER_CFG" ] && [ "$OPENCODE_PIN" = "1" ]; then
|
|
# false, not "notify": with any other value opencode offers OpenCode 2, which the Agent
|
|
# tab's relay is not written for (see the generated config above). This file is the one
|
|
# that check reads (opencode's global config); a box an earlier run set to "notify"
|
|
# moves to false here.
|
|
python3 "$REPO_DIR/oc-merge-limits.py" "$OC_USER_CFG" --autoupdate false || true
|
|
fi
|
|
if [ -f "$OC_USER_CFG" ]; then
|
|
if [ "${LANE:-27b}" = "flash" ]; then
|
|
python3 "$REPO_DIR/oc-merge-limits.py" "$OC_USER_CFG" flashnext qwen3.8-flash-next "$OC_CTX" "$OC_OUT" || true
|
|
python3 "$REPO_DIR/oc-merge-limits.py" "$OC_USER_CFG" --compaction "$OC_KEEP" || true
|
|
# The lean level exists in this lane's template because the run above just
|
|
# patched it. It is offered only for the lane being installed: a provider
|
|
# entry advertising a level the served template does not know answers 500.
|
|
python3 "$REPO_DIR/oc-merge-limits.py" "$OC_USER_CFG" flashnext qwen3.8-flash-next --add-variant lean || true
|
|
else
|
|
# Never downgrade a 27B unit that serves a larger window than this run's
|
|
# CONTEXT_MODE computed (a native-mode re-install clobbered a 1m user's
|
|
# 700000/200000 back to 194048/64000, reference box 2026-08-30). Only a mode
|
|
# nobody asked for, though: an explicit CONTEXT_MODE=native installs the native
|
|
# unit at step 8, and the 1M limits kept here then asked 700,000 of a 262,144
|
|
# window, a 400 past it, under advice to pass CONTEXT_MODE=1m (found in review,
|
|
# 2026-09-24). Since the mode converges on the installed unit, an explicit one is
|
|
# the only way here.
|
|
UNIT_CTX="$(grep -oE -- '--context-length [0-9]+' "$SGL_UNIT_PATH" 2>/dev/null | awk '{print $2}' | head -1 || true)"
|
|
if [ -n "$UNIT_CTX" ] && [ "$UNIT_CTX" -gt 262144 ] && [ "$CONTEXT_MODE" != "1m" ] && [ -z "$_ENV_CONTEXT_MODE" ]; then
|
|
echo "NOTE: the installed 27B unit serves --context-length $UNIT_CTX; keeping the existing"
|
|
echo " opencode limits (these $CONTEXT_MODE-mode values would shrink them). Re-run with"
|
|
echo " CONTEXT_MODE=1m to manage them, or edit $OC_USER_CFG yourself."
|
|
else
|
|
# on 1m the table's pair is a bound, and the fit at the end sets the pair: keep one
|
|
# already under it (see oc-merge-limits.py --keep-lower)
|
|
OC_KEEP_LOWER=(); [ "$CONTEXT_MODE" = "1m" ] && OC_KEEP_LOWER=(--keep-lower)
|
|
python3 "$REPO_DIR/oc-merge-limits.py" "$OC_USER_CFG" qwen38 qwen3.8-27b "$OC_CTX" "$OC_OUT" ${OC_KEEP_LOWER[@]+"${OC_KEEP_LOWER[@]}"} || true
|
|
python3 "$REPO_DIR/oc-merge-limits.py" "$OC_USER_CFG" --compaction "$OC_KEEP" || true
|
|
fi
|
|
# Offered whatever the limits branch decided above: the level comes from the
|
|
# template this run patched, not from the context mode.
|
|
python3 "$REPO_DIR/oc-merge-limits.py" "$OC_USER_CFG" qwen38 qwen3.8-27b --add-variant lean || true
|
|
fi
|
|
fi
|
|
# The default model and the served entry's picker name follow the install, not
|
|
# just the limits: an install that changes lane left opencode offering and
|
|
# defaulting to the previous lane (reference box 2026-09-11: flash selected
|
|
# while stock 1M served). Same helper as switch-model.sh, one label table; it moves
|
|
# the user's default only when that one is unset or already this box's.
|
|
OC_POINT_LANE="$LANE"; OC_POINT_CHOICE="$MODEL_CHOICE"; OC_POINT_WINDOW="$OC_WINDOW"
|
|
if [ "$KOLIBRI_BOOT" -eq 1 ] && [ "$OC_KOLIBRI" -eq 1 ]; then
|
|
# the Kolibri lane is this box's lane: opencode's default stays on it
|
|
OC_POINT_LANE=kolibri; OC_POINT_CHOICE="$OC_KOLIBRI_TARGET"; OC_POINT_WINDOW=262144
|
|
fi
|
|
if [ "$NEMOTRON_BOOT" -eq 1 ] && [ "$OC_NEMOTRON" -eq 1 ]; then
|
|
# the Nemotron lane is this box's lane: opencode's default stays on it
|
|
OC_POINT_LANE=nemotron; OC_POINT_CHOICE=nemotron; OC_POINT_WINDOW=262144
|
|
fi
|
|
if [ "$NEMOTRON_SUPER_BOOT" -eq 1 ] && [ "$OC_NEMOTRON_SUPER" -eq 1 ]; then
|
|
# the Nemotron Super lane is this box's lane: opencode's default stays on it
|
|
OC_POINT_LANE=nemotron-super; OC_POINT_CHOICE=nemotron-super; OC_POINT_WINDOW=1048576
|
|
fi
|
|
python3 "$REPO_DIR/oc-point-default.py" "$CONFIG_DIR/opencode.json" "$OC_POINT_LANE" "$OC_POINT_CHOICE" "$OC_POINT_WINDOW" \
|
|
|| die "could not point the generated opencode config at the installed lane"
|
|
if [ -f "$OC_USER_CFG" ]; then
|
|
python3 "$REPO_DIR/oc-point-default.py" "$OC_USER_CFG" "$OC_POINT_LANE" "$OC_POINT_CHOICE" "$OC_POINT_WINDOW" || true
|
|
fi
|
|
# pi and omp (docs/pi.md): their files are regenerated from the opencode.json written above, as
|
|
# switch-model.sh does after a switch (block 4f), and only on a box that asked for them once
|
|
# (./pi-gen.py made the directories). An update left them behind it: v1.30.0's changed Kolibri's
|
|
# pair in opencode.json and not in pi's models.json, until the next switch (found 2026-10-14).
|
|
if [ -d "$CONFIG_DIR/pi" ] || [ -d "$CONFIG_DIR/omp" ]; then
|
|
python3 "$REPO_DIR/pi-gen.py" --config "$CONFIG_DIR/opencode.json" --out "$CONFIG_DIR" \
|
|
|| echo "NOTE: could not regenerate the pi/omp artifacts; run ./pi-gen.py by hand"
|
|
fi
|
|
# Every opencode.json this install touches has been written by now, except the limits
|
|
# a 1m install fits to the pool once the engine is up (step 9, which restarts it again),
|
|
# so the server that reads them can be restarted. It parses opencode.json ONCE at startup and
|
|
# never again (measured 2026-09-13: the file said 225,000 while the running
|
|
# server still answered 175,000 on /config), so without this the Agent tab keeps
|
|
# compacting against the previous install's window. Last, not mid-write: a
|
|
# restart before the user's own config is merged would reload the old numbers.
|
|
# Only when one of them changed: this restart ended whatever turn the Agent tab was in
|
|
# the middle of, on every run, a run that changed nothing included (up to three restarts
|
|
# of opencode-web per install on 2026-09-23; found in review, 2026-09-24).
|
|
if systemctl list-unit-files opencode-web.service >/dev/null 2>&1 \
|
|
&& systemctl is-active --quiet opencode-web.service; then
|
|
if [ "$(oc_configs_sum)" != "$OC_SUM_BEFORE" ]; then
|
|
sudo systemctl restart opencode-web.service \
|
|
&& echo "opencode-web.service restarted so it reads the new limits" \
|
|
|| echo "NOTE: restart opencode-web.service by hand, or the Agent view keeps the old limits"
|
|
else
|
|
echo "opencode-web.service kept: the configs it reads did not change"
|
|
fi
|
|
fi
|
|
# oc: launcher that lifts opencode's hidden 32000 max_tokens cap to the
|
|
# declared output limit (without it, long thinking is cut at 32000 and the
|
|
# turn ends silently). Never clobbers a foreign oc binary (e.g. OpenShift).
|
|
OC_BIN="$HOME/.local/bin/oc"
|
|
OC_EXISTING="$(command -v oc || true)"
|
|
# Not ours: a file at the launcher's own path without this repo's mark (OpenShift's oc
|
|
# lives there too), or another oc first on the PATH. Only the second was looked at, so an
|
|
# oc at the very path was overwritten, and so was one in a ~/.local/bin this shell's PATH
|
|
# lacks (found in review, 2026-09-24).
|
|
OC_FOREIGN=""
|
|
if [ -e "$OC_BIN" ] && ! grep -q 'dgx-spark-qwen38' "$OC_BIN" 2>/dev/null; then
|
|
OC_FOREIGN="$OC_BIN"
|
|
elif [ -n "$OC_EXISTING" ] && [ "$OC_EXISTING" != "$OC_BIN" ] && ! grep -q 'dgx-spark-qwen38' "$OC_EXISTING" 2>/dev/null; then
|
|
OC_FOREIGN="$OC_EXISTING"
|
|
fi
|
|
if [ -n "$OC_FOREIGN" ]; then
|
|
echo "NOTE: an unrelated 'oc' command exists at $OC_FOREIGN; not installing the launcher."
|
|
# OPENCODE_CONFIG as the launcher sets it: without it opencode sends the prompts to its
|
|
# own hosted model when the global config names no provider for this box (2026-09-23)
|
|
echo " Launch opencode with: OPENCODE_CONFIG=$CONFIG_DIR/opencode.json OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX=$OC_OUT_CAP opencode --yolo"
|
|
else
|
|
mkdir -p "$HOME/.local/bin"
|
|
cat > "$OC_BIN" <<OCWRAP
|
|
#!/bin/bash
|
|
# oc launcher installed by dgx-spark-qwen38: opencode wired to the local server.
|
|
# Lifts opencode's hidden 32000 max_tokens cap above every output limit this
|
|
# repo declares; without this, long thinking phases are cut at 32000 and the
|
|
# turn ends silently. It is a ceiling: the per-model limit.output in
|
|
# opencode.json is the number that follows a model switch, and this one only has
|
|
# to stay above it, which is why it is not the installed target's own limit.
|
|
# --yolo auto-approves permissions (the reference box runs this way; remove it
|
|
# below if you prefer per-action prompts).
|
|
export OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX="\${OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX:-$OC_OUT_CAP}"
|
|
# The box's providers and default model, over whatever the global opencode config
|
|
# says (opencode loads OPENCODE_CONFIG after it). Without this, a config with no
|
|
# provider for this box sent oc's prompts to opencode's own hosted model (2026-09-23).
|
|
[ -f "$CONFIG_DIR/opencode.json" ] && export OPENCODE_CONFIG="\${OPENCODE_CONFIG:-$CONFIG_DIR/opencode.json}"
|
|
OPENCODE_BIN="\$(command -v opencode || true)"
|
|
[ -n "\$OPENCODE_BIN" ] || OPENCODE_BIN="\$HOME/.opencode/bin/opencode"
|
|
if [ ! -x "\$OPENCODE_BIN" ]; then
|
|
echo "oc: opencode is not installed. Re-run ./install.sh in $REPO_DIR: it installs the opencode this repo tests ($OPENCODE_VERSION)." >&2
|
|
exit 127
|
|
fi
|
|
# --yolo goes LAST: opencode's parser rejects global flags before a
|
|
# subcommand (opencode --yolo run ... prints the help instead of running)
|
|
exec "\$OPENCODE_BIN" "\$@" --yolo
|
|
OCWRAP
|
|
chmod +x "$OC_BIN"
|
|
echo "installed the oc launcher at $OC_BIN (output ceiling $OC_OUT_CAP, this target's limit $OC_OUT)"
|
|
case ":$PATH:" in
|
|
*":$HOME/.local/bin:"*) ;;
|
|
*) echo "NOTE: $HOME/.local/bin is not in this shell's PATH: a new login has it (Ubuntu's ~/.profile"
|
|
echo " adds it once the folder exists), or call $OC_BIN directly." ;;
|
|
esac
|
|
fi
|
|
fi
|
|
# end of step 7
|
|
|
|
if [ "$NO_SERVICE" -eq 1 ]; then
|
|
apply_context_configs
|
|
printf '\n\033[1;32m✅ Prepared (no systemd, nothing needed sudo).\033[0m\n'
|
|
echo " Run in the foreground: ./run.sh (Ctrl+C stops it; first boot ≈ 9 min)"
|
|
# Not just two folders: the summary said so, and left out the serving image, opencode,
|
|
# the oc launcher and the provider this box adds to the user's opencode config, which
|
|
# reads the key in the config folder: opencode refuses to start while it points at a key
|
|
# that is gone (found in review, 2026-09-24).
|
|
echo " To remove it later: ./uninstall.sh --list names everything this left and changes nothing:"
|
|
echo " $CONFIG_DIR (the key, templates), the checkpoints in $HF_CACHE, the serving image, opencode"
|
|
echo " and its oc launcher, and a provider in your opencode config that reads $CONFIG_DIR/api-key."
|
|
echo " Remove that provider with the key, or opencode refuses to start."
|
|
echo " No cockpit either: it is a systemd unit, and --no-service installs none."
|
|
exit 0
|
|
fi
|
|
|
|
step "8/10 Installing the systemd service (sudo needed)"
|
|
# The steps below make most of this script's sudo calls, and a dead timestamp used to
|
|
# kill the install here with no message at all (set -e on a bare `sudo cp`, reference
|
|
# box 2026-09-13, three times in one afternoon: background runs and passwordless
|
|
# contexts have no tty for sudo to ask on). The ticket asked for at step 1 can have
|
|
# expired during the downloads (sudo keeps one 15 min), so it is renewed here: with a
|
|
# terminal sudo asks again, without one `sudo -v` fails at once and the refusal names
|
|
# the fix. `sudo -n` alone never asked, and a fresh one-liner died here after ~20 min.
|
|
sudo -n true 2>/dev/null || sudo -v || die "sudo needs a fresh timestamp before the systemd step: run 'sudo -v', then re-run ./install.sh (completed steps are skipped)"
|
|
UNIT_PATH="/etc/systemd/system/$UNIT_NAME"
|
|
if [ -f "$UNIT_PATH" ]; then
|
|
# Safety net for hand-tuned units: the previous unit stays recoverable.
|
|
sudo cp "$UNIT_PATH" "$CONFIG_DIR/$UNIT_NAME.bak-preupdate"
|
|
sudo chown "$(id -u):$(id -g)" "$CONFIG_DIR/$UNIT_NAME.bak-preupdate"
|
|
echo "previous unit backed up at $CONFIG_DIR/$UNIT_NAME.bak-preupdate"
|
|
fi
|
|
if [ "$LANE" = "flash" ]; then
|
|
UNIT_TPL="$REPO_DIR/qwen38-flash.service.template"
|
|
SERVE_IMAGE_FINAL="$FLASH_SERVE_IMAGE"
|
|
else
|
|
UNIT_TPL="$REPO_DIR/qwen38-sglang.service.template"
|
|
[ "$CONTEXT_MODE" = "1m" ] && UNIT_TPL="$REPO_DIR/qwen38-sglang-1m.service.template"
|
|
SERVE_IMAGE_FINAL="$SERVE_IMAGE"
|
|
fi
|
|
# Serve-time revision lock: the pinned sha is passed to the server itself, so
|
|
# an upstream push to the checkpoint repo can never change what is served
|
|
# (download-time pinning alone leaves "main" resolvable at boot). A kept
|
|
# custom model reuses its unit's existing --revision, or none.
|
|
if [ "$KEEP_MODEL_VERBATIM" -eq 1 ]; then
|
|
MODEL_REV_ARGS=""
|
|
[ -n "${CUR_REV:-}" ] && MODEL_REV_ARGS="--revision $CUR_REV"
|
|
else
|
|
MODEL_REV_ARGS="--revision $MODEL_REV"
|
|
fi
|
|
# The 27B lane serves with an fp8 KV cache. The NVFP4 checkpoints carry their own
|
|
# KV scales so SGLang picks it up from the checkpoint; Qwen's FP8 release does not,
|
|
# and defaults to a bf16 KV cache that costs about half the pool (measured on the
|
|
# reference box, same 1m unit: 771,139 tokens with the flag, 382,706 without). So
|
|
# the FP8 pair asks for it explicitly, which is what the reference box has served
|
|
# since 2026-08-31 and what every FP8 pool number in this repo was measured on.
|
|
case "$MODEL_CHOICE" in
|
|
fp8|uncensored-fp8) KV_CACHE_ARGS="--kv-cache-dtype fp8_e4m3 " ;;
|
|
*) KV_CACHE_ARGS="" ;;
|
|
esac
|
|
|
|
# The reduced draft vocabulary is a speculative-path flag: a tier that does not
|
|
# speculate must not receive it. Rendered as a whole line so an off setting
|
|
# leaves no dangling backslash in the launcher.
|
|
SPEC_TOKEN_MAP_LINE=""
|
|
case "$FLASH_TIER_ARGS" in
|
|
*--speculative-algorithm*)
|
|
if [ "${SPEC_TOKEN_MAP_SIZE:-0}" -gt 0 ] && [ -s "$CONFIG_DIR/$TOKEN_MAP_NAME" ]; then
|
|
SPEC_TOKEN_MAP_LINE="TIER+=(--speculative-token-map /out/$TOKEN_MAP_NAME)"
|
|
elif [ "${SPEC_TOKEN_MAP_SIZE:-0}" -gt 0 ]; then
|
|
# Not built yet (a lane installed on demand, whose first Load builds it; a run with no
|
|
# snapshot yet): the launcher takes it at the first start after it is, with no new install.
|
|
SPEC_TOKEN_MAP_LINE="[ -s \"$CONFIG_DIR/$TOKEN_MAP_NAME\" ] && TIER+=(--speculative-token-map /out/$TOKEN_MAP_NAME)"
|
|
fi ;;
|
|
esac
|
|
|
|
# Whatever the convergence block decided, the per-checkpoint and per-tier args
|
|
# are derived from it here, once, before anything is rendered.
|
|
resolve_flash_checkpoint_args
|
|
resolve_flash_tier_args
|
|
# And a flash launcher without its checkpoint's own flags is a ten-minute boot
|
|
# that dies at MoE autotune, so it never gets written.
|
|
if [ "$LANE" = "flash" ] && [ -z "$FLASH_QUANT_ARGS" ]; then
|
|
die "internal error: the flash lane resolved no checkpoint flags for MODEL_CHOICE=$MODEL_CHOICE. Refusing to write a launcher that would fail ten minutes into its boot. Please open an issue with this line."
|
|
fi
|
|
|
|
render_tpl() { # $1 template file; substituted result on stdout
|
|
# Values are paths and versions, and paths may carry sed-special bytes
|
|
# (& expands to the match, | is the delimiter, backslash escapes): escape
|
|
# once so a mount point like /mnt/a&b can never corrupt an installed unit.
|
|
esc() { printf '%s' "$1" | sed -e 's/[\\/&|]/\\&/g'; }
|
|
sed -e "s|__HOME__|$(esc "$HOME")|g" \
|
|
-e "s|__USER__|$(esc "$(id -un)")|g" \
|
|
-e "s|__GROUP__|$(esc "$(id -gn)")|g" \
|
|
-e "s|__PORT__|$(esc "$PORT")|g" \
|
|
-e "s|__ENGINE_BIND__|$(esc "$ENGINE_BIND")|g" \
|
|
-e "s|__IMAGE__|$(esc "$SERVE_IMAGE_FINAL")|g" \
|
|
-e "s|__HF_CACHE__|$(esc "$HF_CACHE")|g" \
|
|
-e "s|__DRAFT2_REV__|$(esc "$DRAFT2_REV")|g" \
|
|
-e "s|__DRAFT2_REPO__|$(esc "$DRAFT2_REPO")|g" \
|
|
-e "s|__DRAFT2_QUANT__|$(esc "$DRAFT2_QUANT")|g" \
|
|
-e "s|__DRAFT2_TOKENS__|$(esc "$DRAFT2_TOKENS")|g" \
|
|
-e "s|__MODEL_REV_ARGS__|$(esc "$MODEL_REV_ARGS")|g" \
|
|
-e "s|__MODEL__|$(esc "$MODEL_REPO")|g" \
|
|
-e "s|__PLE_DIR__|$(esc "$PLE_DIR")|g" \
|
|
-e "s|__MODEL_REV__|$(esc "$MODEL_REV")|g" \
|
|
-e "s|__KV_CACHE_ARGS__|$(esc "$KV_CACHE_ARGS")|g" \
|
|
-e "s|__FLASH_TIER_ARGS__|$(esc "$FLASH_TIER_ARGS")|g" \
|
|
-e "s|__FLASH_QUANT_ARGS__|$(esc "$FLASH_QUANT_ARGS")|g" \
|
|
-e "s|__FLASH_MEM_FRACTION__|$(esc "$FLASH_MEM_FRACTION")|g" \
|
|
-e "s|__PLE_RSS_BUDGET_GB__|$(esc "$PLE_RSS_BUDGET_GB")|g" \
|
|
-e "s|__SPEC_TOKEN_MAP_LINE__|$(esc "$SPEC_TOKEN_MAP_LINE")|g" \
|
|
"$1"
|
|
}
|
|
# What this run renders before installing it is removed however the run ends: a die between
|
|
# a mktemp and its rm left the rendered file in /tmp (2026-10-03). Subshells reset the trap.
|
|
RENDERED=()
|
|
forget_rendered(){ local f; for f in "${RENDERED[@]}"; do if [ -f "$f" ]; then rm -f -- "$f"; fi; done; return 0; }
|
|
trap forget_rendered EXIT
|
|
if [ "$LANE" = "flash" ]; then
|
|
mkdir -p "$PLE_DIR"
|
|
# The docker-run command lives in a plain launch script, not in ExecStart:
|
|
# systemd applies its own C-style unescaping before bash would, and the JSON
|
|
# arguments (--speculative-config, splitting_ops) do not survive two rounds.
|
|
TMP_LAUNCH="$(mktemp)"; RENDERED+=("$TMP_LAUNCH")
|
|
render_tpl "$REPO_DIR/qwen38-flash-launch.sh.template" > "$TMP_LAUNCH"
|
|
bash -n "$TMP_LAUNCH" || die "rendered flash launch script does not parse (report this repo bug)"
|
|
# rewritten only when it changes: the engine reads it at start, and a rewrite, even an
|
|
# identical one, would make the next run restart a running engine (engine-inputs.py)
|
|
# said as it is: an update that changed nothing here read "wrote" all the same
|
|
if cmp -s "$TMP_LAUNCH" "$CONFIG_DIR/launch-flash.sh"; then
|
|
echo "launch script unchanged: $CONFIG_DIR/launch-flash.sh"
|
|
else
|
|
install -m 755 "$TMP_LAUNCH" "$CONFIG_DIR/launch-flash.sh"
|
|
echo "wrote $CONFIG_DIR/launch-flash.sh"
|
|
fi
|
|
rm -f "$TMP_LAUNCH"
|
|
fi
|
|
TMP_UNIT="$(mktemp)"; RENDERED+=("$TMP_UNIT")
|
|
render_tpl "$UNIT_TPL" > "$TMP_UNIT"
|
|
apply_context_configs # the configs, then at once the unit that reads them
|
|
# the same rule for the unit: an identical one is left as it is, mtime included, and one changed
|
|
# only in the lines naming the other lanes keeps its date (lanes.sh unit_put)
|
|
UNIT_PUT="$(unit_put "$TMP_UNIT" "/etc/systemd/system/$UNIT_NAME")"
|
|
[ "$UNIT_PUT" != deps ] || echo "unit updated: only the lines naming the other lanes changed, which the engine does not read"
|
|
rm -f "$TMP_UNIT"
|
|
# Cross-engine switch: exactly one serving unit may start at boot. The other
|
|
# engine's unit (if present) is disabled now and stopped at step 9, right
|
|
# before this one starts; its unit file is kept for a fast switch back.
|
|
OTHER_UNIT=""
|
|
if [ "$LANE" = "flash" ]; then
|
|
[ -f "$SGL_UNIT_PATH" ] && OTHER_UNIT="qwen38-sglang.service"
|
|
else
|
|
[ -f "$FLASH_UNIT_PATH" ] && OTHER_UNIT="qwen38-flash.service"
|
|
fi
|
|
# A secondary run installs its lane beside the one serving and leaves the boot lane alone:
|
|
# the three disables below, the proxy's unit and enabling its own are the serving run's.
|
|
if [ -z "$SECONDARY" ] && [ -n "$OTHER_UNIT" ] && systemctl is-enabled --quiet "$OTHER_UNIT" 2>/dev/null; then
|
|
echo "disabling the other engine's unit at boot: $OTHER_UNIT (file kept, switch back anytime with ./switch-model.sh)"
|
|
sudo systemctl disable "$OTHER_UNIT"
|
|
fi
|
|
# The image lane is the third engine. When this run makes a text lane the boot lane (an
|
|
# explicit MODEL_CHOICE on a box that booted images), leaving it enabled would put two
|
|
# engines at the next boot.
|
|
if [ -z "$SECONDARY" ] && [ "$IMAGE_BOOT" -eq 0 ] && systemctl is-enabled --quiet qwen38-image.service 2>/dev/null; then
|
|
echo "disabling the image lane at boot (unit kept, switch back anytime from the cockpit)"
|
|
sudo systemctl disable qwen38-image.service
|
|
fi
|
|
# The video lane is the fourth engine, under the same rule.
|
|
if [ -z "$SECONDARY" ] && [ "$VIDEO_BOOT" -eq 0 ] && systemctl is-enabled --quiet qwen38-video.service 2>/dev/null; then
|
|
echo "disabling the video lane at boot (unit kept, switch back anytime from the cockpit)"
|
|
sudo systemctl disable qwen38-video.service
|
|
fi
|
|
# The Kolibri lane is the fifth, under the same rule.
|
|
if [ -z "$SECONDARY" ] && [ "$KOLIBRI_BOOT" -eq 0 ] && systemctl is-enabled --quiet qwen38-kolibri.service 2>/dev/null; then
|
|
echo "disabling the Kolibri lane at boot (unit kept, switch back anytime from the cockpit)"
|
|
sudo systemctl disable qwen38-kolibri.service
|
|
fi
|
|
# The Nemotron lanes are the sixth and the seventh, under the same rule.
|
|
if [ -z "$SECONDARY" ] && [ "$NEMOTRON_BOOT" -eq 0 ] && systemctl is-enabled --quiet qwen38-nemotron.service 2>/dev/null; then
|
|
echo "disabling the Nemotron lane at boot (unit kept, switch back anytime from the cockpit)"
|
|
sudo systemctl disable qwen38-nemotron.service
|
|
fi
|
|
if [ -z "$SECONDARY" ] && [ "$NEMOTRON_SUPER_BOOT" -eq 0 ] && systemctl is-enabled --quiet qwen38-nemotron-super.service 2>/dev/null; then
|
|
echo "disabling the Nemotron Super lane at boot (unit kept, switch back anytime from the cockpit)"
|
|
sudo systemctl disable qwen38-nemotron-super.service
|
|
fi
|
|
KEEPALIVE_UNIT="qwen38-keepalive.service"
|
|
KA_CHANGED=0 # whether this run changed what the proxy runs (see its restart below)
|
|
# The proxy, its code and its unit are the serving run's (see the secondary run above).
|
|
if [ -z "$SECONDARY" ]; then
|
|
# One-prompt ceiling enforced by the proxy (tokens; 0 = pool share only). The proxy
|
|
# always refuses a prompt above its share of the KV pool as well, so the smaller of
|
|
# the two binds and a tier with a small pool needs no separate ceiling.
|
|
#
|
|
# Flash lane, 128,000 from v1.5.6 to v1.7 and 200,000 from v1.8: the prefill of a
|
|
# long prompt grew the engine's memory by ~0.27 GiB per 1k tokens beyond ~90k
|
|
# (measured 29/08, a 120k prompt cost ~9 GiB of host headroom), which put a 150k
|
|
# prompt at the memory edge. That growth was the PLE table's mapping faulting in
|
|
# whole page-cache folios, and v1.8 serves an engine that trims it.
|
|
#
|
|
# How far it trims was only half measured: 200,058 tokens cost 3.5 GiB, and above
|
|
# that was left deliberately unmeasured because a livelock on this box costs a
|
|
# power cycle. Measured on 2026-09-13, MemAvailable sampled through each prefill,
|
|
# engine up 19 h with the PLE budget already filled:
|
|
#
|
|
# 195,784 tokens -> 1.16 GiB of host headroom, 94.7 s
|
|
# 225,051 tokens -> 1.57 GiB, 111.3 s
|
|
# 249,500 tokens -> 1.52 GiB, 126.1 s, floor 7.0 GiB
|
|
#
|
|
# The cost is flat past 200k and an order of magnitude below what the v1.5 engine
|
|
# paid, so memory is no longer what caps this lane. What caps it is the engine's
|
|
# own wall, max_req_input_len = 262,138: the ceiling is 250,000, which leaves
|
|
# 12,138 tokens of slack under it. That band matters because until 2026-09-13 the
|
|
# launcher passed --allow-auto-truncate and a prompt over the wall came back
|
|
# silently cut rather than refused.
|
|
# The flash lane's ceiling goes in the unit whatever lane this installs: the proxy applies
|
|
# it while the flash lane serves (v6.25), so a switch no longer has to move it with a
|
|
# restart. PROMPT_CEILING_TOKENS, when given, is a ceiling on any lane.
|
|
PROMPT_CEILING="${PROMPT_CEILING_TOKENS:-0}"
|
|
FLASH_PROMPT_CEILING="${FLASH_PROMPT_CEILING_TOKENS:-250000}"
|
|
[[ "$PROMPT_CEILING$FLASH_PROMPT_CEILING" =~ ^[0-9]+$ ]] || die "PROMPT_CEILING_TOKENS and FLASH_PROMPT_CEILING_TOKENS take a number of tokens"
|
|
# Every service install gets the keepalive proxy: SGLang buffers tool-call
|
|
# arguments while they stream (127 s of measured silence on a 400-line write,
|
|
# at native context) and agent CLIs abort a silent stream (~140-180 s for
|
|
# opencode). It also aborts zombie generations when the client disconnects.
|
|
cmp -s "$REPO_DIR/keepalive-proxy.py" "$CONFIG_DIR/keepalive-proxy.py" \
|
|
|| { install -m 755 "$REPO_DIR/keepalive-proxy.py" "$CONFIG_DIR/keepalive-proxy.py"; KA_CHANGED=1; }
|
|
TMP_KA="$(mktemp)"; RENDERED+=("$TMP_KA")
|
|
sed -e "s|__HOME__|$HOME|g" \
|
|
-e "s|__USER__|$(id -un)|g" \
|
|
-e "s|__GROUP__|$(id -gn)|g" \
|
|
-e "s|__PORT__|$PORT|g" \
|
|
-e "s|__PROXY_PORT__|$PROXY_PORT|g" \
|
|
-e "s|__PROXY_BIND__|$PROXY_BIND|g" \
|
|
-e "s|__PROMPT_CEILING__|$PROMPT_CEILING|g" \
|
|
-e "s|__FLASH_PROMPT_CEILING__|$FLASH_PROMPT_CEILING|g" \
|
|
"$REPO_DIR/qwen38-keepalive.service.template" > "$TMP_KA"
|
|
cmp -s "$TMP_KA" "/etc/systemd/system/$KEEPALIVE_UNIT" \
|
|
|| { sudo install -m 644 "$TMP_KA" "/etc/systemd/system/$KEEPALIVE_UNIT"; KA_CHANGED=1; }
|
|
rm -f "$TMP_KA"
|
|
sudo systemctl enable "$KEEPALIVE_UNIT"
|
|
# The ceiling lives in the unit this installer writes. A switch-model.sh
|
|
# drop-in from an earlier lane would override it silently, so it goes: either
|
|
# path converges on the installed lane's ceiling.
|
|
if [ -f "/etc/systemd/system/$KEEPALIVE_UNIT.d/ceiling.conf" ]; then
|
|
echo "removing the stale keepalive ceiling drop-in (the installed unit carries the ceiling now)"
|
|
sudo rm -f "/etc/systemd/system/$KEEPALIVE_UNIT.d/ceiling.conf"
|
|
KA_CHANGED=1
|
|
sudo rmdir "/etc/systemd/system/$KEEPALIVE_UNIT.d" 2>/dev/null || true
|
|
fi
|
|
fi
|
|
# The Claude Code warmup was removed in v1.3: clean up what earlier versions
|
|
# installed (only the warmup drop-in; any other drop-in in the .d dir is kept).
|
|
if [ -f "/etc/systemd/system/$UNIT_NAME.d/warmup.conf" ]; then
|
|
echo "removing the deprecated Claude Code warmup drop-in"
|
|
sudo rm -f "/etc/systemd/system/$UNIT_NAME.d/warmup.conf"
|
|
sudo rmdir "/etc/systemd/system/$UNIT_NAME.d" 2>/dev/null || true
|
|
fi
|
|
rm -f "$CONFIG_DIR/warmup-claude-code.sh"
|
|
sudo systemctl daemon-reload
|
|
if [ -n "$SECONDARY" ]; then
|
|
# Installed, not enabled and not started: the serving run proves it once it is new.
|
|
if [ "$UNITS_ONLY" -eq 1 ]; then
|
|
step "Done: installed as $UNIT_NAME ($MODEL_CHOICE), not enabled at boot, not prepared yet"
|
|
else
|
|
step "Done: installed as $UNIT_NAME ($MODEL_CHOICE), not enabled at boot"
|
|
fi
|
|
exit 0
|
|
fi
|
|
if [ "$IMAGE_BOOT" -eq 0 ] && [ "$VIDEO_BOOT" -eq 0 ] && [ "$KOLIBRI_BOOT" -eq 0 ] && [ "$NEMOTRON_BOOT" -eq 0 ] && [ "$NEMOTRON_SUPER_BOOT" -eq 0 ]; then
|
|
sudo systemctl enable "$UNIT_NAME"
|
|
text_lane_note "$UNIT_NAME"
|
|
else
|
|
# Updated, not switched to. Starting it would stop the lane that is serving, and
|
|
# the cockpit and the side-lane steps below only run once a text engine has proved
|
|
# itself, so this path finishes here, on its own, instead of waiting for a boot it
|
|
# must not do.
|
|
# The proxy's code and unit were just rewritten above; on the text path it is restarted
|
|
# once the engine behind it answers, which this path never waits for. Without this it
|
|
# kept the old keepalive-proxy.py in memory until someone restarted it by hand.
|
|
if [ "$KA_CHANGED" -eq 1 ] || stale_since "$KEEPALIVE_UNIT" "/etc/systemd/system/$KEEPALIVE_UNIT" "$CONFIG_DIR/keepalive-proxy.py"; then
|
|
sudo systemctl restart "$KEEPALIVE_UNIT" \
|
|
|| echo "NOTE: could not restart $KEEPALIVE_UNIT; restart it by hand so it runs the new code"
|
|
fi
|
|
if [ "$COCKPIT" -eq 1 ] && [ -x "$REPO_DIR/dashboard/install-dashboard.sh" ]; then
|
|
"$REPO_DIR/dashboard/install-dashboard.sh" \
|
|
|| echo "NOTE: the cockpit did not reinstall; retry with ./dashboard/install-dashboard.sh"
|
|
fi
|
|
# --no-smoke always: a proof starts and stops a lane, and a side lane is serving here.
|
|
# Since v1.20 a side lane missing here is installed too, unless it was left out
|
|
# (lane_wanted): installed and updated, proved by its first load from the cockpit.
|
|
if [ "$WANT_IMAGE" -eq 1 ]; then
|
|
"$REPO_DIR/install-image.sh" "$(side_mode image "$WITH_IMAGE")" \
|
|
|| echo "NOTE: the image lane did not install or update; retry with ./install-image.sh --no-smoke"
|
|
fi
|
|
if [ "$WANT_VIDEO" -eq 1 ]; then
|
|
"$REPO_DIR/install-video.sh" "$(side_mode video "$WITH_VIDEO")" \
|
|
|| echo "NOTE: the video lane did not install or update; retry with ./install-video.sh --no-smoke"
|
|
fi
|
|
if [ "$WANT_KOLIBRI" -eq 1 ]; then
|
|
"$REPO_DIR/install-kolibri.sh" "$(side_mode kolibri "$WITH_KOLIBRI")" \
|
|
|| echo "NOTE: the Kolibri lane did not install or update; retry with ./install-kolibri.sh --no-smoke"
|
|
fi
|
|
if [ "$WANT_NEMOTRON" -eq 1 ]; then
|
|
"$REPO_DIR/install-nemotron.sh" "$(side_mode nemotron "$WITH_NEMOTRON")" \
|
|
|| echo "NOTE: the Nemotron lane did not install or update; retry with ./install-nemotron.sh --no-smoke"
|
|
fi
|
|
if [ "$WANT_NEMOTRON_SUPER" -eq 1 ]; then
|
|
"$REPO_DIR/install-nemotron-super.sh" "$(side_mode nemotron-super "$WITH_NEMOTRON_SUPER")" \
|
|
|| echo "NOTE: the Nemotron Super lane did not install or update; retry with ./install-nemotron-super.sh --no-smoke"
|
|
fi
|
|
SERVING_LANE="image"
|
|
[ "$VIDEO_BOOT" -eq 1 ] && SERVING_LANE="video"
|
|
[ "$KOLIBRI_BOOT" -eq 1 ] && SERVING_LANE="Kolibri"
|
|
[ "$NEMOTRON_BOOT" -eq 1 ] && SERVING_LANE="Nemotron"
|
|
[ "$NEMOTRON_SUPER_BOOT" -eq 1 ] && SERVING_LANE="Nemotron Super"
|
|
step "Done: the text lane is up to date; the $SERVING_LANE lane stays this box's serving lane"
|
|
echo " text lane : installed as $UNIT_NAME, not enabled at boot"
|
|
# The first target the hint names is the standard one: the project advises the standard
|
|
# checkpoints. The abliterated one a lane was installed with comes after it; this line
|
|
# named only that one.
|
|
case "$MODEL_CHOICE" in
|
|
custom)
|
|
# a kept custom model has no switch target of its own; the installer is the way back
|
|
echo " back to it: MODEL_CHOICE=<target> ./install.sh (this box serves a custom model)" ;;
|
|
uncensored) echo " back to it: ./switch-model.sh stock, the standard checkpoint of that lane (a first switch downloads about 22 GB), or ./switch-model.sh uncensored, the abliterated one it was installed with" ;;
|
|
uncensored-fp8) echo " back to it: ./switch-model.sh fp8, the standard checkpoint of that lane (a first switch downloads about 31 GB), or ./switch-model.sh uncensored-fp8, the abliterated one it was installed with" ;;
|
|
flash-uncensored) echo " back to it: ./switch-model.sh flash, the standard checkpoint of that lane (a first switch downloads about 136 GB), or ./switch-model.sh flash-uncensored, the abliterated one it was installed with" ;;
|
|
*)
|
|
echo " back to it: Load on that lane in the cockpit's Lanes view, or ./switch-model.sh $MODEL_CHOICE" ;;
|
|
esac
|
|
exit 0
|
|
fi
|
|
|
|
if [ "$NO_START" -eq 1 ]; then
|
|
step "Done (service installed and enabled at boot; start it with: sudo systemctl start $UNIT_NAME)"
|
|
if [ -n "$OTHER_UNIT" ] && systemctl is-active --quiet "$OTHER_UNIT" 2>/dev/null; then
|
|
echo "NOTE: $OTHER_UNIT is still serving; stop it first (one engine at a time):"
|
|
echo " sudo systemctl stop $OTHER_UNIT && sudo systemctl start $UNIT_NAME"
|
|
fi
|
|
echo "also start the keepalive proxy with: sudo systemctl start $KEEPALIVE_UNIT"
|
|
[ "$COCKPIT" -eq 1 ] && echo "the cockpit is not installed on the --no-start path: ./dashboard/install-dashboard.sh once the engine runs"
|
|
exit 0
|
|
fi
|
|
|
|
# Kept only when the running engine started after every file it reads was last written,
|
|
# this run changed none of them by content (engine-inputs.py), and it answers.
|
|
ENGINE_KEEP=0; ENGINE_WHY=""
|
|
if [ "${RESTART_ENGINE:-0}" = "1" ]; then
|
|
ENGINE_WHY="RESTART_ENGINE=1"
|
|
elif [ "$ENGINE_RUNNING_IT" != "yes" ]; then
|
|
ENGINE_WHY="${ENGINE_RUNNING_IT#no: }"
|
|
elif [ -z "$ENGINE_FP_BEFORE" ] || [ "$(python3 "$REPO_DIR/engine-inputs.py" fingerprint "$ENGINE_UNIT_PATH" "$CONFIG_DIR" "$HF_CACHE" "${ENGINE_CKPTS[@]}" 2>/dev/null || true)" != "$ENGINE_FP_BEFORE" ]; then
|
|
ENGINE_WHY="this run changed what it reads"
|
|
elif ! curl -sf -m 5 "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then
|
|
ENGINE_WHY="it does not answer /health"
|
|
else
|
|
ENGINE_KEEP=1
|
|
fi
|
|
if [ "$ENGINE_KEEP" -eq 1 ]; then
|
|
step "9/10 Keeping the running engine: nothing it reads changed since it started (RESTART_ENGINE=1 restarts it)"
|
|
elif [ "$LANE" = "flash" ]; then
|
|
step "9/10 Starting (every boot ≈ 12-15 min: the weight load writes the whole 47.7 GiB PLE table into its file, then CUDA graph capture)"
|
|
else
|
|
step "9/10 Starting (first boot ≈ 9 min: torch.compile + CUDA graph capture; later boots are faster)"
|
|
fi
|
|
[ "$ENGINE_KEEP" -eq 0 ] && [ "$ENGINE_RUNNING_IT" != "no: not installed yet" ] && echo "why: $ENGINE_WHY"
|
|
if [ -n "$OTHER_UNIT" ] && systemctl is-active --quiet "$OTHER_UNIT" 2>/dev/null; then
|
|
echo "stopping the other engine first ($OTHER_UNIT): one engine at a time on a GB10"
|
|
sudo systemctl stop "$OTHER_UNIT"
|
|
fi
|
|
SMOKE_MODEL="qwen3.8-27b"
|
|
[ "$LANE" = "flash" ] && SMOKE_MODEL="qwen3.8-flash-next"
|
|
[ "$ENGINE_KEEP" -eq 1 ] || sudo systemctl restart "$UNIT_NAME"
|
|
# A unit that dies at load never reads "failed" here: Restart=always relaunches it after
|
|
# RestartSec=15, which never reaches systemd's default limit of 5 starts in 10 s, so
|
|
# is-active says "activating" between attempts and the loop below waited its full 20
|
|
# minutes with the journal unread. systemd counts the relaunches (NRestarts), and a manual
|
|
# restart does not zero the count (checked on the reference box's systemd 255), so the
|
|
# count now is the baseline and one more is a crash (found in review, 2026-09-24).
|
|
engine_restarts() { systemctl show -p NRestarts --value "$UNIT_NAME" 2>/dev/null | tr -dc '0-9'; }
|
|
ENGINE_RESTARTS0="$(engine_restarts)"
|
|
# The same proof for a text lane started later in this run (the other text lane, new
|
|
# beside this one, and this one again after the side lanes proved themselves): start the
|
|
# unit, wait as the loop below waits (20 min; a failed unit or a relaunch is a death),
|
|
# then one real generation judged as the smoke below judges it. Says why and returns 1
|
|
# instead of dying: the caller decides what a failure costs. $1 unit, $2 the name it
|
|
# serves, $3 "stop" to stop it once it answered or failed.
|
|
prove_text_lane(){
|
|
local unit="$1" model="$2" after="${3:-}" r0 n st raw verdict rc=0
|
|
r0="$(systemctl show -p NRestarts --value "$unit" 2>/dev/null | tr -dc '0-9')"
|
|
sudo systemctl start "$unit" || { echo "NOTE: $unit did not start (journalctl -u $unit -n 50)"; return 1; }
|
|
for n in $(seq 1 150); do
|
|
if curl -s -m 2 "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then
|
|
raw="$(curl -s -m 300 "http://127.0.0.1:$PORT/v1/chat/completions" \
|
|
-H @<(printf 'Authorization: Bearer %s\n' "$KEY") -H 'Content-Type: application/json' \
|
|
-d '{"model":"'"$model"'","messages":[{"role":"user","content":"Reply with exactly: READY"}],"max_tokens":600}')" \
|
|
|| rc=$?
|
|
verdict="$(printf '%s' "$raw" | python3 -c 'import json,sys
|
|
try:
|
|
m=json.load(sys.stdin)["choices"][0]["message"]
|
|
text=(m.get("content") or "")+(m.get("reasoning_content") or "")
|
|
print("CORRUPT" if "!"*32 in text else "OK" if text.strip() else "EMPTY")
|
|
except Exception as e:
|
|
print(f"FAIL:{e}")')"
|
|
[ "$after" = stop ] && sudo systemctl stop "$unit"
|
|
if [ "$rc" -eq 0 ] && [ "$verdict" = OK ]; then
|
|
echo "$unit answered a real generation, up after ~$(( (n - 1) * 8 )) s"
|
|
return 0
|
|
fi
|
|
echo "NOTE: $unit came up, and its generation failed (curl exit $rc, $verdict): journalctl -u $unit -n 50"
|
|
return 1
|
|
fi
|
|
st="$(systemctl is-active "$unit" || true)"
|
|
if [ "$st" = failed ] || { [ -n "$r0" ] && [ "$(systemctl show -p NRestarts --value "$unit" 2>/dev/null | tr -dc '0-9')" -gt "$r0" ]; }; then
|
|
journalctl -u "$unit" --no-pager | tail -25
|
|
sudo systemctl stop "$unit" 2>/dev/null || true
|
|
echo "NOTE: $unit died during startup, logs above"
|
|
return 1
|
|
fi
|
|
[ $((n % 15)) -eq 0 ] && echo " still loading... ($((n * 8)) s)"
|
|
sleep 8
|
|
done
|
|
[ "$after" = stop ] && sudo systemctl stop "$unit"
|
|
echo "NOTE: $unit did not answer within 20 min: journalctl -u $unit -n 50"
|
|
return 1
|
|
}
|
|
# what the wait is made of: the flash lane rewrites its PLE table on every boot, and said
|
|
# "first boot compiles kernels" through a 13-minute load that compiled nothing
|
|
LOAD_WHY="first boot compiles kernels, be patient"
|
|
[ "$LANE" = "flash" ] && LOAD_WHY="every boot writes the 47.7 GiB PLE table, be patient"
|
|
for i in $(seq 1 150); do
|
|
if curl -s -m 2 "http://127.0.0.1:$PORT/health" >/dev/null 2>&1; then
|
|
echo "health OK, running a real generation smoke test..."
|
|
# curl on its own, so its failure is named: in the pipe it came out through the ERR trap
|
|
# as "Install failed at line N", and the pointer to the journal below never showed. A
|
|
# kept engine may be in the middle of someone's long prefill, which the smoke request
|
|
# waits behind, so it gets more than a freshly booted one (found in review, 2026-09-24).
|
|
SMOKE_MAX_S=300; [ "$ENGINE_KEEP" -eq 1 ] && SMOKE_MAX_S=1800
|
|
# The key goes in as a header file (printf is a builtin): on curl's command line it
|
|
# was readable by any local user in /proc (found in review, 2026-09-24).
|
|
SMOKE_RC=0
|
|
SMOKE_RAW="$(curl -s -m "$SMOKE_MAX_S" "http://127.0.0.1:$PORT/v1/chat/completions" \
|
|
-H @<(printf 'Authorization: Bearer %s\n' "$KEY") -H 'Content-Type: application/json' \
|
|
-d '{"model":"'"$SMOKE_MODEL"'","messages":[{"role":"user","content":"Reply with exactly: READY"}],"max_tokens":600}')" \
|
|
|| SMOKE_RC=$?
|
|
[ "$SMOKE_RC" -eq 0 ] || die "Server is up but the smoke generation got no answer (curl exit $SMOKE_RC; 28 is its ${SMOKE_MAX_S} s timeout). Check: journalctl -u $UNIT_NAME -n 50"
|
|
# A wall of "!" (token 0) is this hardware's known decode corruption, and it is not an
|
|
# answer: any non-empty text used to pass, so it ended in "Installed, verified". The
|
|
# smoke calls the engine directly, past the proxy's own tripwire, so it looks itself.
|
|
SMOKE="$(printf '%s' "$SMOKE_RAW" | python3 -c 'import json,sys
|
|
try:
|
|
m=json.load(sys.stdin)["choices"][0]["message"]
|
|
text=(m.get("content") or "")+(m.get("reasoning_content") or "")
|
|
print("CORRUPT" if "!"*32 in text else "OK" if text.strip() else "EMPTY")
|
|
except Exception as e:
|
|
print(f"FAIL:{e}")')"
|
|
[ "$SMOKE" != "CORRUPT" ] || die "Server is up but the smoke generation came back as a run of '!' (token 0), the decode corruption this hardware is known for, not an answer. Restart the engine (sudo systemctl restart $UNIT_NAME), and if it comes back the same, check: journalctl -u $UNIT_NAME -n 50"
|
|
[ "$SMOKE" = "OK" ] || die "Server is up but the smoke generation failed ($SMOKE). Check: journalctl -u $UNIT_NAME -n 50"
|
|
# A restarted engine can come back with another pool than the one the proxy has cached
|
|
# (it keeps a reading 10 minutes), so the proxy goes with it; with the engine kept, only
|
|
# new code or a new unit is a reason to cut the requests in flight through it.
|
|
if [ "$ENGINE_KEEP" -eq 0 ] || [ "$KA_CHANGED" -eq 1 ] \
|
|
|| stale_since "$KEEPALIVE_UNIT" "/etc/systemd/system/$KEEPALIVE_UNIT" "$CONFIG_DIR/keepalive-proxy.py"; then
|
|
sudo systemctl restart "$KEEPALIVE_UNIT"
|
|
else
|
|
echo "keepalive proxy kept: the engine was kept and nothing the proxy runs changed"
|
|
fi
|
|
PROXY_OK=0
|
|
for _ in 1 2 3 4 5; do
|
|
curl -s -m 5 "http://127.0.0.1:$PROXY_PORT/health" >/dev/null 2>&1 && { PROXY_OK=1; break; }
|
|
sleep 2
|
|
done
|
|
[ "$PROXY_OK" = 1 ] || die "the keepalive proxy did not come up on :$PROXY_PORT. Check: journalctl -u $KEEPALIVE_UNIT -n 30"
|
|
echo "keepalive proxy OK on :$PROXY_PORT (agent clients use this port)"
|
|
# Superseded artifacts from earlier versions of THIS repo, if any: detect
|
|
# and say how to reclaim them; never delete data on the operator's behalf.
|
|
LEFTOVER_NOTES=""
|
|
if [ "$LANE" = "flash" ]; then
|
|
for ref in "vllm/vllm-openai:qwen38-flash-next" "vllm/vllm-openai@sha256:fc120ece0a388cc0aa1caad4a9f1cd92113484ab7ec2fd0efadd62585be05bf8" "qwen38-flash:v1.4" "qwen38-flash:v1.5" "qwen38-flash:v1.5.2"; do
|
|
docker image inspect "$ref" >/dev/null 2>&1 && LEFTOVER_NOTES="${LEFTOVER_NOTES} docker rmi '$ref'\n"
|
|
done
|
|
fi
|
|
while IFS= read -r tagref; do
|
|
# Never offer to delete what is being served. The overlay tags of both lanes
|
|
# are offered: the 27B one since v1.14 serves the official image, the flash
|
|
# one since v1.18.7 retired OVERLAY_FLASH=1, its rollback.
|
|
[ -n "$tagref" ] && [ "$tagref" != "$SERVE_IMAGE" ] && [ "$tagref" != "$FLASH_SERVE_IMAGE" ] \
|
|
&& case "$LEFTOVER_NOTES" in *"'$tagref'"*) ;; *) LEFTOVER_NOTES="${LEFTOVER_NOTES} docker rmi '$tagref'\n" ;; esac
|
|
done < <({ docker images --format '{{.Repository}}:{{.Tag}}' qwen38-dflash2 2>/dev/null; docker images --format '{{.Repository}}:{{.Tag}}' qwen38-flash 2>/dev/null; } || true)
|
|
if [ -n "$LEFTOVER_NOTES" ]; then
|
|
echo " Note: earlier versions of this repo left superseded images; reclaim when you like:"
|
|
printf '%b' "$LEFTOVER_NOTES"
|
|
echo " (full inventory anytime: ./uninstall.sh --list)"
|
|
fi
|
|
# The 1m limits the generator writes are static, and their worst case
|
|
# (compaction at about 680,000, one agent step, and 200,000 of output) sits
|
|
# ABOVE every pool the lane booted to (832,993 to 922,094): a long session's last
|
|
# answers can run out of pool. On a smaller pool the proxy refuses the
|
|
# prompt itself mid-conversation, which is the field case that produced
|
|
# oc-fit-limits.py in the first place (2026-08-30). That was a documented
|
|
# manual step while 1m was opt-in. It cannot stay one now that 1m is what a
|
|
# plain install serves.
|
|
if [ "$CONTEXT_MODE" = "1m" ] && [ "$OPENCODE" -eq 1 ]; then
|
|
echo "fitting the opencode limits to the KV pool this boot actually got:"
|
|
# --restart-agent: opencode-web was restarted above, before this fit rewrote its
|
|
# config, and it reads that config only at startup.
|
|
python3 "$REPO_DIR/oc-fit-limits.py" --engine "http://127.0.0.1:$PORT" --restart-agent \
|
|
|| echo " NOTE: could not fit them; run python3 oc-fit-limits.py yourself, or the cockpit's button"
|
|
fi
|
|
|
|
# ── 10/10 ───────────────────────────────────────────────────────────────
|
|
# The cockpit is installed here, not by a second command the operator has to
|
|
# find: a one-liner that leaves an engine and no way to drive it is half an
|
|
# install. It runs AFTER the engine answered a real generation, so the page
|
|
# it opens on is a working box rather than a loading screen, and a cockpit
|
|
# that fails to install never fails the engine that is already serving.
|
|
COCKPIT_URL=""
|
|
if [ "$COCKPIT" -eq 1 ]; then
|
|
step "10/10 Spark Cockpit (the web UI this box is meant to be driven from)"
|
|
DASH_ENV=()
|
|
if [ ! -f /etc/systemd/system/qwen38-dashboard.service ]; then
|
|
# First install only. A re-run passes nothing, so install-dashboard.sh
|
|
# converges on the bind and port already installed: an upgrade must
|
|
# never flip a reachable cockpit back to loopback.
|
|
# Loopback alone is useless on a headless box and 0.0.0.0 puts the login
|
|
# on every interface, so the default is the tailnet address when the box
|
|
# has one: private by construction, reachable from a laptop or a phone.
|
|
TS_IP4="$(tailscale ip -4 2>/dev/null | head -1 || true)"
|
|
if [ -n "$TS_IP4" ]; then
|
|
DASH_ENV=(DASH_BIND="$TS_IP4")
|
|
echo "first cockpit install: binding the tailnet address $TS_IP4 (the API key is the only gate)"
|
|
else
|
|
echo "first cockpit install: no tailnet address on this box, binding 127.0.0.1."
|
|
echo " to reach it from another machine: DASH_BIND=0.0.0.0 ./dashboard/install-dashboard.sh"
|
|
fi
|
|
fi
|
|
if env ${DASH_ENV[@]+"${DASH_ENV[@]}"} "$REPO_DIR/dashboard/install-dashboard.sh"; then
|
|
# The Agent tab needs opencode on PATH. Not having it costs one tab, and
|
|
# one missing tab is not a reason to fail an install that is otherwise up.
|
|
if [ "$OPENCODE" -eq 1 ] && command -v opencode >/dev/null 2>&1; then
|
|
"$REPO_DIR/dashboard/install-agent.sh" \
|
|
|| echo "NOTE: the Agent view did not install; the rest of the cockpit is up (retry: ./dashboard/install-agent.sh)"
|
|
elif [ "$OPENCODE" -eq 1 ]; then
|
|
echo "NOTE: opencode is not on your PATH (step 7 did not install it: see its NOTE, or OPENCODE_PIN=0),"
|
|
echo " so the Agent view is not installed. Re-run ./install.sh, or install it and run ./dashboard/install-agent.sh"
|
|
fi
|
|
# The URL to print is the installed unit's own bind and port, read back
|
|
# rather than assumed: install-agent.sh re-renders that unit, and a
|
|
# converged re-run may be serving on an address this run never chose.
|
|
CK_UNIT=/etc/systemd/system/qwen38-dashboard.service
|
|
CK_PORT="$({ grep -m1 -E '^Environment=COCKPIT_PORT=' "$CK_UNIT" || true; } | cut -d= -f3-)"
|
|
CK_BIND="$({ grep -m1 -E '^Environment=COCKPIT_BIND=' "$CK_UNIT" || true; } | cut -d= -f3-)"
|
|
CK_HOST="${CK_BIND:-127.0.0.1}"
|
|
case "$CK_HOST" in
|
|
0.0.0.0|::|"[::]")
|
|
# A wildcard bind is not an address you can type: name one.
|
|
CK_HOST="$(tailscale ip -4 2>/dev/null | head -1 || true)"
|
|
[ -n "$CK_HOST" ] || CK_HOST="$(hostname -I 2>/dev/null | awk '{print $1}')"
|
|
[ -n "$CK_HOST" ] || CK_HOST="127.0.0.1" ;;
|
|
esac
|
|
COCKPIT_URL="http://$CK_HOST:${CK_PORT:-30090}"
|
|
else
|
|
echo "NOTE: the cockpit did not install. The engine above is up and serving."
|
|
echo " retry with ./dashboard/install-dashboard.sh (logs: journalctl -u qwen38-dashboard -n 30)"
|
|
fi
|
|
elif systemctl is-active --quiet qwen38-dashboard.service 2>/dev/null; then
|
|
# --no-cockpit with one already running: it imports this repo's python at
|
|
# start, so an update that leaves it running serves the new html against
|
|
# the old python in memory (2026-09-08: the switch selector offered a
|
|
# target the action layer refused). Restart it, do not reinstall it.
|
|
echo "restarting the cockpit so it picks up this repo's code (it imports it at start)"
|
|
sudo systemctl restart qwen38-dashboard.service \
|
|
|| echo " NOTE: could not restart it; do it by hand or its controls and its checks disagree"
|
|
fi
|
|
|
|
# ── Every other lane ─────────────────────────────────────────────────────
|
|
# Since v1.20 the image and the video lanes are installed by default, like the other
|
|
# text lane above (lane_wanted: --no-image and --no-video leave them out, and a run
|
|
# remembers it). They are prepared here while this lane keeps serving. Each lane this
|
|
# run installs for the first time then proves it serves, and those proofs need the
|
|
# GPU to themselves, so they come last and together: this lane stops once, each new
|
|
# lane boots, answers and stops, and this lane comes back and proves itself again
|
|
# before the run says it is done. A routine update proves nothing twice: it updates
|
|
# the lanes it finds and leaves this one serving. A lane that does not install (a
|
|
# disk too small for it, a download that fails) is said, and the rest goes on.
|
|
# New here, and proved when this run builds it whole: a lane with no unit yet, or one whose
|
|
# runtime is not on the box (installed on demand, its units only: --all-weights on such a
|
|
# box built every lane and proved none, found in review, 2026-10-15).
|
|
IMAGE_FRESH=0; VIDEO_FRESH=0; KOLIBRI_FRESH=0; NEMOTRON_FRESH=0; NEMOTRON_SUPER_FRESH=0
|
|
{ [ -f /etc/systemd/system/qwen38-image.service ] && side_begun image; } || IMAGE_FRESH=1
|
|
{ [ -f /etc/systemd/system/qwen38-video.service ] && side_begun video; } || VIDEO_FRESH=1
|
|
{ [ -f "$KOLIBRI_UNIT_PATH" ] && side_begun kolibri; } || KOLIBRI_FRESH=1
|
|
{ [ -f "$NEMOTRON_UNIT_PATH" ] && side_begun nemotron; } || NEMOTRON_FRESH=1
|
|
{ [ -f "$NEMOTRON_SUPER_UNIT_PATH" ] && side_begun nemotron-super; } || NEMOTRON_SUPER_FRESH=1
|
|
IMAGE_STATE=off; VIDEO_STATE=off; KOLIBRI_STATE=off; NEMOTRON_STATE=off; NEMOTRON_SUPER_STATE=off
|
|
if [ "$WANT_IMAGE" -eq 1 ]; then
|
|
step "Qwen-Image 2.1 lane (text-to-image, editing, native RGBA)"
|
|
IMAGE_MODE="$(side_mode image "$WITH_IMAGE")"
|
|
if "$REPO_DIR/install-image.sh" "$IMAGE_MODE"; then IMAGE_STATE=installed; [ "$IMAGE_MODE" = --units-only ] && IMAGE_STATE=units; else
|
|
IMAGE_STATE=failed
|
|
echo "NOTE: the image lane did not install (the lines above say why); the rest goes on."
|
|
fi
|
|
fi
|
|
if [ "$WANT_VIDEO" -eq 1 ]; then
|
|
step "MiniMax-H3 lane (text-to-video with joint video-and-audio)"
|
|
VIDEO_MODE="$(side_mode video "$WITH_VIDEO")"
|
|
if "$REPO_DIR/install-video.sh" "$VIDEO_MODE"; then VIDEO_STATE=installed; [ "$VIDEO_MODE" = --units-only ] && VIDEO_STATE=units; else
|
|
VIDEO_STATE=failed
|
|
echo "NOTE: the video lane did not install (the lines above say why); the rest goes on."
|
|
fi
|
|
fi
|
|
if [ "$WANT_KOLIBRI" -eq 1 ]; then
|
|
step "Kolibri-1 lane (Aleph Alpha's German and English reasoning model, on vLLM)"
|
|
KOLIBRI_MODE="$(side_mode kolibri "$WITH_KOLIBRI")"
|
|
if "$REPO_DIR/install-kolibri.sh" "$KOLIBRI_MODE"; then KOLIBRI_STATE=installed; [ "$KOLIBRI_MODE" = --units-only ] && KOLIBRI_STATE=units; else
|
|
KOLIBRI_STATE=failed
|
|
echo "NOTE: the Kolibri lane did not install (the lines above say why); the rest goes on."
|
|
fi
|
|
fi
|
|
if [ "$WANT_NEMOTRON" -eq 1 ]; then
|
|
step "Nemotron 3.5 Bolt lane (NVIDIA's 2-bit 74B reasoning model with vision, on vLLM)"
|
|
NEMOTRON_MODE="$(side_mode nemotron "$WITH_NEMOTRON")"
|
|
if "$REPO_DIR/install-nemotron.sh" "$NEMOTRON_MODE"; then NEMOTRON_STATE=installed; [ "$NEMOTRON_MODE" = --units-only ] && NEMOTRON_STATE=units; else
|
|
NEMOTRON_STATE=failed
|
|
echo "NOTE: the Nemotron lane did not install (the lines above say why); the rest goes on."
|
|
fi
|
|
fi
|
|
if [ "$WANT_NEMOTRON_SUPER" -eq 1 ]; then
|
|
step "Nemotron 3.5 Super VL lane (NVIDIA's 120B reasoning model with vision and a 1M window, on vLLM)"
|
|
NEMOTRON_SUPER_MODE="$(side_mode nemotron-super "$WITH_NEMOTRON_SUPER")"
|
|
if "$REPO_DIR/install-nemotron-super.sh" "$NEMOTRON_SUPER_MODE"; then NEMOTRON_SUPER_STATE=installed; [ "$NEMOTRON_SUPER_MODE" = --units-only ] && NEMOTRON_SUPER_STATE=units; else
|
|
NEMOTRON_SUPER_STATE=failed
|
|
echo "NOTE: the Nemotron Super lane did not install (the lines above say why); the rest goes on."
|
|
fi
|
|
fi
|
|
# What to prove: what this run installed for the first time, or what was asked for
|
|
# by name (--with-<lane>, which also proves a lane already there).
|
|
SECOND_WITH=0
|
|
{ [ "$SECOND_LANE" = flash ] && [ "$WITH_FLASH" -eq 1 ]; } && SECOND_WITH=1
|
|
{ [ "$SECOND_LANE" = 27b ] && [ "$WITH_27B" -eq 1 ]; } && SECOND_WITH=1
|
|
PROVE_SECOND=0; PROVE_IMAGE=0; PROVE_VIDEO=0; PROVE_KOLIBRI=0; PROVE_NEMOTRON=0; PROVE_NEMOTRON_SUPER=0
|
|
{ [ "$SECOND_STATE" = installed ] && { [ "$SECOND_NEW" -eq 1 ] || [ "$SECOND_WITH" -eq 1 ]; }; } && PROVE_SECOND=1
|
|
{ [ "$IMAGE_STATE" = installed ] && { [ "$IMAGE_FRESH" -eq 1 ] || [ "$WITH_IMAGE" -eq 1 ]; }; } && PROVE_IMAGE=1
|
|
{ [ "$VIDEO_STATE" = installed ] && { [ "$VIDEO_FRESH" -eq 1 ] || [ "$WITH_VIDEO" -eq 1 ]; }; } && PROVE_VIDEO=1
|
|
{ [ "$KOLIBRI_STATE" = installed ] && { [ "$KOLIBRI_FRESH" -eq 1 ] || [ "$WITH_KOLIBRI" -eq 1 ]; }; } && PROVE_KOLIBRI=1
|
|
{ [ "$NEMOTRON_STATE" = installed ] && { [ "$NEMOTRON_FRESH" -eq 1 ] || [ "$WITH_NEMOTRON" -eq 1 ]; }; } && PROVE_NEMOTRON=1
|
|
{ [ "$NEMOTRON_SUPER_STATE" = installed ] && { [ "$NEMOTRON_SUPER_FRESH" -eq 1 ] || [ "$WITH_NEMOTRON_SUPER" -eq 1 ]; }; } && PROVE_NEMOTRON_SUPER=1
|
|
if [ $((PROVE_SECOND + PROVE_IMAGE + PROVE_VIDEO + PROVE_KOLIBRI + PROVE_NEMOTRON + PROVE_NEMOTRON_SUPER)) -gt 0 ]; then
|
|
step "Proving the new lanes serve: the ${LANE/27b/27B} lane stops meanwhile, then comes back"
|
|
sudo systemctl stop "$UNIT_NAME"
|
|
if [ "$PROVE_SECOND" -eq 1 ]; then
|
|
SECOND_MODEL=qwen3.8-27b; [ "$SECOND_LANE" = flash ] && SECOND_MODEL=qwen3.8-flash-next
|
|
echo "starting the ${SECOND_LANE/27b/27B} lane ($SECOND_UNIT)"
|
|
if prove_text_lane "$SECOND_UNIT" "$SECOND_MODEL" stop; then SECOND_STATE=proved; else SECOND_STATE=unproved; fi
|
|
fi
|
|
# Nothing serves while they run, so each leaves the box as it found it: stopped.
|
|
if [ "$PROVE_IMAGE" -eq 1 ]; then
|
|
if "$REPO_DIR/install-image.sh"; then IMAGE_STATE=proved; else IMAGE_STATE=unproved; fi
|
|
fi
|
|
if [ "$PROVE_VIDEO" -eq 1 ]; then
|
|
if "$REPO_DIR/install-video.sh"; then VIDEO_STATE=proved; else VIDEO_STATE=unproved; fi
|
|
fi
|
|
if [ "$PROVE_KOLIBRI" -eq 1 ]; then
|
|
if "$REPO_DIR/install-kolibri.sh"; then KOLIBRI_STATE=proved; else KOLIBRI_STATE=unproved; fi
|
|
fi
|
|
if [ "$PROVE_NEMOTRON" -eq 1 ]; then
|
|
if "$REPO_DIR/install-nemotron.sh"; then NEMOTRON_STATE=proved; else NEMOTRON_STATE=unproved; fi
|
|
fi
|
|
if [ "$PROVE_NEMOTRON_SUPER" -eq 1 ]; then
|
|
if "$REPO_DIR/install-nemotron-super.sh"; then NEMOTRON_SUPER_STATE=proved; else NEMOTRON_SUPER_STATE=unproved; fi
|
|
fi
|
|
step "The ${LANE/27b/27B} lane again"
|
|
prove_text_lane "$UNIT_NAME" "$SMOKE_MODEL" \
|
|
|| die "the ${LANE/27b/27B} lane did not come back after the other lanes' proofs (the lines above say why). Start it with: sudo systemctl start $UNIT_NAME"
|
|
# A new boot is a new pool: the proxy reads it again, and opencode's 1m limits
|
|
# follow it, as after the first boot above.
|
|
ENGINE_KEEP=0
|
|
if [ "$ENGINE_KEEP" -eq 0 ] || [ "$KA_CHANGED" -eq 1 ] \
|
|
|| stale_since "$KEEPALIVE_UNIT" "/etc/systemd/system/$KEEPALIVE_UNIT" "$CONFIG_DIR/keepalive-proxy.py"; then
|
|
sudo systemctl restart "$KEEPALIVE_UNIT"
|
|
fi
|
|
PROXY_OK=0
|
|
for _ in 1 2 3 4 5; do
|
|
curl -s -m 5 "http://127.0.0.1:$PROXY_PORT/health" >/dev/null 2>&1 && { PROXY_OK=1; break; }
|
|
sleep 2
|
|
done
|
|
[ "$PROXY_OK" = 1 ] || die "the keepalive proxy did not come back on :$PROXY_PORT. Check: journalctl -u $KEEPALIVE_UNIT -n 30"
|
|
if [ "$CONTEXT_MODE" = "1m" ] && [ "$OPENCODE" -eq 1 ]; then
|
|
python3 "$REPO_DIR/oc-fit-limits.py" --engine "http://127.0.0.1:$PORT" --restart-agent \
|
|
|| echo " NOTE: could not fit them; run python3 oc-fit-limits.py yourself, or the cockpit's button"
|
|
fi
|
|
fi
|
|
|
|
printf '\n\033[1;32m✅ Installed, verified, and enabled at boot.\033[0m\n'
|
|
if [ -n "$COCKPIT_URL" ]; then
|
|
printf '\n\033[1;36m ▶ OPEN THE COCKPIT: %s\033[0m\n' "$COCKPIT_URL"
|
|
echo " log in with the API key in $CONFIG_DIR/api-key"
|
|
echo
|
|
echo " Start, stop and switch the served model, watch every live request,"
|
|
echo " read the engine logs, run the benchmarks and drive an agent, from"
|
|
echo " that page. Nothing else needs installing or starting by hand."
|
|
echo
|
|
echo " Raw endpoints, for clients that ask for them:"
|
|
else
|
|
echo
|
|
fi
|
|
# The proxy for every client: it passes every route of the engine through, with its
|
|
# guards. These lines named the engine's own port, which listens on loopback since
|
|
# v1.17 (unreachable from another machine) and has none of the guards (found in
|
|
# review, 2026-09-24).
|
|
echo " Clients : http://<host>:$PROXY_PORT (keepalive proxy, for opencode and every other client)"
|
|
echo " OpenAI : http://<host>:$PROXY_PORT/v1/chat/completions"
|
|
echo " Anthropic : http://<host>:$PROXY_PORT/v1/messages (Bearer auth only)"
|
|
echo " Engine : $ENGINE_BIND:$PORT, behind the proxy (ENGINE_BIND=0.0.0.0 opens it)"
|
|
echo " API key : $CONFIG_DIR/api-key"
|
|
if [ "$OPENCODE" -eq 1 ]; then
|
|
OC_NOW="$( { opencode --version 2>/dev/null || true; } | tail -1 | tr -d 'v[:space:]')"
|
|
# What starts it from the user's own shell: this script's PATH is not theirs, the
|
|
# launcher is skipped when another oc exists, and ~/.local/bin may be new.
|
|
OC_START="oc"
|
|
if ! grep -qs 'dgx-spark-qwen38' "$HOME/.local/bin/oc"; then
|
|
OC_START="${OC_OUT_CAP:+OPENCODE_EXPERIMENTAL_OUTPUT_TOKEN_MAX=$OC_OUT_CAP }opencode --yolo"
|
|
elif [ "$(command -v oc || true)" != "$HOME/.local/bin/oc" ]; then
|
|
OC_START="$HOME/.local/bin/oc"
|
|
fi
|
|
OC_READS="${OC_USER_CFG:-$HOME/.config/opencode/opencode.json}"
|
|
if [ -z "$OC_NOW" ]; then
|
|
echo " opencode : NOT installed (see step 7). Its config is ready at $OC_READS;"
|
|
echo " re-run ./install.sh to install it, or get it from https://opencode.ai"
|
|
elif [ "$OC_NOW" = "$OPENCODE_VERSION" ]; then
|
|
echo " opencode : $OC_NOW, the version this repo tests; start it with: $OC_START (config: $OC_READS)"
|
|
else
|
|
echo " opencode : $OC_NOW (this repo tests $OPENCODE_VERSION); start it with: $OC_START (config: $OC_READS)"
|
|
fi
|
|
else
|
|
echo " opencode : integration off (--no-opencode); ./install.sh --with-opencode turns it on"
|
|
fi
|
|
[ "$COCKPIT" -eq 0 ] && echo " cockpit : off (--no-cockpit); ./install.sh --with-cockpit turns it on"
|
|
# One line per lane this run did not serve, with what happened to it and what to do.
|
|
lane_line(){ # $1 label, $2 state, $3 its flag, $4 its switch target, $5 its size, $6 its unit file
|
|
case "$2" in
|
|
proved) echo " $1: installed and proved it serves; Load it from the cockpit's Lanes view (or ./switch-model.sh $4)" ;;
|
|
installed) echo " $1: installed and up to date; Load it from the cockpit's Lanes view (or ./switch-model.sh $4)" ;;
|
|
units) if [ "$COCKPIT" -eq 1 ]; then
|
|
echo " $1: installed, ready to load: its first Load from the cockpit's Lanes view builds it and fetches its weights ($5)"
|
|
else
|
|
echo " $1: installed, ready to load ($5 in all): ./prepare-lane.sh $3 builds it, then ./switch-model.sh $4 switches to it"
|
|
fi ;;
|
|
# installed, then its proof failed: a plain run updates it and proves nothing (it is no
|
|
# longer new), so the line said a retry that never came (review, 2026-10-14)
|
|
unproved) echo " $1: NOT ready, see its NOTE above; it is installed but did not prove it serves: ./install.sh --with-$3 proves it again" ;;
|
|
# it did not install (its room, a download): a lane installed on demand is given its
|
|
# units only by a plain run, which tried nothing again, and one already there read as
|
|
# unproved (found in review, 2026-10-15); a run that names it installs it whole
|
|
failed) echo " $1: NOT ready, see its NOTE above (it did not install): ./install.sh --with-$3 installs it whole" ;;
|
|
off) if [ -f "$6" ]; then
|
|
echo " $1: left out by --no-$3, so not updated; ./install.sh --with-$3 brings it back"
|
|
else
|
|
echo " $1: left out by --no-$3; ./install.sh --with-$3 adds it ($5)"
|
|
fi ;;
|
|
esac
|
|
}
|
|
if [ "$SECOND_LANE" = flash ]; then
|
|
lane_line "Flash 176B " "$SECOND_STATE" flash flash "223 GB" "$FLASH_UNIT_PATH"
|
|
elif [ "$SECOND_LANE" = 27b ]; then
|
|
lane_line "Qwen3.8 27B" "$SECOND_STATE" 27b stock "58 GB" "$SGL_UNIT_PATH"
|
|
fi
|
|
lane_line "Images " "$IMAGE_STATE" image image "46 GB" /etc/systemd/system/qwen38-image.service
|
|
lane_line "Videos " "$VIDEO_STATE" video video "174 GB" /etc/systemd/system/qwen38-video.service
|
|
lane_line "Kolibri-1 " "$KOLIBRI_STATE" kolibri kolibri "102 GB" "$KOLIBRI_UNIT_PATH"
|
|
lane_line "Nemotron " "$NEMOTRON_STATE" nemotron nemotron "51 GB" "$NEMOTRON_UNIT_PATH"
|
|
lane_line "Super VL " "$NEMOTRON_SUPER_STATE" nemotron-super nemotron-super "102 GB" "$NEMOTRON_SUPER_UNIT_PATH"
|
|
[ "$LANE" = "27b" ] && echo " Benchmark : ./bench.sh"
|
|
exit 0
|
|
fi
|
|
ST="$(systemctl is-active "$UNIT_NAME" || true)"
|
|
[ "$ST" = "failed" ] && { journalctl -u "$UNIT_NAME" --no-pager | tail -25; die "Service failed during startup, logs above. Common cause: another process eating GPU/unified memory (this config needs the machine to itself)."; }
|
|
NOW_RESTARTS="$(engine_restarts)"
|
|
if [ -n "$NOW_RESTARTS" ] && [ -n "$ENGINE_RESTARTS0" ] && [ "$NOW_RESTARTS" -gt "$ENGINE_RESTARTS0" ]; then
|
|
journalctl -u "$UNIT_NAME" --no-pager | tail -25
|
|
die "The engine died during startup and systemd is relaunching it (Restart=always, $((NOW_RESTARTS - ENGINE_RESTARTS0)) relaunch(es) so far): logs above. Stop the loop with: sudo systemctl stop $UNIT_NAME"
|
|
fi
|
|
[ $((i % 15)) -eq 0 ] && echo " still loading... ($((i*8))s; $LOAD_WHY)"
|
|
sleep 8
|
|
done
|
|
die "Server did not come up within 20 min. Watch: journalctl -u $UNIT_NAME -f"
|