okami.mom/strata

git clone https://git.nkp.pet/okami.mom/strata

waveringanaserve: restore the DeepSeek V4.1 server paths, tools and headers removed upstream, keeping the native picture tower firstba8745e13

main
3.8 KiB68 linesraw
1#!/bin/bash
2# Copyright (c) 2026 Peasant Smith and the Project Maya contributors (MIT; https://github.com/mw00/project-maya, v1.1.17).
3# Ported into Strata (third_party/project-maya/NOTICE.md, LICENSE); changes are in the git history of this file.
4# tools/ds4/bytecheck.sh - maya-ds4's byte-identity check of two builds (a change that must not move a bit: the same
5# prompt through each, every logit row dumped, the files compared byte for byte, the greedy tokens compared).
6#
7#   tools/ds4/bytecheck.sh <base maya-ds4> <new maya-ds4> <pack> <out dir> <ids file> [<check> ...]
8#     checks: windows (DS4_CHUNK_MIN=100000: windows of 16), chunked (the prompt as one chunked run), drafter
9#             (--dspark on); default: windows chunked.  64 greedy tokens after the prompt.
10#   env: NEW_RESERVE_MIB (default 600, the engine's --reserve-mib default; the packed KV caches: 624, 626 with the
11#        drafter - see "placement" below); GPU (default 0); CTX (default 8192)
12#
13# Placement.  --no-expert-cache --expert-profile none fix WHICH experts VRAM holds (by index) and keep them there, but
14# not HOW MANY: that follows the free VRAM at load.  A change that frees or uses VRAM (smaller caches, a new buffer)
15# moves an expert or more between VRAM and the CPU lane / the prompt path's streamed sets, and the prompt path sums a
16# token's experts batch by batch - another order, other bits (the windows path only differs when a moved expert is
17# picked).  So whenever a change frees or uses VRAM, give the build with more free VRAM that much more reserve:
18# NEW_RESERVE_MIB = 600 + what it frees, measured, not added up from the allocations (the driver rounds them): load
19# both once (the check's own first pair will do), and with E experts in VRAM each and F MiB free after the load,
20# freed = (F_new - F_base) + (E_new - E_base) * the MiB of an expert (the load line: experts GB / E).  Then check that
21# the load lines' "(N of M in VRAM)" agree - this script prints them.  The packed KV caches on a 32 GB V100 at 8K:
22# 24 MiB (626 with the drafter's 26; the allocations' sum said 18-19, and 618 / 619 left one expert more).
23#
24# A prompt that a checkpoint splits (600 tokens, then 400 more from the checkpoint) is not the same bits as the 1000 in
25# one chunked run: chunk boundaries change the arithmetic.  Compare a split run with the same split in the other build.
26set -u
27base=$1
28new=$2
29pack=$3
30out=$4
31ids=$(cat "$5")
32shift 5
33checks=${*:-windows chunked}
34mkdir -p "$out"
35common="--pack $pack --max-context ${CTX:-8192} --vision off --verbose --no-expert-cache --expert-profile none --n 64"
36run() {   # <build> <check> <exe> [env ...] -- <args ...>
37    local b=$1 c=$2 exe=$3
38    shift 3
39    local envs=()
40    while [ "$1" != "--" ]; do
41        envs+=("$1")
42        shift
43    done
44    shift
45    local reserve=600
46    [ "$b" = new ] && reserve=${NEW_RESERVE_MIB:-600}
47    env CUDA_VISIBLE_DEVICES=${GPU:-0} ${envs[@]+"${envs[@]}"} "$exe" $common --reserve-mib $reserve "$@" --ids "$ids" \
48        --dump-logits "$out/${b}_$c.f32" > "$out/${b}_$c.out" 2> "$out/${b}_$c.err"
49    echo "$b $c rc=$?"
50}
51for c in $checks; do
52    for b in base new; do
53        exe=$base
54        [ $b = new ] && exe=$new
55        case $c in
56        windows) run $b $c "$exe" DS4_CHUNK_MIN=100000 -- --dspark none ;;
57        chunked) run $b $c "$exe" -- --dspark none --window 1048576 ;;
58        drafter) run $b $c "$exe" -- --dspark on ;;
59        *) echo "unknown check $c" && exit 2 ;;
60        esac
61    done
62    echo "== $c"
63    for b in base new; do
64        echo "  $b: $(grep -h 'in VRAM' "$out/${b}_$c.err" | head -1 | sed 's/.*experts/experts/')"
65    done
66    echo "  logits: $(cmp -s "$out/base_$c.f32" "$out/new_$c.f32" && echo IDENTICAL || echo DIFFER);" \
67        "tokens: $(cmp -s <(grep -h '^[0-9]' "$out/base_$c.out") <(grep -h '^[0-9]' "$out/new_$c.out") && echo IDENTICAL || echo DIFFER)"
68done