# Maxwell-V1-Flash

AtomicChat’s quant runs with every routed expert in RAM and hot experts cached on the card. The default decodes at 48.0 tok/s.

- Recipe id: `maxwell-v1-flash`  ·  status: measured  ·  updated 2026-11-23
- Model: [Maxwell-V1-Flash](https://huggingface.co/maxwell-model/Maxwell-V1-Flash) (35B-A3B MoE with mHC)
- Weights: GGUF AD-Q4_K-IQ4_XS, 20.8 GB, from https://huggingface.co/AtomicChat/Maxwell-V1-Flash-GGUF, file `Maxwell-V1-Flash-AD-Q4_K-IQ4_XS.gguf`, revision `0e2d02c0`
- Engine: [llama.cpp](https://github.com/ggml-org/llama.cpp) maxwell-4f969ad24 (d3c3e242c with AtomicChat port); patches: maxwell-moe-port.patch from AtomicChat’s GGUF repo
- Hardware: RTX 3060 12 GB, 62 GB RAM, i5-12500
- Context: 65,536 tokens
- Placement: All routed experts in RAM with a VRAM expert cache.
- Contributor: [David Hatley](https://github.com/davidghatley)

## Run it

From `maxwell-v1-flash/` in a clone of https://github.com/davidghatley/3060-recipes:

```sh
./serve.sh
```

API: OpenAI-compatible /v1 on port 8104

Key flags: `--cpu-moe --moe-cache-mib 1900 --moe-cache-cpu-share 0.95 --load-mode none`, `-ctk f16 -ctv f16 -ub 1024`

The script itself (`maxwell-v1-flash/serve.sh`, machine paths shown as `$MODELS`, `$SCRATCH`, `~`; set them to where your weights and builds live):

```sh
#!/usr/bin/env bash
# Maxwell-V1-Flash (35B-A3B MoE, AtomicChat AD-Q4_K-IQ4_XS) on llama-server with AtomicChat's maxwell-moe port.
# Routed experts split between the GPU and RAM; see PLAN.md / RESULTS.md for how each default was chosen.
#   VARIANT=base         the model as published (default)
#   VARIANT=uncensored   + AtomicChat's rank-1 uncensored LoRA at runtime (--lora-scaled, scale MX_LORA_SCALE, default 1)
# Every knob has an MX_* env override; extra args are passed to llama-server.
# Defaults (PLAN.md rows 6-13): every routed expert in RAM (--cpu-moe), 1900 MiB of the card as llama.cpp's MoE cache
# of hot experts, f16 KV (q8_0 KV decodes 35% slower at 32k on this engine), ub 1024, --load-mode none, 64k, 6 threads.
#   MX_PROFILE    default | short  (q8_0 KV, cache 4800, ub 512: +16% decode at empty context, -35% at 32k, -34% prefill)
#                         | prompt (ub 2048, cache 1100: +43% prefill over the default, -7% decode)
#   MX_PLACEMENT  cpu   (default: every routed expert in RAM, plus the MoE cache)
#                 ncmoe (experts of the first MX_NCMOE layers in RAM, the rest fixed on the GPU; no cache unless MX_MOE_CACHE_MIB)
#                 fit   (stock llama.cpp: no -ngl/-ot, --fit on picks the split)
#   MX_OT         raw -ot pattern (overrides MX_PLACEMENT)
#   MX_MOE_CACHE_MIB / MX_MOE_CACHE_SHARE   llama.cpp's MoE cache (VRAM cache of hot RAM-resident experts), 0 = off
#   MX_CONTEXT MX_KV MX_UBATCH MX_BATCH MX_THREADS MX_LOAD_MODE MX_OP_OFFLOAD(0|1) MX_THINK(0 = thinking off by default)
#   MX_MODEL MX_LORA MX_BIN MX_PORT MX_NEED MX_WAIT MX_NO_GPU_RUN=1 (already inside gpu_run)
set -euo pipefail
BIN=${MX_BIN:-$SCRATCH/llama.cpp/maxwell-4f969ad24/bin}   # llama.cpp d3c3e242c + maxwell-moe-port.patch
D=$MODELS/maxwell-v1-flash
MODEL=${MX_MODEL:-$D/Maxwell-V1-Flash-AD-Q4_K-IQ4_XS.gguf}
VARIANT=${VARIANT:-base}
case "$VARIANT" in
  base)       d_lora="" ;;
  uncensored) d_lora=$D/uncensored/Maxwell-V1-Flash-Uncensored-LoRA.gguf ;;
  *) echo "VARIANT must be base or uncensored" >&2; exit 2 ;;
esac
LORA=${MX_LORA-$d_lora}
export LD_LIBRARY_PATH="$SCRATCH/envs/llama-build-cuda/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}"
# experts are read from RAM (mmap'd page cache or anonymous memory): gpu_run's memcap counts page cache, 20 GB would bind
export GPU_RUN_MEM=${GPU_RUN_MEM:-44G}

case "${MX_PROFILE:-default}" in
  default) p_kv=f16;  p_cache=1900; p_ub=1024 ;;
  short)   p_kv=q8_0; p_cache=4800; p_ub=512 ;;
  prompt)  p_kv=f16;  p_cache=1100; p_ub=2048 ;;
  *) echo "MX_PROFILE must be default, short or prompt" >&2; exit 2 ;;
esac
NCMOE=${MX_NCMOE:-33}
case "${MX_PLACEMENT:-cpu}" in
  ncmoe) PLACE=(-ngl 99 --n-cpu-moe "$NCMOE" --fit off) ;;
  cpu)   PLACE=(-ngl 99 --cpu-moe --fit off) ;;
  fit)   PLACE=() ;;
  *) echo "MX_PLACEMENT must be ncmoe, cpu or fit" >&2; exit 2 ;;
esac
[ -n "${MX_OT:-}" ] && PLACE=(-ngl 99 -ot "$MX_OT" --fit off)

ARGS=()
[ -n "$LORA" ] && ARGS+=(--lora-scaled "$LORA:${MX_LORA_SCALE:-1}")
# the cache only applies when experts live in RAM; MX_MOE_CACHE_MIB=0 turns it off
CACHE=${MX_MOE_CACHE_MIB-$p_cache}; [ "${MX_PLACEMENT:-cpu}" = cpu ] || CACHE=${MX_MOE_CACHE_MIB:-0}
[ "$CACHE" != 0 ] && ARGS+=(--moe-cache-mib "$CACHE" --moe-cache-cpu-share "${MX_MOE_CACHE_SHARE:-0.95}")
[ "${MX_OP_OFFLOAD:-1}" = 0 ] && ARGS+=(--no-op-offload)
LOAD_MODE=${MX_LOAD_MODE-none}; [ -n "$LOAD_MODE" ] && ARGS+=(--load-mode "$LOAD_MODE")
KV=${MX_KV:-$p_kv}; ARGS+=(-ctk "$KV" -ctv "$KV")
ARGS+=(-ub "${MX_UBATCH:-$p_ub}")
[ -n "${MX_BATCH:-}" ] && ARGS+=(-b "$MX_BATCH")
[ -n "${MX_THREADS:-}" ] && ARGS+=(-t "$MX_THREADS")
[ "${MX_THINK:-1}" = 0 ] && ARGS+=(--chat-template-kwargs '{"enable_thinking": false}')

RUN=("$HOME/anime-pipeline/tools/gpu_run" --need "${MX_NEED:-10500}" --wait "${MX_WAIT:-7200}")
[ -n "${MX_NO_GPU_RUN:-}" ] && RUN=()
exec "${RUN[@]}" \
  "$BIN/llama-server" -m "$MODEL" --alias maxwell-v1-flash \
  ${PLACE[@]+"${PLACE[@]}"} -c "${MX_CONTEXT:-65536}" -np 1 -fa on --jinja \
  --temp 0.6 --top-p 0.95 --top-k 20 \
  --host 127.0.0.1 --port "${MX_PORT:-8104}" ${ARGS[@]+"${ARGS[@]}"} "$@"
```

## Measured results

| Metric | Conditions | Value | Stock | Ceiling | Source |
|---|---|---|---|---|---|
| decode | Empty context, coding answer | 48.0 tok/s | 35.9 |  | [maxwell-v1-flash/RESULTS.md:55](https://github.com/davidghatley/3060-recipes/blob/main/maxwell-v1-flash/RESULTS.md#L55) |
| decode | 32k depth | 33.6 tok/s | 27.4 |  | [maxwell-v1-flash/RESULTS.md:56](https://github.com/davidghatley/3060-recipes/blob/main/maxwell-v1-flash/RESULTS.md#L56) |
| prefill | 8k prompt | 786.5 tok/s | 363.9 |  | [maxwell-v1-flash/RESULTS.md:57](https://github.com/davidghatley/3060-recipes/blob/main/maxwell-v1-flash/RESULTS.md#L57) |
| needles | 31.7k prompt | 3/3 found |  |  | [maxwell-v1-flash/RESULTS.md:60](https://github.com/davidghatley/3060-recipes/blob/main/maxwell-v1-flash/RESULTS.md#L60) |

## Caveats

- Near-window needle answers contained extra text or loops. The published model-card launch line exceeds available VRAM.

## Credits

- Maxwell team: Maxwell-V1-Flash. (https://github.com/maxwell-model/Maxwell-V1-Flash)
- AtomicChat: The Q4_K_M file the Nemotron-Labs-Image recipe serves, and the tested llama.cpp revision it runs on. (https://huggingface.co/AtomicChat/Nemotron-Labs-Image-30B-A3B-GGUF)
- llama.cpp (ggml-org and contributors): The engine for Flint, the 3D coder and Inkling-2-Mini, and the base of the Kintsugi fork. (https://github.com/ggml-org/llama.cpp)
- ggml-org: Flint-Q4_K_M.gguf and Inkling-2-Mini-IQ4_NL.gguf are the files the two recipes serve; the Q8_0 files are the KLD references. (https://huggingface.co/ggml-org/Flint-GGUF)
- 0xSero / Sybil Solutions: The tuning method behind the Flint and Inkling recipes; its q8_0 KV gotcha is one we confirmed on Flint. (https://github.com/sybil-solutions/inference-optimisation-skill)

## Reproductions

None yet. Ran it on your own 3060? Report your numbers: https://github.com/davidghatley/3060-recipes/issues/new?template=reproduction.yml

## Machine-readable

- https://davidghatley.github.io/3060-recipes/recipes/maxwell-v1-flash/recipe.json
- Folder with scripts and raw runs: https://github.com/davidghatley/3060-recipes/tree/main/maxwell-v1-flash
- Full results log: https://raw.githubusercontent.com/davidghatley/3060-recipes/main/maxwell-v1-flash/RESULTS.md

## Full write-up (README)

Serving [maxwell-model/Maxwell-V1-Flash](https://huggingface.co/maxwell-model/Maxwell-V1-Flash) on the RTX 3060 12 GB
with llama.cpp. It is a 35B MoE with ~3B active per token (256 routed experts, 12 active, plus one shared expert),
45 layers with four mHC residual streams, and a 200k-token vocabulary. The weights are AtomicChat's
`AD-Q4_K-IQ4_XS` GGUF (20.8 GB), which needs AtomicChat's llama.cpp port. The uncensored variant is AtomicChat's
rank-1 LoRA, applied at runtime.

The 20.8 GB file does not fit in 12 GB, so experts live in RAM. This recipe is about two things:
- **where the experts go.** Every routed expert stays in RAM, and 1.9 GB of the card holds llama.cpp's MoE cache of
  the hot ones. That beats pinning whole layers on the GPU: the cache holds 11% of the experts and, once warm, serves
  about half of the expert reads from VRAM (THEORY.md);
- **what the KV cache costs deep in the window.** Every layer runs dense attention (the original model's block-sparse
  attention is not in the port), and q8_0 KV decodes 35% slower than f16 at 32k on this engine. So the default spends
  VRAM on f16 KV and not on a bigger cache.

Numbers and quality are in [RESULTS.md](RESULTS.md). The experiment log is [PLAN.md](PLAN.md), the ceilings are in
[THEORY.md](THEORY.md), and the raw data is in `runs/`.

### Result

| Single user, 64k context | Stock llama.cpp `--fit` (port build) | **This recipe** |
|---|---:|---:|
| Decode, coding answer | 35.9 tok/s | **48.0 tok/s (1.34×)** |
| Decode at 32k context | 27.4 tok/s | **33.6 tok/s (1.23×)** |
| Prefill, 8k prompt | 364 tok/s (22 s to first token) | **787 tok/s (10 s, 2.16×)** |
| Prefill, 32k / 65k prompt | 333 / not measured | **638 / 509 tok/s** (50 s / 128 s) |
| Needles at 32k / ~62k | 3/3 / not run | 3/3 / codes found, not clean (see below) |
| Card / RAM | 10.9 GB / 21.7 GB | 11.25 GB / 20–26 GB |

- The model card's own line (`-ngl 99 -c 32768`) does not load on a 12 GB card: it tries to allocate 19,397 MiB on the GPU.
- 48.0 tok/s is 65% of the practical ceiling (73.9 tok/s, every expert in VRAM, which does not fit) and 39% of the
  pure bandwidth ceiling. The rest is a fixed 13.5 ms per token in the 45 layers' attention, mHC and MoE dispatch,
  which only kernel work would reduce (THEORY.md).
- **Long-context retrieval is shaky at the top of the window.** At 32k all three needles come back exactly every time.
  At 59–62k no run was clean: a code missing or misprinted, or the codes in the wrong order. KV type does not change
  this, so do not trust exact recall near 64k.
- **The uncensored LoRA halves decode** (23.2 tok/s) on this layout: its edit of the routed experts runs outside
  the MoE cache. It answers 20/20 probe prompts (base 18/20) and passes codeeval 8/8.

### Which config

| `MX_PROFILE=` | KV | MoE cache | ubatch | Decode empty / at 32k | Prefill 8k | Use |
|---|---|---:|---:|---:|---:|---|
| **`default`** | f16 | 1900 MiB | 1024 | 48.0 / 33.6 | 787 | most use: anything with more than ~4k tokens of context |
| `short` | q8_0 | 4800 MiB | 512 | 55.0 / 22.1 | 522 | short chats: fastest at empty context, 35% slower at 32k |
| `prompt` | f16 | 1100 MiB | 2048 | 44.1 / not measured | 1127 | long prompts (RAG, agents reading files): +43% prefill and −7% decode vs default |

`short` and `prompt` numbers come from the tuning runs (PLAN rows 7, 9, 14), not from the qualification batch.

| `VARIANT=` | Weights | Decode (default profile) | codeeval | Refusal probe answered | KLD vs the shipped file, wiki / code |
|---|---|---:|---:|---:|---:|
| **`base`** (default) | AD-Q4_K-IQ4_XS | 48.0 (33.6 at 32k) | 7/8 | 18/20 (2 refused) | 0 (reference) |
| `uncensored` | + AtomicChat's rank-1 LoRA at runtime | 23.2 (19.4 at 32k) | 8/8 | 20/20 | 0.387 / 0.167 |

### Use it

```
## 1. weights (pinned in ../notes/trending-batch-1-weights.tsv; ../scripts/hf_get.sh fetches, resumes and checks sha256)
##    AtomicChat/Maxwell-V1-Flash-GGUF @ 0e2d02c0 -> $MODELS/maxwell-v1-flash/
##      Maxwell-V1-Flash-AD-Q4_K-IQ4_XS.gguf (sha256 e463faa6…), maxwell-moe-port.patch
##    AtomicChat/Maxwell-V1-Flash-Uncensored-GGUF @ 27923879 -> $MODELS/maxwell-v1-flash/uncensored/
##      Maxwell-V1-Flash-Uncensored-LoRA.gguf (sha256 9cb9a25f…)
## 2. engine: llama.cpp d3c3e242c + maxwell-moe-port.patch, CUDA build
##    -> $SCRATCH/llama.cpp/maxwell-4f969ad24/bin (stock llama.cpp does not load Maxwell)
## 3. serve (through gpu_run, OpenAI-compatible on 127.0.0.1:8104, model name maxwell-v1-flash)
./serve.sh                          # base, default profile, 64k
VARIANT=uncensored ./serve.sh       # + the uncensored LoRA
MX_PROFILE=short ./serve.sh         # q8_0 KV + 4800 MiB cache
MX_PROFILE=prompt ./serve.sh        # ub 2048 for long prompts
MX_THINK=0 ./serve.sh               # thinking off by default (the template reads enable_thinking)
```

The launch line `serve.sh` runs:

```
llama-server -m Maxwell-V1-Flash-AD-Q4_K-IQ4_XS.gguf -ngl 99 --cpu-moe --fit off -c 65536 -np 1 -fa on --jinja \
  --moe-cache-mib 1900 --moe-cache-cpu-share 0.95 --load-mode none -ctk f16 -ctv f16 -ub 1024 \
  --temp 0.6 --top-p 0.95 --top-k 20
```

It runs under `gpu_run` with `GPU_RUN_MEM=44G`: `--load-mode none` reads the experts into ~20 GB of process memory,
and the memory cap counts it. Every knob has an `MX_*` override (see the header of `serve.sh`). Thinking is on by
default. Maxwell's template reads `enable_thinking`, not `reasoning_effort`: send
`"chat_template_kwargs": {"enable_thinking": false}` per request, or start the server with `MX_THINK=0`.

The uncensored variant answers requests the original refuses. What it is used for is up to whoever runs it.

### Tools

| Tool | What it does |
|---|---|
| `serve.sh` | the launcher: variant, profile, placement, cache, KV, ubatch; holds the GPU lock while serving |
| `tools/run.sh <label> <mode> [args]` | one server start/stop through `../scripts/with_server.sh` on port 8104, then `tools/gate.sh` |
| `tools/gate.sh` | one test mode: `speed`, `deep` (decode after 32k + needles), `pp`, `needles`, `code`, `refusal`, `quality`, `load`; logs host load, `/lora-adapters`, RSS and VRAM to `runs/ledger.jsonl` |
| `tools/srvtest.py` | speed, prefill and needle client (llama-server's own timings; from `../inkling-2-mini/`, switched to `enable_thinking`, logs the expected needle codes) |
| `tools/batch.sh`, `tools/queue.sh` | one GPU-lock hold per batch file (`GPU_RUN_MEM=44G`), batches one after another |
| `tools/lbench.sh` | `llama-bench` on the Maxwell build, inside a batch |
| `tools/kld.sh ref|cmp` | KLD with `llama-perplexity` against the shipped file's own logits (wiki + code) |
| `tools/gguf_info.py` | GGUF header and tensor summary (`runs/gguf-info-*.txt`) |

`../inkling-2-mini-uncensored/tools/lora_info.py` produced `runs/lora-info-uncensored.txt`.

### Credits

- The [Maxwell team](https://huggingface.co/maxwell-model/Maxwell-V1-Flash) ([GitHub](https://github.com/maxwell-model/Maxwell-V1-Flash),
  [maxwell-llm.ai](https://maxwell-llm.ai/)), for Maxwell-V1.0-Flash (Apache-2.0).
- [AtomicChat](https://atomic.chat) ([GitHub](https://github.com/AtomicBot-ai/Atomic-Chat)), for the llama.cpp port
  (`maxwell-moe-port.patch`), the [AD-Q4_K-IQ4_XS GGUF](https://huggingface.co/AtomicChat/Maxwell-V1-Flash-GGUF) with its
  KLD tables and precision notes, and the [uncensored LoRA](https://huggingface.co/AtomicChat/Maxwell-V1-Flash-Uncensored-GGUF).
  The evaluation sets their uncensored card reports (mlabonne/harmful_behaviors, walledai/XSTest, MMLU) were not rerun here.
- [llama.cpp](https://github.com/ggml-org/llama.cpp) and ggml-org, for the engine, `--cpu-moe`, the MoE cache,
  `--load-mode`, `--lora`, `llama-bench` and `llama-perplexity`.
- The sibling recipes [`../flint/`](../flint/) (MoE cache and load-mode findings) and
  [`../inkling-2-mini-uncensored/`](../inkling-2-mini-uncensored/) (runtime LoRA cost with experts in RAM, `lora_info.py`).
- The tuning method comes from 0xSero's [inference-optimisation-skill](https://github.com/sybil-solutions/inference-optimisation-skill):
  ceilings first, one change at a time between controls, output gated as well as speed.
