okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
aff3a132f
main
1"""OWN-1B: the quant header's text lives in third_party/strata-ggml/strata-quant-common.h; third_party/ggml/ggml-common.h (and the SYCL-mode copy's old name) 2only forward to it. The Metal runtime reads the text under the new name, the Mac package ships both names (the old one for two releases). 3 4python -m unittest tools.test_quant_header_names -v 5""" 6import shutil 7import subprocess 8import sys 9import tempfile 10import unittest 11from pathlib import Path 12 13ROOT = Path (__file__ ).resolve ().parents [1 ] 14NEW = ROOT / "third_party" / "strata-ggml" / "strata-quant-common.h" 15OLD = ROOT / "third_party" / "ggml" / "ggml-common.h" 16 17 18class QuantHeaderNames (unittest .TestCase ): 19def test_the_text_is_in_the_new_file_and_the_old_path_forwards (self ): 20text = NEW .read_text (encoding = "utf-8" ) 21self .assertTrue (text .startswith ("#ifndef GGML_COMMON_DECL" ),"the new file is the header's text, verbatim (the Metal runtime reads it as text)" ) 22self .assertIn ("GGML_COMMON_IMPL_METAL" ,text ) 23self .assertGreater (text .count ("\n" ),1900 ) 24old = [ln for ln in OLD .read_text (encoding = "utf-8" ).splitlines ()if not ln .startswith ("//" )and ln .strip ()] 25self .assertEqual (old , ['#include "../strata-ggml/strata-quant-common.h"' ]) 26sycl = ROOT / "sycl" / "third_party" / "ggml" 27self .assertEqual ([ln for ln in (sycl / "ggml-common.h" ).read_text (encoding = "utf-8" ).splitlines ()if not ln .startswith ("//" )and ln .strip ()], 28 ['#include "strata-quant-common.h"' ]) 29self .assertIn ("sycl" , (sycl / "strata-quant-common.h" ).read_text (encoding = "utf-8" )) 30 31def test_the_metal_runtime_reads_the_new_name_and_the_old_one_second (self ): 32rp = (ROOT / "metal" / "src" / "resource_path.h" ).read_text (encoding = "utf-8" ) 33self .assertIn ("resource2" ,rp ) 34rt = (ROOT / "metal" / "src" / "mtl_rt.mm" ).read_text (encoding = "utf-8" ) 35self .assertIn ('resource2("STRATA_GGML_COMMON", "strata-quant-common.h", "ggml-common.h", STRATA_GGML_COMMON_DEFAULT)' ,rt ) 36cm = (ROOT / "metal" / "CMakeLists.txt" ).read_text (encoding = "utf-8" ) 37self .assertIn ("third_party/strata-ggml/strata-quant-common.h" ,cm ) 38 39def test_the_repo_mac_qwen_package_script_stages_the_real_header_under_both_names (self ): 40"""packaging/mac/build_engine.sh is the repo version of the release scripts' Mac stage (rel213/scripts/mac_rel213.sh copied third_party/ggml/ggml-common.h, 41which is only a forwarder now: staged like that the Metal kernels would have no block layouts).""" 42sh = (ROOT / "packaging" / "mac" / "build_engine.sh" ).read_text (encoding = "utf-8" ) 43self .assertIn ('QUANT=third_party/strata-ggml/strata-quant-common.h' ,sh ) 44self .assertIn ('cp "$QUANT" "$STAGE/metal/strata-quant-common.h"' ,sh ) 45self .assertIn ('cp "$QUANT" "$STAGE/metal/ggml-common.h"' ,sh ) 46self .assertNotIn ("cp third_party/ggml/ggml-common.h" ,sh ) 47self .assertIn ('cmp "$PKG/metal/$n" "$QUANT"' ,sh ) 48self .assertNotIn ("STRATA_GGML_DIR=$LL" ,sh ) 49 50@ unittest . skipUnless ( shutil . which ( "c++" ) or shutil . which ( "g++" ) or shutil . which ( "clang++" ), "no C++ compiler" ) 51def test_an_include_of_the_old_name_still_compiles (self ): 52cxx = shutil .which ("c++" )or shutil .which ("g++" )or shutil .which ("clang++" ) 53with tempfile .TemporaryDirectory ()as d : 54src = Path (d )/ "t.cpp" 55src .write_text ("#define GGML_COMMON_DECL_CPP\n#define GGML_COMMON_IMPL_CPP\n#include \"ggml-common.h\"\n" 56"int main() { return sizeof(block_q4_K) == 144 ? 0 : 1; }\n" ,encoding = "utf-8" ) 57exe = Path (d )/ "t" 58done = subprocess .run ([cxx ,"-std=c++17" ,"-I" ,str (OLD .parent ),str (src ),"-o" ,str (exe )],capture_output = True ,text = True ) 59self .assertEqual (done .returncode ,0 ,done .stderr [- 800 :]) 60self .assertEqual (subprocess .run ([str (exe )]).returncode ,0 ) 61 62 63if __name__ == "__main__" : 64unittest .main ()