Janus-35B-HERETIC / scripts /cap_ctx.sh
FoolDev's picture
feat: /v1 cap-ctx helper + strip_mtp/build.sh hardening (Thanatos parity)
26f1c69
Raw
History Blame Contribute Delete
2.12 kB
#!/usr/bin/env bash
# Janus-35B — create a small-context local tag for OpenAI /v1 clients.
#
# Ollama's /v1/chat/completions (OpenAI-compatible) silently ignores the
# `options` field, so it loads at the baked default `num_ctx 1010000` and OOMs
# on <=~48 GB hosts. This bakes a local tag with num_ctx overridden to a
# loadable value (and num_batch 256), which any OpenAI /v1 client can point at.
# Reuses this repo's Modelfile verbatim (TEMPLATE / SYSTEM / stop params), only
# swapping the FROM line to the bundled blob and the num_ctx parameter.
#
# Usage:
# ./scripts/cap_ctx.sh # tag `janus`, num_ctx 4096
# CTX=8192 TAG=janus-cap ./scripts/cap_ctx.sh
# GGUF=/path/to/other.gguf ./scripts/cap_ctx.sh
#
# Requires: ollama, awk.
set -euo pipefail
CTX="${CTX:-4096}"
NBATCH="${NBATCH:-256}"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
MODELFILE="${ROOT}/Modelfile"
GGUF="${GGUF:-${ROOT}/Janus-35B-A3B.Q4_K_M.gguf}"
TAG="${TAG:-janus}"
if ! command -v ollama >/dev/null 2>&1; then echo "[!] ollama not found in PATH" >&2; exit 1; fi
if [[ ! -f "${MODELFILE}" ]]; then echo "[!] missing ${MODELFILE}" >&2; exit 1; fi
if [[ ! -f "${GGUF}" ]]; then
echo "[!] ${GGUF} not present (smudge the LFS pointer via './scripts/load_bundle.sh', or set GGUF=)" >&2
exit 1
fi
echo "[*] tag: ${TAG}"
echo "[*] gguf: ${GGUF}"
echo "[*] num_ctx: ${CTX} num_batch: ${NBATCH}"
TMP="$(mktemp -t janus35b-capctx.XXXXXX)"
trap 'rm -f "${TMP}"' EXIT
awk -v g="${GGUF}" -v c="${CTX}" -v b="${NBATCH}" '
/^FROM[[:space:]]/ && !done { print "FROM " g; done=1; next }
/^PARAMETER[[:space:]]+num_ctx[[:space:]]/ { print "PARAMETER num_ctx " c; print "PARAMETER num_batch " b; next }
{ print }
' "${MODELFILE}" > "${TMP}"
echo "[*] ollama create ${TAG} -f <patched modelfile>"
ollama create "${TAG}" -f "${TMP}"
echo
echo "[+] Done. ${TAG} is baked at num_ctx=${CTX} — usable from any OpenAI /v1 client:"
echo " curl http://localhost:11434/v1/chat/completions \\"
echo " -d '{\"model\":\"${TAG}\",\"messages\":[{\"role\":\"user\",\"content\":\"hi\"}]}'"