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
2.6 KiB56 linesraw
1"""The long-prompt layer skip (STRATA_DS4_PROMPT_SKIP=1) against the full work: same answers within noise.
2
3Needs a GPU, a DeepSeek-V4.1 pack and the golden ids file, so it runs only when they are named:
4
5    STRATA_DSV41_BIN=.../strata-dsv41 STRATA_DSV41_PACK=/data/pack2.00 STRATA_DSV41_IDS=.../logpos.ids.json \
6        python -m unittest tools.dsv41.test_prompt_skip
7
8The golden segments are joined, the first DS4_SCORE_PREFIX tokens (4200) are read as one prompt (the path a long prompt
9takes: logits of the last row only, where the skip applies), and the positions after them are scored teacher-forced.
10The skip changes only what the layers 20-39 compute for the prompt's early rows, so the scored rows' KL against the
11full work must stay at the noise of the experts' summing order.
12"""
13import os
14import pathlib
15import subprocess
16import sys
17import tempfile
18import unittest
19
20sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
21import quant_quality  # noqa: E402
22
23BIN = os.environ.get("STRATA_DSV41_BIN")
24PACK = os.environ.get("STRATA_DSV41_PACK")
25IDS = os.environ.get("STRATA_DSV41_IDS")
26
27
28def keep_rows(nl=40, yoco=20, win=128):
29    """The rows a long prompt keeps on layers yoco.. (the engine's forward_chunks): each layer looks back one window
30    more than the layer before, so the last (nl - yoco) * (win - 1) + win rows."""
31    return (nl - yoco) * (win - 1) + win
32
33
34class PromptSkip(unittest.TestCase):
35    def test_keep_rows_is_the_chain_of_windows(self):
36        self.assertEqual(keep_rows(), 2668)
37
38    @unittest.skipUnless(BIN and PACK and IDS, "needs STRATA_DSV41_BIN / _PACK / _IDS")
39    def test_scored_rows_after_a_skipped_prompt_match_the_full_work(self):
40        with tempfile.TemporaryDirectory() as tmp:
41            outs = {}
42            for mode in ("0", "1"):
43                out = pathlib.Path(tmp) / f"skip{mode}.tsv"
44                env = dict(os.environ, STRATA_DS4_PROMPT_SKIP=mode, DS4_SCORE_PREFIX="4200", DS4_CHUNK="1024")
45                subprocess.run([BIN, "--pack", PACK, "--tp", "1", "--threads", "off", "--max-context", "6144", "--vision",
46                                "off", "--dspark", "off", "--expert-profile", "none", "--window", "128", "--score", IDS,
47                                "--score-out", str(out)], check=True, env=env)
48                outs[mode] = quant_quality.read_run(str(out))
49            res = quant_quality.compare(outs["0"], outs["1"])["all"]
50            self.assertGreater(res["positions"], 500)
51            self.assertLess(res["kl"], 0.002)
52            self.assertGreaterEqual(res["top1"], 0.99)
53
54
55if __name__ == "__main__":
56    unittest.main()