okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1"""strata_control/retired.py: DeepSeek configs, names, folders and files are recognised locally and at once; the words name the folder 2and its size; a Qwen config never matches; nothing raises on unreadable input.""" 3from __future__import annotations 4 5import json 6import struct 7import sys 8import tempfile 9import time 10import unittest 11from pathlib import Path 12 13ROOT = Path (__file__ ).resolve ().parents [2 ] 14sys .path .insert (0 ,str (ROOT )) 15 16from strata_control import retired # noqa: E402 17 18 19def gguf (path :Path ,arch :str ,extra_kv_first :bool = False )-> Path : 20"""A GGUF header with general.architecture (optionally behind a u32 key) and no tensors.""" 21def kv_str (k :str ,v :str )-> bytes : 22kb ,vb = k .encode (),v .encode () 23return struct .pack ("<Q" ,len (kb ))+ kb + struct .pack ("<I" ,8 )+ struct .pack ("<Q" ,len (vb ))+ vb 24kvs = [] 25if extra_kv_first : 26kb = b"general.quantization_version" 27kvs .append (struct .pack ("<Q" ,len (kb ))+ kb + struct .pack ("<I" ,4 )+ struct .pack ("<I" ,2 )) 28kvs .append (kv_str ("general.architecture" ,arch )) 29path .write_bytes (b"GGUF" + struct .pack ("<I" ,3 )+ struct .pack ("<Q" ,0 )+ struct .pack ("<Q" ,len (kvs ))+ b"" .join (kvs )) 30return path 31 32 33QWEN = {"exe" :"/x/components/engine/0.1.60-linux-x86_64-cuda/strata" ,"args" : ["--model" ,"/m/q.gguf" ],"arch" :"qwen3next" , 34"model_name" :"qwen3.8-flash-next-iq3_s" } 35DS = {"exe" :"/x/engine-dsv41/0.1.59-linux-x86_64-cuda-cuda13/strata-dsv41" ,"args" : ["--pack" ,"/nowhere/deepseek" ], 36"arch" :"deepseek41" ,"model_name" :"deepseek-v4.1-flash" } 37 38 39class ConfigReason (unittest .TestCase ): 40def test_each_reason (self ): 41self .assertEqual (retired .config_reason (DS ),"arch" ) 42self .assertEqual (retired .config_reason ({"exe" :"C:\\S\\engine-dsv41\\v\\strata-dsv41.exe" ,"args" : []}),"engine" ) 43self .assertEqual (retired .config_reason ({"exe" :"/x/strata" ,"model_name" :"deepseek-v4.1-flash-ist-das-2.00bpw" }),"name" ) 44with tempfile .TemporaryDirectory ()as d : 45tok = Path (d )/ "tokenizer" 46tok .mkdir () 47 (tok / "tokenizer.json" ).write_text (json .dumps ({"pre" :"deepseek3" }),encoding = "utf-8" ) 48self .assertEqual (retired .config_reason ({"exe" :"/x/strata" ,"tokenizer" :str (tok )}),"tokenizer" ) 49 (tok / "tokenizer.json" ).write_text (json .dumps ({"pre" :"qwen35" }),encoding = "utf-8" ) 50self .assertIsNone (retired .config_reason ({"exe" :"/x/strata" ,"tokenizer" :str (tok )})) 51 52def test_qwen_configs_never_match (self ): 53self .assertIsNone (retired .config_reason (QWEN )) 54for arch in ("qwen3next" ,"qwen35moe" ,"" ,None ): 55self .assertIsNone (retired .config_reason ({** QWEN ,"arch" :arch })) 56 57def test_bad_input_never_raises (self ): 58for bad in (None ,3 ,"x" , [], {"exe" :5 ,"arch" :7 ,"args" :None ,"tokenizer" :9 }): 59self .assertIsNone (retired .config_reason (bad )) 60self .assertIsNone (retired .config_file_reason ("/no/such/strata-x.json" )) 61self .assertEqual (retired .config_file_reason ("/no/such/strata-deepseek-v4.1-flash-ist-das-2.00bpw.json" ),"name" ) 62 63def test_config_file (self ): 64with tempfile .TemporaryDirectory ()as d : 65p = Path (d )/ "strata-anything.json" 66p .write_text (json .dumps (DS ),encoding = "utf-8" ) 67self .assertEqual (retired .config_file_reason (p ),"arch" ) 68p .write_text (json .dumps (QWEN ),encoding = "utf-8" ) 69self .assertIsNone (retired .config_file_reason (p )) 70 71 72class Names (unittest .TestCase ): 73def test_typed_names (self ): 74for w in ("IST-DAS-2.00bpw" ,"ist-das-2.25bpw" ,"IST-DAS-1.75bpw" ,"ISTA-DAS-Coder" ,"deepseek41" ,"DeepSeek" ,"UD-Q8_K_XL" ): 75self .assertTrue (retired .is_name (w ),w ) 76for w in ("IQ3_S" ,"UD-IQ1_M" ,"UD-IQ4_XS" ,"coder" ,"qwen" ,"" ,None ,4 ): 77self .assertFalse (retired .is_name (w ),w ) 78 79def test_file_names (self ): 80for n in ("DeepSeek-V4.1-Flash-1017-UD-Q8_K_XL-00001-of-00009.gguf" ,"DeepSeek-V4.1-Flash-Engram-IQ4_NL.gguf" , 81"dspark-DeepSeek-V4.1-Flash-1017-Q8_0.gguf" ,"DeepSeek-V4.1-Flash-1017-GSQ-RCO-IQ2_XXS-00001-of-00004.gguf" ): 82self .assertTrue (retired .is_file_name (n ),n ) 83self .assertFalse (retired .is_file_name ("Qwen3.8-Flash-Next-GSQ-RCO-IQ3_S-00001-of-00002.gguf" )) 84 85 86class Files (unittest .TestCase ): 87def test_gguf_arch (self ): 88with tempfile .TemporaryDirectory ()as d : 89self .assertEqual (retired .gguf_arch (gguf (Path (d )/ "a.gguf" ,"deepseek4" )),"deepseek4" ) 90self .assertEqual (retired .gguf_arch (gguf (Path (d )/ "b.gguf" ,"qwen3next" ,extra_kv_first = True )),"qwen3next" ) 91 (Path (d )/ "c.gguf" ).write_bytes (b"not a gguf" ) 92self .assertIsNone (retired .gguf_arch (Path (d )/ "c.gguf" )) 93self .assertIsNone (retired .gguf_arch (Path (d )/ "missing.gguf" )) 94 95def test_folder_reason (self ): 96with tempfile .TemporaryDirectory ()as d : 97root = Path (d ) 98 (root / "byname" ).mkdir () 99 (root / "byname" / "DeepSeek-V4.1-Flash-Engram-IQ4_NL.gguf" ).write_bytes (b"x" ) 100self .assertEqual (retired .folder_reason (root / "byname" ),"name" ) 101 (root / "byarch" ).mkdir () 102gguf (root / "byarch" / "model-00001-of-00004.gguf" ,"deepseek4" ) 103self .assertEqual (retired .folder_reason (root / "byarch" ),"gguf" ) 104self .assertEqual (retired .folder_reason (root / "byarch" / "model-00001-of-00004.gguf" ),"gguf" ) 105 (root / "qwen" ).mkdir () 106gguf (root / "qwen" / "Qwen3.8-Flash-Next-IQ3_S-00001-of-00002.gguf" ,"qwen3next" ) 107self .assertIsNone (retired .folder_reason (root / "qwen" )) 108self .assertIsNone (retired .folder_reason (root / "none" )) 109 110def test_bounded_look_is_quick (self ): 111"""A folder with many entries is looked at, not walked: the answer comes at once.""" 112with tempfile .TemporaryDirectory ()as d : 113root = Path (d ) 114for i in range (600 ): 115 (root / f"f { i :04d } .bin" ).write_bytes (b"" ) 116sub = root / "deep" 117sub .mkdir () 118 (sub / "DeepSeek-V4.1-Flash-Engram-IQ4_NL.gguf" ).write_bytes (b"x" ) 119t = time .monotonic () 120self .assertIsNone (retired .folder_reason (root ))# the DeepSeek file is one level down: not entered 121self .assertIsNotNone (retired .where ([root ])) 122self .assertLess (time .monotonic ()- t ,2.0 ) 123 124 125class Words (unittest .TestCase ): 126def test_refusal_names_folder_and_size (self ): 127with tempfile .TemporaryDirectory ()as d : 128models = Path (d )/ "models" 129models .mkdir () 130 (models / "DeepSeek-V4.1-Flash-1017-GSQ-RCO-IQ2_XXS-00001-of-00004.gguf" ).write_bytes (b"\0" * 2_500_000 ) 131pack = Path (d )/ "packs" / "deepseek" 132pack .mkdir (parents = True ) 133 (pack / "ds4.txt" ).write_text (f"n_layer 43\nformat gguf\nmodel_dir { models } \n" ,encoding = "utf-8" ) 134cfg = {** DS ,"args" : ["--pack" ,str (pack )]} 135text = retired .refusal (cfg ,"DeepSeek-V4.1-Flash ISTA-DAS 2.00 bpw" ) 136self .assertTrue (text .startswith ("DeepSeek-V4.1-Flash ISTA-DAS 2.00 bpw is a DeepSeek model. This version of Strata no longer runs " 137"DeepSeek models, so it was not started." ),text ) 138self .assertIn (f"Its files are still on this computer: 0.0 GB in { models } and { pack } . Nothing was changed or deleted." ,text ) 139self .assertTrue (text .endswith ("Choose a Qwen model to run instead. If you no longer need the DeepSeek files, you can delete that " 140"folder to free the space." ),text ) 141self .assertNotIn ("[DRAFT]" ,text ) 142 143def test_refusal_without_files (self ): 144text = retired .refusal (DS ) 145self .assertNotIn ("Its files" ,text ) 146self .assertIn ("deepseek-v4.1-flash is a DeepSeek model." ,text ) 147 148def test_sizes (self ): 149self .assertEqual (retired .size_words (257_000_000_000 ),"257 GB" ) 150self .assertEqual (retired .size_words (2_500_000_000 ),"2.5 GB" ) 151 152 153if __name__ == "__main__" : 154unittest .main ()