Procházet zdrojové kódy

adopt r35 (latest lab rev): full 3-fork pin profile + r35 4x-dcp4 recipe; image built on dgx5 (71m, checksum 8bb87348), boot gates green

Alexander Korolev před 1 měsícem
rodič
revize
9bf6e76e6c

+ 49 - 0
docker-images/glm53-jovian-r27/profiles/glm53-r35.env

@@ -0,0 +1,49 @@
+# Version profile: GLM-5.3-Flash r35 source lock (2026-09-11 cut, all forks).
+#
+# Referenced from recipes via `build_profile = "glm53-r35"`; merged over this
+# image dir's versions.env (profile wins, then recipe [build.versions] wins
+# last). Only the keys that differ from versions.env are listed — the rest
+# (CUDA base, torch/flashinfer, apt) stay at the image dir's pins.
+#
+# Pinned by commit + tree hash (the Dockerfile gates HEAD + HEAD^{tree} per
+# repo). SHA-only cut (no named branches at these tips; branch names on the
+# forks lag at r28). r35 is the latest published lock:
+#   rtx6kpro models/glm-5.3-flash/validation/swiglu-reviewed-composition-r35
+#   .source.lock — "R35 qualifies the public source composition with GLM
+#   DFlash2 TP4/DCP1 serving, C1/C8, cold 32K prefill, prefix restoration and
+#   focused GPU correctness tests" (qualified 2026-09-11, published image
+#   localinferencelab/vllm:jovian-judgement-community-20260911-r35).
+#
+# What moved over r31 (per the lab changelog in models/glm-5.3-flash.md):
+#   R33: shared-input NVFP4 split MoE prefill (eligible prefills share input
+#        quantization across routed experts; +8.6-8.9% 32K prefill on their
+#        RTX quartet).
+#   R35: MERGED B12X SWIGLU-CLAMP CORRECTION — R33/R34's split path omitted
+#        the model's SwiGLU clamp (runaway-generation risk); R35 fixes it
+#        without disabling the fast split path. We adopt r35 directly
+#        (never r33/r34).
+#   plus: VLLM_DEFAULT_MOE_BACKEND=b12x default, LMCache fs-eviction
+#   accounting (retired objects leave byte accounting, pending writes
+#   protected), DFlash2 K7 qualification.
+#
+# Build-dep gates verified against the r35 vLLM tree (de982a50, 2026-09-12):
+# cmake/external_projects listing identical to r31 (no dep add/remove),
+# FlashKDA still 3b225bf2 + in-tree packed-checkpoints patch, DeepGEMM tag
+# still 8b1392b9 (= our versions.env pin), requirements/cuda.txt still
+# torch 2.13.0 + flashinfer 0.6.17. fetch-deps.sh needs no resync.
+VLLM_PIN=de982a50c6a3e4718e5cf9f00423a92192718da1
+VLLM_TREE=6d5cc3490735a53e849a4f0909183cb5e3a22e8b
+VLLM_PRETEND_VERSION=0.1.dev0+glm53.r35.de982a50
+
+B12X_PIN=98086604c86ec1e78977e5023ce282ecb97ab8a7
+B12X_TREE=d963f030c72a426753d2afa412b35d29eeb045f7
+B12X_PRETEND_VERSION=0.1.dev0+glm53b12x.r35.98086604
+
+LMCACHE_PIN=29bc5a2efde737c436b04499eb62cd1776cebeec
+LMCACHE_TREE=5a88a1ea9d2627c76288d056e7193f7454669b64
+LMCACHE_VERSION=0.5.5.dev0+glm53checkpoints.29bc5a2e
+
+# Same r31+ behavior: empty on purpose — the r35 tree gates FlashKDA on the
+# packed-checkpoint API and applies its own in-tree patch (same pin + patch
+# as r31); our r27 unpatched checkout would fail the gate.
+FLASH_KDA_SRC_DIR=

+ 254 - 0
recipes/glm53-flash-r35-4x-dcp4/recipe.toml

@@ -0,0 +1,254 @@
+# r28 4x DCP4 cell (2026-09-08) — clone of the r27 4x-dcp4 recipe (160/176
+# RoCEnante, 46.8 t/s) retargeted at the FULL r28 source lock (cut 2026-09-06
+# ~18:30 UTC across all three forks): vLLM 62f6385c (prefill/decode
+# compute-time sharing + interleaved parallel prefills, chat-template
+# rendering parity, GLM boundary restore, partial prefix-cache hits),
+# b12x 7216f6b9 (21 commits over r27: GLM/DeepSeek loader fixes, W4A4 FC1
+# fusion, M8 route prep, M1 FC2 overlap, GDN/MHC perf), LMCache 934c287a
+# (3 MP-transfer robustness fixes). Same model/flags/KV pin; the image is
+# the r27 build dir with the named version profile profiles/glm53-r28.env
+# (clone-at-pin fetches each commit directly, the tree gates verify them).
+
+# GLM-5.3-Flash NVFP4 — local-inference-lab quant (vLLM) — 2× DGX Spark, TP=2.
+#
+# local-inference-lab mixed quant: NVFP4 routed experts (layers 3–44,
+# group-16) + MXFP8 MTP experts (layer 45) + W4A4 input scales. Best agent
+# quant so far: tool-eval-bench 89/100 (vs 85 LibertAIDAI, 90 official FP8).
+# Model: https://huggingface.co/local-inference-lab/GLM-5.3-Flash-NVFP4
+#        (~186 GB → 92.72 GiB weights/node; KV pinned at 10 GiB, see below)
+#
+# Image: glm53-flash-nvfp4-lab:local (docker-images/glm53-flash-nvfp4-lab/ —
+# day-0 arm64 image + NoPE-MLA mod + the four FujitsuPolycom lab-checkpoint
+# patches: model naming shim, modelopt MTP namespace fix, persistent_topk
+# CC-12.x guards). Their launch config is mirrored below.
+# PROVENANCE: https://github.com/FujitsuPolycom/glm53-flash-tp2-spark
+#             (Apache-2.0; see patches/UPSTREAM.md) + forum 381350 #41.
+#
+# Deviations from their launch script (intentional):
+#   * no --kda-prefill-backend flashkda (needs their base-image patch — skipped)
+#   * --kv-cache-dtype fp8_ds_mla instead of `fp8` (same packed layout; this
+#     spelling is what the NoPE-MLA mod booted with on the LibertAIDAI stack)
+#   * --language-model-only + no mm-renderer patch/env (text-only)
+#   * no bundled NCCL/LD_PRELOAD, no NCCL_* fabric block (our switched fabric
+#     is configured via [nccl.ds4] + launcher GID auto-detect)
+#   * no --moe-backend marlin: their proven stack uses the default backend for
+#     THIS quant and reports clean evals. Sanity-check output for token loops
+#     anyway (the silent FP4 MoE corruption gotcha) before trusting a new node.
+#   * flashinfer autotune disabled via --kernel-config (their proven boot);
+#     VLLM_ENGINE_READY_TIMEOUT_S stays high regardless.
+#
+# Boot success markers (engine log, in order):
+#   "Model loading took 92.72 GiB" → "[quantprobe] ... algo=MXFP8" (MTP fix
+#   active; algo=None means broken) → "GPU KV cache size: 1,164,369 tokens" →
+#   "Application startup complete". ~700 s sequential weight load.
+#
+# Test request: chat completions need "chat_template_kwargs":{"reasoning_effort"
+# :"low"} — omitted/other values select MAX reasoning effort (empty content on
+# short max_tokens).
+#
+# Optional: instanttensor loader (~30 s weight load vs ~700 s):
+#   FROM glm53-flash-nvfp4-lab:local + pip install --no-deps --no-build-isolation
+#   instanttensor==0.1.9, then add --load-format instanttensor (--no-deps is
+#   required: resolution would downgrade the image's NCCL).
+#
+# PREREQUISITES: weights cached on both nodes:
+# [A/B CELL 2026-09-03] ship recipe verbatim, checkpoint swapped to the lab
+# non-Spark NVFP4 (isolates checkpoint from image lineage vs the lab-image cell).
+# [BISECT A2 2026-09-03] EXACT 90/100 recipe (236ce5a) + instanttensor + JIT
+# mounts, on the CURRENT eugr-patched image. Isolates image lineage from the
+# execution-env/flag cluster (AOT/V2/b12x/card-env). Comparator: 124/138.
+# GLM-5.3-Flash NVFP4-Spark — local-inference-lab quant with the speculative
+# layers embedded — 2× DGX Spark, TP=2.
+#
+# local-inference-lab/GLM-5.3-Flash-NVFP4-Spark (rev 06972cdee7280cec849aedf05a02062b3e870246):
+# NVFP4 routed experts (layers 3+, group-16) + NVFP4 MTP expert layer in the
+# separate model-mtp-0000x.safetensors shards (mtp_tokens: 5 per their
+# lil.yaml), amax/nonexpert/inputscales side shards, Glm5NextForConditionalGeneration.
+# THE "DSpark speculative embedded" checkpoint — no separate DFlash2 download
+# needed; lil.yaml: default_speculator mtp, dflash2_tokens 7 (r12 doc fr: their
+# standalone-Q: MTP:3 254 tok/s CC1, 333 Sieve, 94 steps/s).
+#
+# Image: glm53-flash-nvfp4-lab:local (same proven day-0 arm64 stack + NoPE-MLA
+# mod + modelopt MTP namespace patch used by the 92/100 lab lane). The MTP
+# layer here is NVFP4 (not MXFP8) — the quantprobe marker may print
+# algo=NVFP4/- different; algo=None = patch missed (fall back to 4p67 image).
+#
+# Deviations from lab (unchanged mechanics): same fabric/env/GMU/KV pinning.
+# lil.yaml launch mirrors: block 256, disable_flashinfer_autotune, mm data
+# mode — our text-only flags identical to glm53-flash-nvfp4-lab.
+#
+# Boot markers: "Model loading took ~XX GiB" → "[quantprobe] ..." →
+# "GPU KV cache size" → "Application startup complete".
+#
+# PREREQUISITES: weights on the NAS hub (175 GiB): hf download local-inference-lab/GLM-5.3-Flash-NVFP4-Spark
+
+engine = "vllm"
+name = "GLM-5.3-Flash NVFP4 (r35 img, lab ckpt, 4x DCP4)"
+docker_image = "glm53-jovian-r35:local"  # full r35 lock (build_profile) over the r27 image tree
+docker_image_dir = "glm53-jovian-r27"
+# NOTE: build_profile must stay a TOP-LEVEL key — a bare key after
+# [[extra_mounts]] would parse into the last mount table and be silently
+# ignored (2026-09-08).
+# FULL r28 source lock (2026-09-06 cut, all three forks): the named version
+# profile docker-images/glm53-jovian-r27/profiles/glm53-r28.env — vLLM
+# 62f6385c + b12x 7216f6b9 (21 commits over r27: GLM/DeepSeek loader fixes,
+# MoE perf) + LMCache 934c287a (3 MP-transfer fixes). Merged over the image
+# dir's versions.env and folded into the build checksum, so this is a
+# distinct image (tag glm53-jovian-r28:local) sharing the r27 build tree.
+# Clone-at-pin fetches each commit directly; the Dockerfile gates HEAD + tree
+# hash per repo. Both r28 branches are strictly ahead of their r27/r26 pins
+# (0 behind) — a clean superset. The r28 vLLM tree has NO requirements/cmake
+# changes vs r27 (verified via the GitHub compare API, 13 commits / 29 files),
+# so the fetch-deps.sh dep gates still hold.
+build_profile = "glm53-r35"
+# Required: the clean r12 image follows the solar contract (ENTRYPOINT []
+# + CMD bash), so the recipe carries the entrypoint (the old day-0-based
+# r12 image had ["vllm","serve"] baked in, which is why this was absent
+# until the clean rebuild).
+entrypoint = ["vllm", "serve"]
+model = "local-inference-lab/GLM-5.3-Flash-NVFP4"
+required_nodes = 4
+tensor_parallel_size = 4
+pipeline_parallel_size = 1
+distributed_backend = "mp"
+shm_size = "32gb"
+
+args = [
+    # R31 delta (their r28.1-r31 locks): adaptive prefill/decode
+    # compute-time sharing with a fixed 40% prefill floor.
+    "--prefill-compute-share", "0.4",
+    # Stable served name — quant-agnostic (shared across glm53 quants)
+    "--served-model-name", "glm53",
+    "--trust-remote-code",
+    "--distributed-executor-backend", "mp",
+    # GMU is ONLY a startup guardrail here (KV pool is pinned below): 0.90
+    # demands 109.46 GiB free on GB10's 121.63 GiB, but driver reserve +
+    # page cache routinely leave ~108.5 -> flaky
+    # "Free memory ... less than desired" boot deaths (this was the class
+    # of the old "54-second death"), and post-crash reruns see ~106.6 GiB.
+    # 0.82 = 99.7 GiB, below any realistic dip; does NOT change what gets
+    # allocated (weights ~93 + pinned KV 10 + activations).
+    # 0.88 (not 0.90): the startup admission gate is free-mem >= GMU*total
+    # (107.0 vs 109.5 GiB); ~12 GiB of starting vLLM processes + docker
+    # daemon can push the 0.90 check under the line (2026-09-08, #48140).
+    # KV is explicitly pinned (--kv-cache-memory-bytes) so capacity is unchanged.
+    "--gpu-memory-utilization", "0.88",
+    # Pinned 10 GiB KV (≈1.16M tokens) — GMU sizing has no headroom at
+    # 92.72 GiB weights/node; pinning also keeps warmup off the swap path
+    "--kv-cache-memory-bytes", "17179869184",  # 16 GiB: 4x NVFP4 has the headroom (47.1 GiB weights/node vs 108 usable); 2x stays 10
+    "--decode-context-parallel-size", "4",
+    "--cp-kv-cache-interleave-size", "4",
+    # No --kv-cache-dtype: let the r12 fork pick its default (the explicit
+    # fp8 / fp8_ds_mla both failed auto-selection on this build).
+    # The GLM5Next model wires the B12X sparse-MLA backend (sm_120/sm_121)
+    # when the global backend is B12X (glm5next/nvidia/attention.py:
+    # _select_sparse_backend); the sm12x auto-priority list never offers it
+    # (FLASHINFER_MLA_SPARSE_SM120 only supports head 576, not GLM's 512).
+    "--attention-backend", "B12X",
+    # pure I/O loader (kept across every config; 171 GB in ~5.5 min vs ~16 NFS)
+    "--load-format", "instanttensor",
+    # [R17 FULL-CLUSTER TEST] lil manifest backends (quality gate: hardmode
+    # must stay ≥88; r12-era this cluster dropped it to 74 — r17 may carry
+    # the fix through — one boot decides).
+    "--block-size", "256",
+    # FINAL BISECT (2026-09-03, hardmode 176pt, r17 img):
+    #   knobs-only 87: d0 c1 24.1, d8192 23.8
+    #   +moe b12x  88: d0 c1 23.5, d8192 26.6  <- SHIP (2 pts d8192)
+    #   +linear b12x 44: W4A4 linear kernel destroys numerics (param-precision 0%)
+    #   +align     88: but d0 c1 18.6 (-5) — perf-negative, dropped
+    # (all three together = 44-74; the lab needs its private packed package)
+    "--max-model-len", "524288",
+    "--max-num-seqs", "16",
+    "--max-num-batched-tokens", "4096",
+    "--enable-chunked-prefill",
+    "--async-scheduling",
+    "--enable-prefix-caching",
+    # NO --disable-custom-all-reduce here: in the r27 fork the RoCEnante
+    # adapter is gated on the custom-all-reduce enable flag
+    # (use_roce_allreduce = use_custom_allreduce && VLLM_ENABLE_ROCE_ALLREDUCE).
+    # On 2x/4x 1-GPU-node clusters vLLM's own CUDA-IPC custom AR is functionally
+    # inert (no cross-node P2P), so dropping the flag only opens the b12x path;
+    # the b12x-PCIe branch stays off (VLLM_ENABLE_PCIE_ALLREDUCE defaults False).
+    # Their proven boot: no flashinfer autotune, no CuTe-DSL warmup
+    "--kernel-config", """
+'{"enable_cutedsl_warmup":false,"enable_flashinfer_autotune":false}'""",
+    # Built-in MTP draft, 3 tokens (the r12-qualified "mtp:3" mode — their
+    # x86 numbers: 254 tok/s CC1, 2.37 accept; the checkpoint embeds up to
+    # 5 via the model-mtp-0000x shards but 3 is the verified depth). This is
+    # the checkpoint's own MTP head (Glm5NextMTPModel), NOT dspark — dspark
+    # is the DeepSeek-V4 family's mechanism; GLM's other r12 mode is
+    # dflash2:7 with a separate trained draft checkpoint.
+    # The draft model's vllm_config takes its attention backend from the
+    # SPECULATIVE config, not the global flag (eagle/utils.py:
+    # _make_eagle_draft_vllm_config) — B12X here mirrors the main model's.
+    "--speculative-config", """
+'{"method":"mtp","num_speculative_tokens":3,"attention_backend":"B12X"}'""",
+    "--language-model-only",
+    # MTP + CUDA graphs degrades OUTPUT QUALITY on the glm53 day-0 dev build
+    # (forum #381350/#44, CONFIRMED by A/B bench 2026-08-28: same seed/flags,
+    # graphs on = 89/100, eager = 92/100; decode unchanged 28.4 t/s @ c1,
+    # c2 -7%, TTFT +1.6s). The b12x glm52 stack does NOT need this (its
+    # graphs+MTP combo benches clean at 100/100) — bug is build-specific.
+    # graphs moved BEFORE tool-call-parser; enforce-eager removed for the
+    # r17-graphs test (bisect A2 was 88/100 eager; graphs+MTP fix is public
+    # in r17 refs? verify by bench).
+    "--tool-call-parser", "glm47",
+    "--enable-auto-tool-choice",
+    "--reasoning-parser", "glm45",
+]
+
+[env]
+
+# R31 lock: 16 NCCL channels (their qualified runtime).
+NCCL_NCHANNELS = "16"
+HF_HUB_OFFLINE = "1"
+# RoCEnante (b12x one-shot RoCE all-reduce/all-gather) — default on for r27
+# lanes since the 2026-09-08 A/B (4x DCP4: decode +31..+90%, quality 160 vs
+# 155, prefill within noise; specs/tech-architecture/glm53-recipe-state.md,
+# history/night-shifts/2026-09-07.md). Needs the CX-7 RoCE fabric (all of
+# ours); single-node serves skip it silently. Caps default 2MB AR / 16MB AG.
+VLLM_ENABLE_ROCE_ALLREDUCE = "1"
+# FlashInfer JIT (mxfp8_gemm_cutlass_sm120, ~12 kernels) compiles at first
+# boot with 12 parallel nvcc jobs -> OOM-killed (code 137) on GB10's
+# 121 GB unified while the 93 GB weights + 10 GB KV pin are resident.
+# MAX_JOBS caps ninja parallelism so the JIT fits in the remaining ~20 GB.
+MAX_JOBS = "2"
+# NoPE-MLA rope-pad runtime gate (mod baked into the image)
+VLLM_MLA_NOPE_PAD_ROPE = "1"
+VLLM_ENGINE_READY_TIMEOUT_S = "3600"
+# Upstream launch-script env (memory + compile knobs)
+PYTORCH_CUDA_ALLOC_CONF = "expandable_segments:True"
+VLLM_USE_AOT_COMPILE = "0"
+VLLM_USE_STANDALONE_COMPILE = "1"
+VLLM_USE_FLASHINFER_SAMPLER = "1"
+VLLM_USE_BREAKABLE_CUDAGRAPH = "0"
+TORCH_USE_RTLD_GLOBAL = "1"
+VLLM_NO_USAGE_STATS = "1"
+
+# Architecture (aarch64 / sm_121a DGX Spark)
+TORCH_CUDA_ARCH_LIST = "12.1a"
+FLASHINFER_CUDA_ARCH_LIST = "12.1f"
+CUTE_DSL_ARCH = "sm_121a"
+CMAKE_CUDA_ARCHITECTURES = "121"
+OMP_NUM_THREADS = "2"
+
+[[extra_mounts]]
+host = "~/sm121-cache/glm53-jit-121f/b12x"
+container = "/root/.cache/b12x"
+
+# JIT caches persist per-node across serves (was: cold /root/.cache per
+# container -> ~20 min flashinfer/torch recompile every serve). The host
+# dirs are shared between lanes of the same arch — each cache
+# self-namespaces by its engine version key internally.
+[[extra_mounts]]
+host = "~/sm121-cache/jit-121f/flashinfer"
+container = "/root/.cache/flashinfer"
+
+[[extra_mounts]]
+host = "~/sm121-cache/jit-121f/torchinductor"
+container = "/root/.cache/torchinductor"
+
+[[extra_mounts]]
+host = "~/sm121-cache/jit-121f/vllm"
+container = "/root/.cache/vllm"
+

+ 86 - 0
src/ansi.rs

@@ -0,0 +1,86 @@
+//! ANSI escape-sequence stripping — keeps bench/console logs readable in
+//! `sm121 report` and under grep/less (the pty-wrapped tool emits colors,
+//! cursor moves, and OSC titles).
+
+/// Strip ANSI escape sequences out of `buf` into `out`, in place. The
+/// consumed prefix is drained from `buf`; a trailing partial escape (a
+/// sequence split across chunk boundaries) is left in `buf` as the carry
+/// for the next call. Handles CSI (`ESC [ ... final`), OSC (`ESC ] ... BEL`
+/// or `ST`), and generic escapes with intermediate bytes (`ESC ( B`).
+pub(crate) fn strip_ansi_step(buf: &mut Vec<u8>, out: &mut Vec<u8>) {
+    let n = buf.len();
+    let mut i = 0;
+    while i < n {
+        if buf[i] != 0x1b {
+            out.push(buf[i]);
+            i += 1;
+            continue;
+        }
+        let rest = &buf[i + 1..];
+        match rest.first() {
+            Some(b'[') => match rest.iter().skip(1).position(|c| (0x40..=0x7e).contains(c)) {
+                Some(p) => i += 1 + 1 + p + 1, // ESC [ params final
+                None => break,                 // incomplete: wait for more data
+            },
+            Some(b']') => match rest.iter().skip(1).position(|c| *c == 0x07 || *c == 0x1b) {
+                Some(p) => {
+                    i += 1 + 1 + p + 1;
+                    if rest[1 + p] == 0x1b {
+                        i += 1; // consume the backslash of the ST
+                    }
+                }
+                None => break,
+            },
+            None => break, // lone ESC at the chunk end
+            Some(_) => {
+                // Generic escape: intermediate bytes (0x20-0x2f), then one
+                // final byte — drop all of them.
+                let mut j = 1;
+                while j < rest.len() && (0x20..=0x2f).contains(&rest[j]) {
+                    j += 1;
+                }
+                if j < rest.len() {
+                    j += 1; // final byte
+                }
+                i += 1 + j;
+            }
+        }
+    }
+    buf.drain(..i);
+}
+
+/// One-shot ANSI strip (whole buffer at once; for files already on disk).
+pub(crate) fn strip_ansi(bytes: &[u8]) -> Vec<u8> {
+    let mut buf = bytes.to_vec();
+    let mut out = Vec::new();
+    strip_ansi_step(&mut buf, &mut out);
+    out
+}
+
+#[cfg(test)]
+mod tests {
+    use super::*;
+
+    #[test]
+    fn strip_ansi_removes_codes_keeps_text() {
+        let raw = b"\x1b[38;5;214mred\x1b[0m plain \x1b]0;title\x07osc \x1b]2;x\x1b\\st \x1b(Bc";
+        assert_eq!(strip_ansi(raw), b"red plain osc st c");
+        // nothing to strip
+        assert_eq!(strip_ansi(b"clean text"), b"clean text".to_vec());
+    }
+
+    #[test]
+    fn strip_ansi_survives_split_chunks() {
+        // the escape sequence straddles the chunk boundary
+        let a = b"ab\x1b[38;5;2"; // split inside a CSI parameter
+        let b2 = b"14mtext";
+        let mut ca = Vec::new();
+        ca.extend_from_slice(a);
+        let mut out = Vec::new();
+        strip_ansi_step(&mut ca, &mut out);
+        ca.extend_from_slice(b2);
+        strip_ansi_step(&mut ca, &mut out);
+        assert_eq!(out, b"abtext");
+        assert!(ca.is_empty(), "no dangling carry: {ca:?}");
+    }
+}

+ 52 - 80
src/bench.rs

@@ -18,6 +18,7 @@ use std::time::{Duration, Instant, SystemTime, UNIX_EPOCH};
 
 use anyhow::Result;
 
+use crate::ansi::strip_ansi_step;
 use crate::config::{
     Config, Recipe, default_config_dir, load_recipe, local_path, select_cluster_by_name,
 };
@@ -173,62 +174,6 @@ fn pump<R: Read>(mut reader: R, to_console: bool, file: Arc<Mutex<fs::File>>) {
     }
 }
 
-/// Strip ANSI escape sequences out of `buf` into `out`, in place. The
-/// consumed prefix is drained from `buf`; a trailing partial escape (a
-/// sequence split across chunk boundaries) is left in `buf` as the carry
-/// for the next call. Handles CSI (`ESC [ ... final`), OSC (`ESC ] ... BEL`
-/// or `ST`), and generic escapes with intermediate bytes (`ESC ( B`).
-fn strip_ansi_step(buf: &mut Vec<u8>, out: &mut Vec<u8>) {
-    let n = buf.len();
-    let mut i = 0;
-    while i < n {
-        if buf[i] != 0x1b {
-            out.push(buf[i]);
-            i += 1;
-            continue;
-        }
-        let rest = &buf[i + 1..];
-        match rest.first() {
-            Some(b'[') => match rest.iter().skip(1).position(|c| (0x40..=0x7e).contains(c)) {
-                Some(p) => i += 1 + 1 + p + 1, // ESC [ params final
-                None => break,                 // incomplete: wait for more data
-            },
-            Some(b']') => match rest.iter().skip(1).position(|c| *c == 0x07 || *c == 0x1b) {
-                Some(p) => {
-                    i += 1 + 1 + p + 1;
-                    if rest[1 + p] == 0x1b {
-                        i += 1; // consume the backslash of the ST
-                    }
-                }
-                None => break,
-            },
-            None => break, // lone ESC at the chunk end
-            Some(_) => {
-                // Generic escape: intermediate bytes (0x20-0x2f), then one
-                // final byte — drop all of them.
-                let mut j = 1;
-                while j < rest.len() && (0x20..=0x2f).contains(&rest[j]) {
-                    j += 1;
-                }
-                if j < rest.len() {
-                    j += 1; // final byte
-                }
-                i += 1 + j;
-            }
-        }
-    }
-    buf.drain(..i);
-}
-
-/// One-shot ANSI strip (whole buffer at once; for files already on disk —
-/// see `report::serve`).
-pub(crate) fn strip_ansi(bytes: &[u8]) -> Vec<u8> {
-    let mut buf = bytes.to_vec();
-    let mut out = Vec::new();
-    strip_ansi_step(&mut buf, &mut out);
-    out
-}
-
 /// Run the bench tool in `cwd`, teeing stdout+stderr to the console and the
 /// log file; returns the exit code.
 ///
@@ -238,6 +183,16 @@ pub(crate) fn strip_ansi(bytes: &[u8]) -> Vec<u8> {
 /// lucky) while it runs clean on a tty, exactly as in an interactive
 /// terminal (2026-09-09). `script` is BSD/macOS form (the launcher is a
 /// Mac tool); if it is absent we fall back to the direct exec.
+///
+/// The pty makes the tool think it is interactive — rich redraws its
+/// spinner/progress bars in place (\r soup on one line) and that soup
+/// leaked into the saved .log, even shadowing real parser cells
+/// (glm53-flash-eugr-2x, 2026-09-12). `TTY_COMPATIBLE=0` is rich's own
+/// knob for this: the console renders non-interactively (progress bars
+/// stay silent during the run, one final frame at the end) while the pty
+/// keeps the deadlock workaround intact. `NO_COLOR=1` covers non-rich
+/// output. Verified locally under `script`: 1.3 KB/8 CR of soup → 141
+/// bytes/1 static final frame.
 fn run_tool(bin: &str, args: &[String], cwd: &Path, log_path: &Path) -> Result<i32> {
     let file = Arc::new(Mutex::new(fs::File::create(log_path)?));
     let mut cmd = if std::process::Command::new("/usr/bin/script")
@@ -247,8 +202,19 @@ fn run_tool(bin: &str, args: &[String], cwd: &Path, log_path: &Path) -> Result<i
         .output()
         .is_ok()
     {
+        // Wrap in `sh` + `stty -onlcr`: the macOS pty's ONLCR would turn every
+        // `\n` the tool writes into `\r\n` on disk, and the report viewer
+        // then renders each line twice (blank line after every line).
+        // `stty -onlcr` disables the post-processing at the source; `exec`
+        // replaces the shell so the tool keeps the pty and the exit code.
         let mut c = std::process::Command::new("/usr/bin/script");
-        c.args(["-q", "/dev/null", bin]);
+        c.arg("-q");
+        c.arg("/dev/null");
+        c.arg("sh");
+        c.arg("-c");
+        c.arg("stty -onlcr 2>/dev/null; exec \"$@\"");
+        c.arg("sh"); // $0 inside the -c script
+        c.arg(bin);
         c.args(args);
         c
     } else {
@@ -257,6 +223,8 @@ fn run_tool(bin: &str, args: &[String], cwd: &Path, log_path: &Path) -> Result<i
         c
     };
     cmd.current_dir(cwd);
+    cmd.env("TTY_COMPATIBLE", "0");
+    cmd.env("NO_COLOR", "1");
     cmd.stdout(Stdio::piped());
     cmd.stderr(Stdio::piped());
     let mut child = cmd.spawn()?;
@@ -456,6 +424,33 @@ mod tests {
         assert_eq!(sanitize("ok_name-2.v3"), "ok_name-2.v3");
     }
 
+    /// The non-interactive env must reach the child through the `script`
+    /// pty wrapper — rich reads TTY_COMPATIBLE from the child's env. Also:
+    /// `stty -onlcr` must hold, so the saved log is LF-only (CRLF made the
+    /// report viewer render every line twice).
+    #[test]
+    fn run_tool_passes_non_interactive_env() {
+        let tmp = std::env::temp_dir().join(format!("sm121-bench-env-test-{}", std::process::id()));
+        fs::create_dir_all(&tmp).unwrap();
+        let log = tmp.join("env.log");
+        let code = run_tool(
+            "sh",
+            &[
+                "-c".to_string(),
+                "echo TTY=$TTY_COMPATIBLE NO=$NO_COLOR".to_string(),
+            ],
+            &tmp,
+            &log,
+        )
+        .unwrap();
+        let body = fs::read_to_string(&log).unwrap();
+        let _ = fs::remove_dir_all(&tmp);
+        assert_eq!(code, 0, "exit code, log: {body:?}");
+        assert!(body.contains("TTY=0"), "TTY_COMPATIBLE lost: {body:?}");
+        assert!(body.contains("NO=1"), "NO_COLOR lost: {body:?}");
+        assert!(!body.contains('\r'), "pty ONLCR leaked CRLF: {body:?}");
+    }
+
     #[test]
     fn served_model_parsed_from_args() {
         let content = fs::read_to_string("recipes/glm53-flash-r27-spark/recipe.toml")
@@ -466,27 +461,4 @@ mod tests {
         r2.args = crate::pre_serve::RecipeArgs::List(vec!["--trust-remote-code".into()]);
         assert!(served_model(&r2).is_none());
     }
-
-    #[test]
-    fn strip_ansi_removes_codes_keeps_text() {
-        let raw = b"\x1b[38;5;214mred\x1b[0m plain \x1b]0;title\x07osc \x1b]2;x\x1b\\st \x1b(Bc";
-        assert_eq!(strip_ansi(raw), b"red plain osc st c");
-        // nothing to strip
-        assert_eq!(strip_ansi(b"clean text"), b"clean text".to_vec());
-    }
-
-    #[test]
-    fn strip_ansi_survives_split_chunks() {
-        // the escape sequence straddles the chunk boundary
-        let a = b"ab\x1b[38;5;2"; // split inside a CSI parameter
-        let b2 = b"14mtext";
-        let mut ca = Vec::new();
-        ca.extend_from_slice(a);
-        let mut out = Vec::new();
-        strip_ansi_step(&mut ca, &mut out);
-        ca.extend_from_slice(b2);
-        strip_ansi_step(&mut ca, &mut out);
-        assert_eq!(out, b"abtext");
-        assert!(ca.is_empty(), "no dangling carry: {ca:?}");
-    }
 }

+ 1 - 0
src/main.rs

@@ -6,6 +6,7 @@ use clap::Parser;
 fluent_i18n::i18n!("locales", fallback = "en");
 
 mod after_stop;
+mod ansi;
 mod before_serve;
 mod bench;
 mod builtin_scripts;

+ 4 - 4
src/report/page.html

@@ -49,11 +49,11 @@
   <input id="q" type="search" placeholder="Search recipes, models, images, labels…">
   <label>Group:
     <select id="group">
-      <option value="mq" selected>Model → Quant</option>
+      <option value="mq">Model → Quant</option>
       <option value="model">Model</option>
       <option value="quant">Quant</option>
       <option value="engine">Engine</option>
-      <option value="">None (flat)</option>
+      <option value="" selected>None (flat)</option>
     </select>
   </label>
   <label>TP:
@@ -224,7 +224,7 @@ for (const v of TPVALS) {
 }
 const S = {
   q: P.get("q") ?? "",
-  group: P.get("group") ?? "mq",
+  group: P.get("group") ?? "",
   sort: P.get("sort") ?? "name",
   dir: P.get("dir") ? +P.get("dir") : 1,
   size: [25, 50, 100, 0].includes(size0) ? size0 : 50,
@@ -241,7 +241,7 @@ document.getElementById("tp").value = S.tp;
 function syncUrl() {
   const p = new URLSearchParams();
   if (S.q) p.set("q", S.q);
-  if (S.group !== "mq") p.set("group", S.group);
+  if (S.group !== "") p.set("group", S.group);
   if (S.sort !== "name") p.set("sort", S.sort);
   if (S.dir !== 1) p.set("dir", String(S.dir));
   if (S.size !== 50) p.set("size", String(S.size));

+ 8 - 1
src/report/parse.rs

@@ -59,6 +59,13 @@ fn split_tokens(line: &str) -> impl Iterator<Item = &str> + '_ {
 pub(crate) fn parse_perf_box(content: &str) -> Vec<PerfCell> {
     let mut out = Vec::new();
     for line in content.lines() {
+        // Perf rows are table rows — box/md chrome with ≥3 column
+        // separators. llama-benchy progress/spinner frames embed the same
+        // `pp2048 tg128 @ d0` labels with no columns (they parsed as
+        // d=0/c=1/tg=0.0 and shadowed the real cells in lookups).
+        if line.matches(['|', '│']).count() < 3 {
+            continue;
+        }
         let Some(at) = line.find("@ d") else {
             continue;
         };
@@ -77,7 +84,7 @@ pub(crate) fn parse_perf_box(content: &str) -> Vec<PerfCell> {
         let nums: Vec<f64> = split_tokens(&line[at..])
             .filter_map(|tok| tok.replace(',', "").parse::<f64>().ok())
             .collect();
-        if nums.len() >= 4 {
+        if nums.len() >= 4 && nums[1] > 0.0 {
             out.push(PerfCell { d, c, tg: nums[1] });
         }
     }

+ 7 - 5
src/report/serve.rs

@@ -153,11 +153,13 @@ async fn report_file(
     match load_report(&state.config, &recipe, &file) {
         Some(text) => {
             // Strip ANSI escapes (old logs were saved raw; new ones are
-            // already clean — see `bench::strip_ansi_step`) and turn the
-            // rich Live display's \r frame separators into real newlines so
-            // progress lines read top-to-bottom instead of overprinting.
-            let clean = crate::bench::strip_ansi(text.as_bytes());
-            let clean = String::from_utf8_lossy(&clean).replace('\r', "\n");
+            // already clean) and normalize line ends: the old pty-saved
+            // logs carry CRLF (ONLCR) and the Live-soup ones bare \r —
+            // CRLF first, then lone \r, so nothing doubles.
+            let clean = crate::ansi::strip_ansi(text.as_bytes());
+            let clean = String::from_utf8_lossy(&clean)
+                .replace("\r\n", "\n")
+                .replace('\r', "\n");
             axum::response::Html(format!(
                 "<!doctype html><meta charset=\"utf-8\"><title>{recipe} — {file}</title>\
              <pre style=\"font:12px/1.45 ui-monospace,monospace;white-space:pre-wrap;\

+ 32 - 0
src/report/tests.rs

@@ -295,6 +295,38 @@ fn parse_perf_box_reads_both_table_shapes() {
     assert!(super::parse::parse_perf_box("no perf here").is_empty());
 }
 
+#[test]
+fn parse_perf_box_ignores_progress_spinner_soup() {
+    // llama-benchy redraws its progress bar on one \r-overwritten line that
+    // embeds the same `pp2048 tg128 @ d0` labels with no table columns —
+    // it used to parse as a bogus {d:0, c:1, tg:0.0} cell that shadowed the
+    // real one in first-match lookups (glm53-flash-eugr-2x).
+    let soup = "⠋ Initializing… ━━━━━━━━━━━━━━━━━━━━━━  0/18 0:00:00⠙ Warming… pp2048 tg128 @ d0  0/18 0:00:00⠹ ━━━━ 0/18\n\
+│ pp2048 tg128 @ d0    │ c1 │   1,198 │    29.0 │    2,113 │    6,437 │ 2048+128\n\
+│ pp2048 tg128 @ d0    │ c2 │   1,287 │    35.1 │    2,148 │    8,054 │ 2048+128\n";
+    let cells = super::parse::parse_perf_box(soup);
+    assert_eq!(
+        cells,
+        vec![
+            super::PerfCell {
+                d: 0,
+                c: 1,
+                tg: 29.0
+            },
+            super::PerfCell {
+                d: 0,
+                c: 2,
+                tg: 35.1
+            },
+        ]
+    );
+    // first-match lookup must see the real speed, not 0
+    assert_eq!(
+        cells.iter().find(|p| p.d == 0 && p.c == 1).map(|p| p.tg),
+        Some(29.0)
+    );
+}
+
 fn row(name: &str, model: &str, quant: &str, score: Option<serde_json::Value>) -> ReportRow {
     let reports = score.unwrap_or(
         serde_json::json!([{"file": "f.md", "files": ["f.md"], "perf": [], "date": "", "label": ""}]),