Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tools/test_conversation_cache_disabled.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import tempfile
import unittest

sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # runnable as tools/test_x.py from the repo root too

from tools.conversation_cache_disabled import NAMES, SETTINGS, STATE_KEYS, common_args, state_hashes, verify


Expand Down
2 changes: 2 additions & 0 deletions tools/test_conversation_cache_growth.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import tempfile
import unittest

sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # runnable as tools/test_x.py from the repo root too

from tools.conversation_cache_growth import NAMES, SECRET, SETTINGS, STATE_KEYS, verify


Expand Down
2 changes: 2 additions & 0 deletions tools/test_conversation_cache_http_smoke.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import unittest
from unittest.mock import Mock

sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # runnable as tools/test_x.py from the repo root too

from tools.conversation_cache_http_smoke import run


Expand Down
2 changes: 2 additions & 0 deletions tools/test_conversation_cache_isolation.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import tempfile
import unittest

sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # runnable as tools/test_x.py from the repo root too

from tools.conversation_cache_isolation import STATE_KEYS, fixtures, verify
from tools.gguf_reader import GGUFFile

Expand Down
2 changes: 2 additions & 0 deletions tools/test_conversation_cache_parity.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import tempfile
import unittest

sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # runnable as tools/test_x.py from the repo root too

from tools.conversation_cache_parity import STATE_KEYS, engine_args, pressure_budget_hint, verify_admission, verify_exchange, verify_pressure, verify_results


Expand Down
2 changes: 2 additions & 0 deletions tools/test_conversation_cache_soak.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import tempfile
import unittest

sys.path.insert(0, str(Path(__file__).resolve().parents[1])) # runnable as tools/test_x.py from the repo root too

from tools.conversation_cache_soak import STATE_KEYS, answer_text, verify


Expand Down
30 changes: 26 additions & 4 deletions tools/test_iq_pack.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,25 @@
sys.path.insert(0, str(Path(__file__).resolve().parent)) # runnable from the repo root too

from _paths import add_gguf_py
add_gguf_py()
from gguf import GGUFWriter, GGMLQuantizationType as Q, quants
import iq_pack
import iq_pack # needs numpy + gguf_reader only, not gguf-py: import it unguarded

try:
add_gguf_py() # llama.cpp's gguf-py: setup.py clones it; gguf_py() exits when absent
from gguf import GGUFWriter, GGMLQuantizationType as Q, quants
except SystemExit:
GGUF_PY = None
else:
GGUF_PY = "found"


def require_gguf_py(test):
"""setUpClass for the classes that build GGUF fixtures: skip (not fail) on a checkout without llama.cpp."""
@classmethod
def setUpClass(cls):
if GGUF_PY is None:
raise unittest.SkipTest("llama.cpp's gguf-py not found: run setup.py (it clones llama.cpp into "
"third_party/) or set STRATA_GGUF_PY")
return setUpClass


def write_gguf(path, tensors, split=None, arch=True):
Expand All @@ -37,6 +53,7 @@ def write_gguf(path, tensors, split=None, arch=True):


class CompatibilityTests(unittest.TestCase):
setUpClass = require_gguf_py(unittest.TestCase)
def test_bf16_halfway_rounds_to_even(self):
values = np.array([0x3F808000, 0x3F818000, 0xBF808000, 0xBF818000], dtype=np.uint32)
got = np.frombuffer(iq_pack.bf16_bytes(values.view(np.uint8), "F32"), dtype=np.uint16)
Expand Down Expand Up @@ -253,6 +270,8 @@ class ConversionTests(unittest.TestCase):
"""CS2: FORM decides the engine's form; exact F32->BF16 by default, rounding only with --compat-bf16, the PLE
conv F32 -> F16 by the loader (index kind 3), non-finite values refused, every conversion in conversions.json."""

setUpClass = require_gguf_py(unittest.TestCase)

def test_exact_f32_to_bf16_by_default(self):
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp:
x = bits(np.arange(64, dtype=np.uint32).reshape(2, 32) << 16 | 0x3F000000) # BF16 values held as F32
Expand Down Expand Up @@ -362,8 +381,9 @@ def expert(seed, shape):
return np.random.default_rng(seed).standard_normal((N_EXPERT, *shape)).astype(np.float32)


def split_model(root, name="model", split_layer=True, dup=False, split_no=None, gate1=Q.Q8_0, seed=0):
def split_model(root, name="model", split_layer=True, dup=False, split_no=None, gate1=None, seed=0):
"""Writes the 4 shards; returns their paths."""
gate1 = Q.Q8_0 if gate1 is None else gate1 # not a default arg: the module imports without gguf-py
gu, dn = (32, 32), (32, 32)
router = [(f"blk.{l}.ffn_gate_inp.weight", np.full((N_EXPERT, 32), 0.5, np.float32), Q.F32) for l in (0, 1)]
l0 = [(f"blk.0.ffn_{r}_exps.weight", expert(seed + 10 + i, gu if r != "down" else dn), Q.Q8_0)
Expand Down Expand Up @@ -406,6 +426,7 @@ def expected_experts(model):


class SplitArtifactTests(unittest.TestCase):
setUpClass = require_gguf_py(unittest.TestCase)
def test_four_shards_and_a_layer_split_per_role(self):
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp:
root = Path(tmp)
Expand Down Expand Up @@ -600,6 +621,7 @@ def test_refusals(self):

class NativeExpertsV5Tests(unittest.TestCase):
"""The v5 mark (Hadamard-folded experts) rewrites only the tables the packer writes, v3 and v4."""
setUpClass = require_gguf_py(unittest.TestCase) # test_packer_refuses_before_writing builds GGUF fixtures
ROWS = "0 145 146 0 100 1 2 3\n1 145 146 100 100 4 5 6\n"

def table(self, version, tail="(n_expert 2, total 200)"):
Expand Down
4 changes: 4 additions & 0 deletions tools/test_strata_mcp.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,12 @@ def setUp(self):
self.strata.disk_free = lambda p: 1000.0
self.tools = M.Tools(self.strata)
self.extra = []
# the tests must never see a Strata server that happens to run on the real default port on this PC
self._default_port = M.DEFAULT_PORT
M.DEFAULT_PORT = free_port()

def tearDown(self):
M.DEFAULT_PORT = self._default_port
for p in self.extra:
if p.poll() is None:
p.kill()
Expand Down
Loading