mirror of
https://github.com/Niko1221/Strata.git
synced 2026-12-04 15:28:40 +00:00
Step 10 edits the CMake files and package scripts that f-0216-int already changed (own-stack steps 1-3, f-spark-nommq), so it is built on top of them. Two conflicts, both from this branch's step 5 next to GGML-R1's SYCL clean-up: - third_party/strata-ggml/UPSTREAM.md item 3: this branch's text (the quant header is include/strata/quant, generated) plus R1's sentence that the SYCL-mode copy was deleted in 0.2.15; - tools/test_quant_header_names.py: this branch's forwarder path and docstring, R1's sycl assertions. tools/test_quant_header_names.py, test_quant_header.py, test_strata_gguf.py and check_vendored.py pass after the merge.
66 lines
4.1 KiB
Python
66 lines
4.1 KiB
Python
"""The quant header is Strata's include/strata/quant/strata-quant-common.h (generated by tools/gen_quant_header.py, 0.2.16; tools/test_quant_header.py
|
|
checks its content); third_party/ggml/ggml-common.h only forwards to it (the dpct-migrated SYCL-mode copy, sycl/third_party/ggml, is gone since
|
|
0.2.15: the SYCL build includes the shared header). The Metal runtime reads the text under the new name, the Mac package ships both names (the old one for two releases).
|
|
|
|
python -m unittest tools.test_quant_header_names -v
|
|
"""
|
|
import shutil
|
|
import subprocess
|
|
import sys
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
|
|
ROOT = Path(__file__).resolve().parents[1]
|
|
NEW = ROOT / "include" / "strata" / "quant" / "strata-quant-common.h"
|
|
OLD = ROOT / "third_party" / "ggml" / "ggml-common.h"
|
|
|
|
|
|
class QuantHeaderNames(unittest.TestCase):
|
|
def test_the_text_is_in_the_new_file_and_the_old_path_forwards(self):
|
|
text = NEW.read_text(encoding="utf-8")
|
|
self.assertIn("\n#ifndef GGML_COMMON_DECL\n", text, "the new file is the header's text (the Metal runtime reads it as text)")
|
|
self.assertIn("GENERATED by tools/gen_quant_header.py", text)
|
|
self.assertIn("GGML_COMMON_IMPL_METAL", text)
|
|
self.assertGreater(text.count("\n"), 1900)
|
|
old = [ln for ln in OLD.read_text(encoding="utf-8").splitlines() if not ln.startswith("//") and ln.strip()]
|
|
self.assertEqual(old, ['#include "../../include/strata/quant/strata-quant-common.h"'])
|
|
# the SYCL build takes the shared header (sycl/CMakeLists.txt: ${STRATA_ROOT}/third_party/ggml), not a migrated copy of its own
|
|
self.assertFalse((ROOT / "sycl" / "third_party" / "ggml").exists(), "sycl/third_party/ggml is a dpct output copy no build reads")
|
|
self.assertIn("${STRATA_ROOT}/third_party/ggml", (ROOT / "sycl" / "CMakeLists.txt").read_text(encoding="utf-8"))
|
|
|
|
def test_the_metal_runtime_reads_the_new_name_and_the_old_one_second(self):
|
|
rp = (ROOT / "metal" / "src" / "resource_path.h").read_text(encoding="utf-8")
|
|
self.assertIn("resource2", rp)
|
|
rt = (ROOT / "metal" / "src" / "mtl_rt.mm").read_text(encoding="utf-8")
|
|
self.assertIn('resource2("STRATA_GGML_COMMON", "strata-quant-common.h", "ggml-common.h", STRATA_GGML_COMMON_DEFAULT)', rt)
|
|
cm = (ROOT / "metal" / "CMakeLists.txt").read_text(encoding="utf-8")
|
|
self.assertIn("${STRATA_ROOT}/include/strata/quant/strata-quant-common.h", cm)
|
|
|
|
def test_the_repo_mac_qwen_package_script_stages_the_real_header_under_both_names(self):
|
|
"""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,
|
|
which is only a forwarder now: staged like that the Metal kernels would have no block layouts)."""
|
|
sh = (ROOT / "packaging" / "mac" / "build_engine.sh").read_text(encoding="utf-8")
|
|
self.assertIn('QUANT=include/strata/quant/strata-quant-common.h', sh)
|
|
self.assertIn('cp "$QUANT" "$STAGE/metal/strata-quant-common.h"', sh)
|
|
self.assertIn('cp "$QUANT" "$STAGE/metal/ggml-common.h"', sh)
|
|
self.assertNotIn("cp third_party/ggml/ggml-common.h", sh)
|
|
self.assertIn('cmp "$PKG/metal/$n" "$QUANT"', sh)
|
|
self.assertNotIn("STRATA_GGML_DIR=$LL", sh)
|
|
|
|
@unittest.skipUnless(shutil.which("c++") or shutil.which("g++") or shutil.which("clang++"), "no C++ compiler")
|
|
def test_an_include_of_the_old_name_still_compiles(self):
|
|
cxx = shutil.which("c++") or shutil.which("g++") or shutil.which("clang++")
|
|
with tempfile.TemporaryDirectory() as d:
|
|
src = Path(d) / "t.cpp"
|
|
src.write_text("#define GGML_COMMON_DECL_CPP\n#define GGML_COMMON_IMPL_CPP\n#include \"ggml-common.h\"\n"
|
|
"int main() { return sizeof(block_q4_K) == 144 ? 0 : 1; }\n", encoding="utf-8")
|
|
exe = Path(d) / "t"
|
|
done = subprocess.run([cxx, "-std=c++17", "-I", str(OLD.parent), str(src), "-o", str(exe)], capture_output=True, text=True)
|
|
self.assertEqual(done.returncode, 0, done.stderr[-800:])
|
|
self.assertEqual(subprocess.run([str(exe)]).returncode, 0)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
unittest.main()
|