Files
strata/tools/dsv41/test_prompt_skip.py
T
Niko1221 8a7102ec4d dsv41: a long prompt skips layers 20-39 on all but its last 2,668 rows (STRATA_DS4_PROMPT_SKIP, on by default)
Layers 20-39 of DeepSeek-V4.1-Flash read a prompt's earlier tokens only through layer 20's compressed KV and index
keys, and each looks back one 128-token window more than the layer before. So for the answer and for the rings the
decode reads they need their own work only on the last (40 - 20) x 127 + 128 = 2,668 rows. A prompt of ~3,700 or more
new tokens on one GPU now runs its earlier chunks through layers 0-19 plus layer 20's kv_only part (the hyper-connection
pre-norm, the compressor latent, the index keys, the compressed KV) and nothing of the later layers' attention or
experts; the chunk the cut falls in runs layers 20-39 from the cut row on; later chunks run every layer. The expert flow
plans nothing for the skipped (chunk, layer)s. STRATA_DS4_PROMPT_SKIP: 1 (default) the skip, 2 only the last 128 rows
(DeepSeek's own serving; answers shift a little), 0 off. Same approach as Maya #318.

H100 emulation (64 GB cgroup, 12 GiB VRAM, store 41 GB, 3.6 GB/s SSD cap): 16K prompt 69.3 s -> 51.5 s (236 -> 318
tok/s, two alternating pairs), 4K 32.5 s -> 30.7 s; 800 teacher-forced positions after a 4,200-token skipped prompt: KL
0.00029 against the full work, top-1 against the text 88.11% against 87.98%, ppl 1.5110 against 1.5111.

--score gets DS4_SCORE_PREFIX=N (the segments joined, the first N tokens read as one prompt with the last row's logits,
the rest scored) so the skip can be scored; tools/dsv41/test_prompt_skip.py runs it against a pack when one is named.
The Maya notice file now says later Maya changes are covered by the same notice.
2026-10-24 01:11:34 +02:00

57 lines
2.6 KiB
Python

"""The long-prompt layer skip (STRATA_DS4_PROMPT_SKIP=1) against the full work: same answers within noise.
Needs a GPU, a DeepSeek-V4.1 pack and the golden ids file, so it runs only when they are named:
STRATA_DSV41_BIN=.../strata-dsv41 STRATA_DSV41_PACK=/data/pack2.00 STRATA_DSV41_IDS=.../logpos.ids.json \
python -m unittest tools.dsv41.test_prompt_skip
The golden segments are joined, the first DS4_SCORE_PREFIX tokens (4200) are read as one prompt (the path a long prompt
takes: logits of the last row only, where the skip applies), and the positions after them are scored teacher-forced.
The skip changes only what the layers 20-39 compute for the prompt's early rows, so the scored rows' KL against the
full work must stay at the noise of the experts' summing order.
"""
import os
import pathlib
import subprocess
import sys
import tempfile
import unittest
sys.path.insert(0, str(pathlib.Path(__file__).resolve().parents[1]))
import quant_quality # noqa: E402
BIN = os.environ.get("STRATA_DSV41_BIN")
PACK = os.environ.get("STRATA_DSV41_PACK")
IDS = os.environ.get("STRATA_DSV41_IDS")
def keep_rows(nl=40, yoco=20, win=128):
"""The rows a long prompt keeps on layers yoco.. (the engine's forward_chunks): each layer looks back one window
more than the layer before, so the last (nl - yoco) * (win - 1) + win rows."""
return (nl - yoco) * (win - 1) + win
class PromptSkip(unittest.TestCase):
def test_keep_rows_is_the_chain_of_windows(self):
self.assertEqual(keep_rows(), 2668)
@unittest.skipUnless(BIN and PACK and IDS, "needs STRATA_DSV41_BIN / _PACK / _IDS")
def test_scored_rows_after_a_skipped_prompt_match_the_full_work(self):
with tempfile.TemporaryDirectory() as tmp:
outs = {}
for mode in ("0", "1"):
out = pathlib.Path(tmp) / f"skip{mode}.tsv"
env = dict(os.environ, STRATA_DS4_PROMPT_SKIP=mode, DS4_SCORE_PREFIX="4200", DS4_CHUNK="1024")
subprocess.run([BIN, "--pack", PACK, "--tp", "1", "--threads", "off", "--max-context", "6144", "--vision",
"off", "--dspark", "off", "--expert-profile", "none", "--window", "128", "--score", IDS,
"--score-out", str(out)], check=True, env=env)
outs[mode] = quant_quality.read_run(str(out))
res = quant_quality.compare(outs["0"], outs["1"])["all"]
self.assertGreater(res["positions"], 500)
self.assertLess(res["kl"], 0.002)
self.assertGreaterEqual(res["top1"], 0.99)
if __name__ == "__main__":
unittest.main()