okami.mom/strata

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

Niko1221Merge f-vit-exact: the picture reader follows the float32 reference closer on the CPU and on the GPU60d431e2a

main
2.3 KiB47 linesraw
1"""The picture reader's GPU gate reads our tower against the float32 reference (VitRef), not against llama.cpp's reader.
2
3tools/vision/own/gate_gpu.py: rule 1 = cosine(own GPU, float32) >= 0.999, rule 2 = no further from float32 than mtmd's GPU reader (1e-4 slack, or >= 0.9999).
4The numbers are code4217.png at 1,024 picture tokens, measured on 11-14 (RTX PRO 5000 and a Zen 3 CPU, Qwen3.8 BF16 mmproj).
5"""
6
7import importlib.util
8import unittest
9from pathlib import Path
10
11GATE = Path(__file__).resolve().parents[2] / "tools" / "vision" / "own" / "gate_gpu.py"
12
13
14def load_gate():
15    spec = importlib.util.spec_from_file_location("gate_gpu", GATE)
16    mod = importlib.util.module_from_spec(spec)
17    spec.loader.exec_module(mod)
18    return mod
19
20
21class VisionGateRuleTest(unittest.TestCase):
22    def setUp(self):
23        self.g = load_gate()
24
25    def test_code4217_float32_is_the_reference(self):
26        mtmd_gpu = 0.999029                      # mtmd's GPU reader against float32 on code4217 (the floor)
27        self.assertTrue(self.g.gate_pass(1.000000, mtmd_gpu))   # our tower without input rounding equals float32
28        self.assertFalse(self.g.gate_pass(0.998392, mtmd_gpu))  # our CUDA tower with BF16 inputs: under rule 1 against float32
29        self.assertFalse(self.g.gate_pass(0.998312, mtmd_gpu))  # our CPU tower with the old BF16 rounding default: under rule 1
30
31    def test_rule_two_against_the_mtmd_floor(self):
32        self.assertTrue(self.g.gate_pass(0.99920, 0.99925))     # inside the 1e-4 slack
33        self.assertFalse(self.g.gate_pass(0.99920, 0.99940))    # further from float32 than mtmd's GPU reader
34        self.assertTrue(self.g.gate_pass(0.99990, 1.0))         # 0.9999 passes whatever the floor
35
36    def test_largest_pictures_compare_the_gpu_readers(self):
37        self.assertTrue(self.g.gate_pass(0.995, 1.0, skip_cpu=True))
38        self.assertFalse(self.g.gate_pass(0.985, 1.0, skip_cpu=True))
39
40    def test_mtmd_is_information_only(self):
41        src = GATE.read_text(encoding="utf-8")
42        self.assertIn('"STRATA_VIT_CPU": "ref"', src)            # the reference reader the gate starts where --ref-dir lacks a picture
43        self.assertIn("own/mtmdC", src)                          # mtmd's CPU path stays a printed column
44
45
46if __name__ == "__main__":
47    unittest.main()