Parcourir la source

staging(sparse-copy): aiden base+rem row tiling + aiden16 localized engram staging

- sparse_rows.py sparse-copy branch now tiles ranks with the wrapper's
  base+rem formula; the overlay cross-checks engram-local.json against
  SPARK_ENGRAM_ROWS and refuses to start on any disagreement (layer14 is
  not tp-divisible: old formula was off by one row per rank)
- aiden16 recipe: [[staging]] sparse-copy -> /home/kilork/aiden-engram,
  ro-mounted at /engram-local, SPARK_ENGRAM_DIR off the NAS fallback path
  (the 09-26 perf caveat: 2-10 s fresh-context prefill)
- verified: fixture 1006 rows (1006%4=2) -> manifest [252,504] == wrapper
Alexander Korolev il y a 3 semaines
Parent
commit
789983fc62

+ 45 - 24
recipes/dsv41-flash-4x-sglang-aiden16/recipe.toml

@@ -13,12 +13,10 @@
 # ~4.2M, 524K context, ~10 min to healthy.
 #
 # Model: deepseek-ai/DeepSeek-V4.1-Flash (510 GB, fp8 native) on the NAS —
-# serve with --hf-cache /mnt/nas/ai/huggingface. The checkpoint snapshot
-# dba1be0a... is also the Engram row source (SPARK_ENGRAM_DIR): all four
-# ranks read their rows directly from the NAS shards (Aiden's fallback path;
-# his measured config uses 47.2 GiB node-local sparse copies, which needs the
-# private engram_local.py — the NFS read costs ~3-5 ms/step extra, acceptable
-# for a validation run).
+# serve with --hf-cache /mnt/nas/ai/huggingface (weights are mmap-loaded from
+# the snapshot). The Engram rows are staged node-locally by [[staging]] below
+# (Aiden's measured production config: 47.2 GiB sparse copies per node) and
+# mounted at /engram-local — SPARK_ENGRAM_DIR points there.
 #
 # Per-rank Engram row ranges: the two tables have DIFFERENT row counts
 # (layer 1: 384,006,168; layer 14: 384,016,682 rows for this snapshot) and the
@@ -31,19 +29,13 @@
 # B12X_ROCE_GID_INDEX reuses the launcher's per-node NCCL GID auto-detect
 # (the wrapper exports it), so no pinned GID anywhere.
 #
-# Measured 2026-09-26 (4nodes-switch, NAS model, NAS Engram rows):
-#   162/176 (92/100, ★★★★★) — best DSV4.1 score on this cluster; fails
-#   TC-68/74/88, partials TC-03/14/50/51/57/58/62/81. Smoke: count-20 exact,
-#   tools OK, 155K-token needle OK, 524K context, KV pool 9.5M full tokens.
-#   PERF CAVEAT (engram/NAS, not the engine): every FRESH context pays a
-#   2-10 s prefill penalty (llama-benchy: pp 154-359 t/s, tg 8.6-21.8 t/s)
-#   while prefix-cached repeats run 0.3 s TTFT — the engram n-gram rows come
-#   from the NAS shards (30 ms mean gather; the 4 GB page cache releases once
-#   and misses re-fetch). Aiden's production uses 47.2 GiB node-local sparse
-#   copies (private engram_local.py). Agent traffic (short, repeated system
-#   prompts) sits in the cached regime and is fast; long fresh-context loads
-#   are slow. The tool-eval-bench llama-benchy perf table for this lane
-#   reflects the fresh-context penalty (see the shift notes 2026-09-26).
+# MEASURED 2026-09-26 (4nodes-switch, NAS model, NAS Engram rows):
+#   162/176 (92/100, ★★★★★) — best DSV4.1 score on this cluster.
+#   PERF CAVEAT then: every FRESH context paid a 2-10 s prefill penalty —
+#   engram rows came from the NAS shards (30 ms mean gather). The [[staging]]
+#   block below now localizes them on node NVMe (Aiden's production config);
+#   a re-bench on staged rows is pending — treat the 09-26 perf row as the
+#   NAS-engram baseline, not this config.
 
 engine = "sglang"
 name = "DeepSeek-V4.1-Flash (SGLang 4x, Aiden production-1.6)"
@@ -101,12 +93,41 @@ host = "/home/kilork/aiden4x-launch.sh"
 container = "/aiden4x-launch.sh"
 read_only = true
 
-# Engram row source: the full checkpoint snapshot on the NAS (container-side
-# path — the launcher mounts --hf-cache /mnt/nas/ai/huggingface at
-# /root/.cache/huggingface). No engram-local.json manifest in a full snapshot,
-# so per-rank ranges come from SPARK_ENGRAM_ROWS (wrapper).
+# Node-local sparse copy of the Engram tables (staging P2.5, sparse-copy —
+# the aiden overlay's engram-local.json contract). Built/verified per serve by
+# the launcher's [[staging]] below; the wrapper-computed SPARK_ENGRAM_ROWS and
+# the manifest agree because sparse_rows.py tiles ranks with the wrapper's
+# base+rem formula (the overlay refuses to start unless both are identical).
+[[extra_mounts]]
+host = "/home/kilork/aiden-engram"
+container = "/engram-local"
+read_only = true
+
+# Staging (spec: specs/tech-architecture/staging-feature.md): the sparse-copy
+# format writes the aiden16 contract directly (engram-local.json manifest +
+# sparse shard copies at the original safetensors byte offsets) so the overlay
+# reads rows from node-local NVMe. Ranges use the wrapper's base+rem tiling;
+# first serve packs ~95 GiB/node from the NAS, later serves verify sampled
+# row hashes against the ledger stored inside the dst tree.
+[[staging]]
+kind = "sparse-rows"
+format = "sparse-copy"
+id = "engram"
+src = "{{hf}}/hub/models--deepseek-ai--DeepSeek-V4.1-Flash/snapshots/dba1be0a40aa45a94ad051997016db3960a90277"
+dst = "/home/kilork/aiden-engram"
+min_free = "55G"
+
+# Engram row source: the node-local sparse copy staged by [[staging]] —
+# Aiden's measured production config (47.2 GiB rows on node NVMe). The
+# manifest (engram-local.json) carries the per-layer rank ranges; the
+# wrapper's SPARK_ENGRAM_ROWS is the identity cross-check the overlay runs.
 [env]
-SPARK_ENGRAM_DIR = "/root/.cache/huggingface/hub/models--deepseek-ai--DeepSeek-V4.1-Flash/snapshots/dba1be0a40aa45a94ad051997016db3960a90277"
+# Engram row source: the node-local sparse copy staged by [[staging]] below
+# (Aiden's measured production config — 47.2 GiB of rows on node NVMe, ~0.3 ms
+# gather; previously read straight from the NAS snapshot, which cost a 2-10 s
+# fresh-context prefill penalty). The manifest (engram-local.json) carries the
+# per-layer rank ranges; SPARK_ENGRAM_ROWS from the wrapper is the cross-check.
+SPARK_ENGRAM_DIR = "/engram-local"
 SPARK_ENGRAM_MODE = "hostnode"
 SPARK_ENGRAM_EARLY = "1"
 SPARK_ENGRAM_PREFETCH = "1"

+ 10 - 1
src/staging/scripts/sparse_rows.py

@@ -325,6 +325,15 @@ def main() -> int:
         return 2
 
     if args.format == "sparse-copy":
+        # The aiden overlay cross-checks engram-local.json against
+        # SPARK_ENGRAM_ROWS (its launch wrapper tiles with base+rem, NOT
+        # rows*rank//tp) and refuses to start on any disagreement — use the
+        # identical formula here. layer1/layer14 tile identically when
+        # rows % tp == 0; layer14 (%4==2 on this snapshot) differs by a row.
+        def rank_range(rows, r, tp):
+            base, rem = divmod(rows, tp)
+            lo = base * r + min(r, rem)
+            return lo, lo + base + (1 if r < rem else 0)
         # the loader resolves tensors through the index, so it travels too
         idx_src = root / "model.safetensors.index.json"
         idx_dst = out_dir / "model.safetensors.index.json"
@@ -337,7 +346,7 @@ def main() -> int:
         for layer in layers:
             recs = sparse_recs(root, layer)
             rows = recs["weight"][3]
-            lo, hi = rows * args.rank // args.tp, rows * (args.rank + 1) // args.tp
+            lo, hi = rank_range(rows, args.rank, args.tp)
             stage_sparse_layer(out_dir, layer, recs, lo, hi, ledger,
                                args.samples, args.force, args.verify)
             manifest[str(layer)] = [lo, hi]