Merge f-024-rel into f-024-tui
This commit is contained in:
commit
f4e7685ccf
44 files changed
+3711
-159
No files matched your search
@@ -0,0 +1,153 @@
|
||||
// The kept conversations' bookkeeping without a GPU (src/dsv41/ds4_slotmeta.hpp): the .meta file's round trip and
|
||||
// every way it is refused, and which kept conversation a prompt continues, and from where.
|
||||
// ds4_slot_test exit 0: all passed
|
||||
#include "ds4_slotmeta.hpp"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace sm = strata::ds4::slotmeta;
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
static int fails = 0;
|
||||
#define CHECK(c) \
|
||||
do { \
|
||||
if (!(c)) { \
|
||||
std::printf("FAIL line %d: %s\n", __LINE__, #c); \
|
||||
++fails; \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
static std::vector<int32_t> seq(int a, int n) {
|
||||
std::vector<int32_t> v((size_t) n);
|
||||
for (int i = 0; i < n; ++i) v[(size_t) i] = a + i;
|
||||
return v;
|
||||
}
|
||||
static std::vector<int> as_int(const std::vector<int32_t>& v) { return std::vector<int>(v.begin(), v.end()); }
|
||||
|
||||
static void patch(const std::string& p, size_t off, uint8_t b) {
|
||||
std::FILE* f = std::fopen(p.c_str(), "r+b");
|
||||
std::fseek(f, (long) off, SEEK_SET);
|
||||
std::fwrite(&b, 1, 1, f);
|
||||
std::fclose(f);
|
||||
}
|
||||
|
||||
static void meta_tests(const fs::path& dir) {
|
||||
const std::string id = "strata-ds4-session-2 engine=test", path = (dir / "slot-1.meta").string();
|
||||
const std::vector<int32_t> toks = seq(100, 50);
|
||||
const std::vector<int64_t> cks = {40, 33, 7};
|
||||
CHECK(sm::write(path, id, toks, 123456789ull, cks));
|
||||
CHECK(!fs::exists(path + ".tmp")); // (renamed over, no half file left)
|
||||
std::vector<int32_t> t;
|
||||
std::vector<int64_t> c;
|
||||
uint64_t bytes = 0;
|
||||
CHECK(sm::read(path, id, 1000, t, bytes, c));
|
||||
CHECK(t == toks && c == cks && bytes == 123456789ull);
|
||||
// no checkpoints is valid (a slot of a state that had none)
|
||||
CHECK(sm::write(path, id, toks, 5, {}));
|
||||
CHECK(sm::read(path, id, 1000, t, bytes, c) && c.empty() && bytes == 5);
|
||||
// another model's / engine's identity: refused, never read
|
||||
CHECK(!sm::read(path, id + "x", 1000, t, bytes, c));
|
||||
CHECK(!sm::read(path, "other", 1000, t, bytes, c));
|
||||
// more tokens than the context: refused
|
||||
CHECK(!sm::read(path, id, 49, t, bytes, c));
|
||||
CHECK(sm::read(path, id, 50, t, bytes, c));
|
||||
// a missing file
|
||||
CHECK(!sm::read((dir / "none.meta").string(), id, 1000, t, bytes, c));
|
||||
// every cut length, a damaged magic at either end
|
||||
CHECK(sm::write(path, id, toks, 9, cks));
|
||||
const size_t full = (size_t) fs::file_size(path);
|
||||
for (size_t keep = 0; keep < full; ++keep) {
|
||||
fs::copy_file(path, dir / "cut.meta", fs::copy_options::overwrite_existing);
|
||||
fs::resize_file(dir / "cut.meta", keep);
|
||||
if (sm::read((dir / "cut.meta").string(), id, 1000, t, bytes, c)) {
|
||||
std::printf("FAIL: a .meta cut to %zu of %zu bytes was read\n", keep, full);
|
||||
++fails;
|
||||
break;
|
||||
}
|
||||
}
|
||||
fs::copy_file(path, dir / "bad0.meta", fs::copy_options::overwrite_existing);
|
||||
patch((dir / "bad0.meta").string(), 0, 0x55);
|
||||
CHECK(!sm::read((dir / "bad0.meta").string(), id, 1000, t, bytes, c));
|
||||
fs::copy_file(path, dir / "bad1.meta", fs::copy_options::overwrite_existing);
|
||||
patch((dir / "bad1.meta").string(), full - 1, 0x55);
|
||||
CHECK(!sm::read((dir / "bad1.meta").string(), id, 1000, t, bytes, c));
|
||||
// a checkpoint outside the conversation, a zero one, more than four
|
||||
CHECK(sm::write(path, id, toks, 9, {51}));
|
||||
CHECK(!sm::read(path, id, 1000, t, bytes, c));
|
||||
CHECK(sm::write(path, id, toks, 9, {0}));
|
||||
CHECK(!sm::read(path, id, 1000, t, bytes, c));
|
||||
CHECK(sm::write(path, id, toks, 9, {4, 3, 2, 1}));
|
||||
CHECK(sm::read(path, id, 1000, t, bytes, c) && c.size() == 4);
|
||||
CHECK(sm::write(path, id, toks, 9, {1, 2, 3, 4, 5}));
|
||||
CHECK(!sm::read(path, id, 1000, t, bytes, c));
|
||||
// no tokens at all
|
||||
CHECK(sm::write(path, id, {}, 9, {}));
|
||||
CHECK(!sm::read(path, id, 1000, t, bytes, c));
|
||||
// an unwritable place: false, not a crash
|
||||
CHECK(!sm::write((dir / "nodir" / "x.meta").string(), id, toks, 1, {}));
|
||||
}
|
||||
|
||||
static size_t pick(const std::vector<std::vector<int32_t>>& toks, const std::vector<std::vector<int64_t>>& cks,
|
||||
const std::vector<int>& prompt, size_t floor, size_t* len) {
|
||||
std::vector<sm::Cand> c;
|
||||
for (size_t i = 0; i < toks.size(); ++i) c.push_back({&toks[i], &cks[i]});
|
||||
return sm::pick(c, prompt, floor, len);
|
||||
}
|
||||
|
||||
static void pick_tests() {
|
||||
size_t len = 99;
|
||||
const std::vector<int32_t> a = seq(1000, 3000), b = seq(5000, 2000);
|
||||
// the next turn of A: A whole, then new tokens
|
||||
std::vector<int32_t> a_turn = a;
|
||||
for (int32_t x : seq(9000, 40)) a_turn.push_back(x);
|
||||
CHECK(pick({a, b}, {{}, {}}, as_int(a_turn), 0, &len) == 0 && len == a.size());
|
||||
CHECK(pick({b, a}, {{}, {}}, as_int(a_turn), 0, &len) == 1 && len == a.size());
|
||||
// nothing shared: none, len 0
|
||||
CHECK(pick({a, b}, {{}, {}}, as_int(seq(7777, 100)), 0, &len) == SIZE_MAX && len == 0);
|
||||
// a prompt equal to the slot's tokens: the last token is still read, so the slot is not taken whole
|
||||
CHECK(pick({a}, {{}}, as_int(a), 0, &len) == SIZE_MAX && len == 0);
|
||||
CHECK(pick({a}, {{2900}}, as_int(a), 0, &len) == 0 && len == 2900);
|
||||
// a shorter prompt than the slot (a prefix of it): taken at a checkpoint within it, never past it
|
||||
std::vector<int32_t> head(a.begin(), a.begin() + 2000);
|
||||
CHECK(pick({a}, {{2900, 1500}}, as_int(head), 0, &len) == 0 && len == 1500);
|
||||
// a retried prompt: A's prompt end (2950) is a checkpoint; the new prompt agrees up to 2960 then differs
|
||||
std::vector<int32_t> retry(a.begin(), a.begin() + 2960);
|
||||
for (int32_t x : seq(8000, 30)) retry.push_back(x);
|
||||
CHECK(pick({a}, {{2950, 2000, 1000}}, as_int(retry), 0, &len) == 0 && len == 2950);
|
||||
// diverging before the latest checkpoint: the latest one it still agrees with (the anchor)
|
||||
std::vector<int32_t> early(a.begin(), a.begin() + 1200);
|
||||
for (int32_t x : seq(8000, 30)) early.push_back(x);
|
||||
CHECK(pick({a}, {{2950, 2000, 1000}}, as_int(early), 0, &len) == 0 && len == 1000);
|
||||
// diverging before every checkpoint: none
|
||||
std::vector<int32_t> first(a.begin(), a.begin() + 500);
|
||||
for (int32_t x : seq(8000, 30)) first.push_back(x);
|
||||
CHECK(pick({a}, {{2950, 2000, 1000}}, as_int(first), 0, &len) == SIZE_MAX && len == 0);
|
||||
// the floor: what the model itself can go back to wins unless the slot goes further
|
||||
CHECK(pick({a}, {{}}, as_int(a_turn), 3000, &len) == SIZE_MAX && len == 0);
|
||||
CHECK(pick({a}, {{}}, as_int(a_turn), 2999, &len) == 0 && len == 3000);
|
||||
// two slots, the longer match wins; a tie keeps the earlier one
|
||||
std::vector<int32_t> a_short(a.begin(), a.begin() + 1000);
|
||||
CHECK(pick({a_short, a}, {{}, {}}, as_int(a_turn), 0, &len) == 1 && len == 3000);
|
||||
CHECK(pick({a, a}, {{}, {}}, as_int(a_turn), 0, &len) == 0 && len == 3000);
|
||||
// too short a prompt
|
||||
CHECK(pick({a}, {{}}, {1000}, 0, &len) == SIZE_MAX && len == 0);
|
||||
CHECK(pick({a}, {{}}, {}, 0, &len) == SIZE_MAX && len == 0);
|
||||
// an empty slot list
|
||||
CHECK(pick({}, {}, as_int(a_turn), 0, &len) == SIZE_MAX && len == 0);
|
||||
}
|
||||
|
||||
int main() {
|
||||
const fs::path dir = fs::temp_directory_path() / "ds4-slot-test";
|
||||
std::error_code ec;
|
||||
fs::remove_all(dir, ec);
|
||||
fs::create_directories(dir);
|
||||
meta_tests(dir);
|
||||
pick_tests();
|
||||
fs::remove_all(dir, ec);
|
||||
std::printf(fails ? "FAILED: %d\n" : "slot_test: all passed\n", fails);
|
||||
return fails ? 1 : 0;
|
||||
}
|
||||
BIN
Binary file not shown.
@@ -130,5 +130,74 @@ class Dsv41Engine(unittest.TestCase):
|
||||
self.assertFalse((self.root / "data" / "engine-dsv41").exists() and any((self.root / "data" / "engine-dsv41").iterdir()))
|
||||
|
||||
|
||||
class ManualPackage(Dsv41Engine):
|
||||
"""A package the person downloaded by hand: a .tar.gz / .zip or the unpacked folder, checked before it is installed."""
|
||||
|
||||
def archive(self, version="0.1.49"):
|
||||
folder = build(self.root / f"man-{version}", version, self.key)
|
||||
out = self.root / "dl"
|
||||
out.mkdir(exist_ok=True)
|
||||
entry = feed_tool.pack_engine(folder, out, prefix="strata-dsv41")
|
||||
return folder, out / Path(entry["url"]).name
|
||||
|
||||
def test_a_downloaded_archive_is_checked_and_installed_beside_the_engine(self):
|
||||
_folder, archive = self.archive()
|
||||
lines = []
|
||||
exe = dsv41_engine.install_package(self.root / "data" / "engine-dsv41", archive, emit=lines.append)
|
||||
self.assertIsNotNone(exe, lines)
|
||||
self.assertTrue(exe.is_file())
|
||||
self.assertIn("signed, every file matches", " ".join(lines))
|
||||
self.assertEqual(self.tree(self.eng), self.before)
|
||||
|
||||
def test_an_unpacked_folder_works_too(self):
|
||||
folder, _ = self.archive()
|
||||
exe = dsv41_engine.install_package(self.root / "data" / "engine-dsv41", folder)
|
||||
self.assertIsNotNone(exe)
|
||||
|
||||
def test_a_damaged_file_is_refused_and_nothing_is_installed(self):
|
||||
folder, _ = self.archive()
|
||||
(folder / EXE).write_bytes(b"tampered")
|
||||
lines = []
|
||||
self.assertIsNone(dsv41_engine.install_package(self.root / "data" / "engine-dsv41", folder, emit=lines.append))
|
||||
self.assertIn("did not pass its check", " ".join(lines))
|
||||
dest = self.root / "data" / "engine-dsv41"
|
||||
self.assertFalse(dest.exists() and any(p.is_dir() for p in dest.iterdir()))
|
||||
|
||||
def test_a_package_signed_by_an_unknown_key_is_refused(self):
|
||||
other = fx.make_key()
|
||||
folder = build(self.root / "foreign", "0.1.49", other)
|
||||
lines = []
|
||||
self.assertIsNone(dsv41_engine.install_package(self.root / "data" / "engine-dsv41", folder, emit=lines.append))
|
||||
self.assertIn("did not pass its check", " ".join(lines))
|
||||
|
||||
def test_the_strata_engine_package_is_not_taken_for_deepseeks(self):
|
||||
src = self.root / "qsrc"
|
||||
src.mkdir()
|
||||
(src / "strata").write_bytes(b"qwen engine")
|
||||
folder = package_engine.build(src, "cuda", "0.1.49", components.host_platform(), self.root / "qout", entry="strata", archs=("sm_86",),
|
||||
min_driver={"nvidia": "580.65"}, build_id="q", variant="cuda13")
|
||||
feed_tool.sign_package(folder, self.key)
|
||||
lines = []
|
||||
self.assertIsNone(dsv41_engine.install_package(self.root / "data" / "engine-dsv41", folder, emit=lines.append))
|
||||
self.assertIn("not the DeepSeek engine", " ".join(lines))
|
||||
|
||||
def test_a_missing_or_wrong_file_is_said_plainly(self):
|
||||
lines = []
|
||||
self.assertIsNone(dsv41_engine.install_package(self.root / "x", self.root / "nope.tar.gz", emit=lines.append))
|
||||
self.assertIn("is not there", " ".join(lines))
|
||||
junk = self.root / "notes.txt"
|
||||
junk.write_text("x")
|
||||
self.assertIsNone(dsv41_engine.install_package(self.root / "x", junk, emit=lines.append))
|
||||
self.assertIn("not a package file", " ".join(lines))
|
||||
|
||||
def test_files_put_in_the_folder_are_found(self):
|
||||
_f, archive = self.archive()
|
||||
dest = self.root / "data" / "engine-dsv41"
|
||||
dest.mkdir(parents=True)
|
||||
shutil.copy(archive, dest / archive.name)
|
||||
(dest / "readme.txt").write_text("x")
|
||||
self.assertEqual([p.name for p in dsv41_engine.pending(dest)], [archive.name])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -0,0 +1,119 @@
|
||||
"""H100 fresh-install items for DeepSeek in the Terminal: the screens' packages, the Advanced list's own flags, the disk in "fits"."""
|
||||
from __future__ import annotations
|
||||
|
||||
import sys
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest import mock
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT))
|
||||
sys.path.insert(0, str(ROOT / "tools"))
|
||||
|
||||
from strata_cli.launch import cmd, params as P # noqa: E402
|
||||
from strata_cli.launch.catalog import TIGHT, verdict # noqa: E402
|
||||
|
||||
CARD = {"index": 0, "name": "RTX 5070", "vram_gb": 12.0, "vendor": "nvidia", "usable": True}
|
||||
|
||||
|
||||
class Screens(unittest.TestCase):
|
||||
def test_missing_package_is_named_not_a_traceback(self):
|
||||
import importlib.util as u
|
||||
real = u.find_spec
|
||||
with mock.patch.object(u, "find_spec", lambda n, *a, **k: None if n == "rich" else real(n, *a, **k)):
|
||||
self.assertEqual(cmd._screens_missing(), "rich")
|
||||
with mock.patch.object(u, "find_spec", lambda n, *a, **k: None if n == "textual" else real(n, *a, **k)):
|
||||
self.assertEqual(cmd._screens_missing(), "textual")
|
||||
|
||||
def test_setup_installs_the_screens_packages(self):
|
||||
import setup
|
||||
names = [r.split("==")[0].split(";")[0].strip() for r in setup.runtime_packages()]
|
||||
self.assertIn("textual", names)
|
||||
self.assertIn("numpy", names)
|
||||
|
||||
|
||||
class Advanced(unittest.TestCase):
|
||||
ARGS = ["--pack", "P", "--max-context", "8192", "--eos", "1", "--dspark", "auto", "--dspark-conf", "0.65"]
|
||||
|
||||
def test_deepseeks_own_flags_are_known_before_the_engine_is_installed(self):
|
||||
rows = P.build_rows(P.dsv41_help_text(None), self.ARGS, None, {}, {}, {})
|
||||
mine = {r.name: r for r in rows if r.name in self.ARGS}
|
||||
self.assertEqual(set(mine), {"--pack", "--max-context", "--eos", "--dspark", "--dspark-conf"})
|
||||
for r in mine.values():
|
||||
self.assertNotIn("not in this engine's list", r.description)
|
||||
self.assertTrue(r.known)
|
||||
|
||||
def test_a_real_typing_mistake_is_still_flagged(self):
|
||||
rows = P.build_rows(P.dsv41_help_text(None), self.ARGS + ["--dsparkk", "1"], None, {}, {}, {})
|
||||
self.assertIn("not in this engine's list", next(r for r in rows if r.name == "--dsparkk").description)
|
||||
|
||||
|
||||
class Presets(unittest.TestCase):
|
||||
def test_a_saved_preset_is_read_from_where_it_is_written_whatever_the_data_dir(self):
|
||||
import tempfile
|
||||
from strata_cli.launch import settings as S, store
|
||||
with tempfile.TemporaryDirectory() as d, mock.patch.dict("os.environ", {"STRATA_LAUNCH_PRESET_DIR": d}):
|
||||
s = S.LaunchSettings(family="deepseek41", model="IST-DAS-2.00bpw", data_dir=str(Path(d) / "elsewhere"), name="DS 8K")
|
||||
store.save(s, "DS 8K")
|
||||
self.assertEqual([p.name for p in store.list_presets()], ["DS 8K"])
|
||||
self.assertEqual(store.preset_dir(), Path(d)) # (the folder does not depend on the launch's --data-dir)
|
||||
|
||||
|
||||
class PlanEngine(unittest.TestCase):
|
||||
def test_an_installed_deepseek_engine_is_named_in_the_plan_not_downloaded(self):
|
||||
import tempfile
|
||||
from strata_cli.launch import runner as R
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
pkg = Path(d) / "engine-dsv41" / "0.1.49-windows-x86_64-cuda-cuda13"
|
||||
pkg.mkdir(parents=True)
|
||||
exe = pkg / ("strata-dsv41.exe" if sys.platform == "win32" else "strata-dsv41")
|
||||
exe.write_bytes(b"x")
|
||||
fake = mock.MagicMock()
|
||||
fake.s.data_dir = d
|
||||
fake.catalog.data_dir.return_value = Path(d)
|
||||
fake.catalog.strata.setup_module.side_effect = RuntimeError("no setup")
|
||||
with mock.patch.dict("os.environ", {"STRATA_DSV41_EXE": ""}), mock.patch("strata_control.engine_component.status", return_value={"usable": False}):
|
||||
found, known = R.Runner.dsv41_engine_found(fake)
|
||||
self.assertEqual(found, exe)
|
||||
self.assertTrue(known)
|
||||
|
||||
|
||||
class Disk(unittest.TestCase):
|
||||
def setUp(self):
|
||||
import strata_mcp as M
|
||||
self.s = M.Strata(ROOT)
|
||||
|
||||
def hw(self, disk):
|
||||
return {"ram_gb": 64.0, "gpus": [CARD], "engine_vendor": "nvidia", "disk_free_gb": disk}
|
||||
|
||||
def test_fits_in_memory_but_not_on_the_disk_is_tight_with_the_numbers(self):
|
||||
w = self.s.dsv41_words(self.hw(37.0), "IST-DAS-2.25bpw")
|
||||
self.assertTrue(w.startswith("tight"), w)
|
||||
self.assertIn("free disk space", w)
|
||||
self.assertIn("37 GB", w)
|
||||
self.assertEqual(verdict(w), (TIGHT, "tight: needs more disk space"))
|
||||
|
||||
def test_enough_disk_or_already_installed_is_unchanged(self):
|
||||
self.assertNotIn("free disk space", self.s.dsv41_words(self.hw(900.0), "IST-DAS-2.25bpw"))
|
||||
self.assertNotIn("free disk space", self.s.dsv41_words(self.hw(37.0), "IST-DAS-2.25bpw", installed=True))
|
||||
self.assertNotIn("free disk space", self.s.dsv41_words({**self.hw(None)}, "IST-DAS-2.25bpw"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
|
||||
class FinalHint(unittest.TestCase):
|
||||
def test_no_preset_means_the_plain_stop_command_and_a_way_to_keep_the_settings(self):
|
||||
from strata_cli.launch import settings as S
|
||||
s = S.LaunchSettings(name="IST-DAS-2.00bpw 8K")
|
||||
lines = cmd.final_hint_lines(s, False)
|
||||
text = "\n".join(lines)
|
||||
self.assertIn("strata launch --stop", text)
|
||||
self.assertNotIn("--preset", text.replace("--save-preset", ""))
|
||||
self.assertIn("--save-preset NAME", text)
|
||||
|
||||
def test_a_saved_preset_keeps_its_name_in_the_hint(self):
|
||||
from strata_cli.launch import settings as S
|
||||
s = S.LaunchSettings(name="Office")
|
||||
self.assertIn('--stop --preset "Office"', "\n".join(cmd.final_hint_lines(s, True)))
|
||||
@@ -51,6 +51,18 @@ class Tune(unittest.TestCase):
|
||||
self.assertEqual(len(calls), 4) # baseline, drafter on, block 3, threads
|
||||
self.assertIn("tuned", json.loads(self.cfg.read_text()))
|
||||
|
||||
def test_the_result_says_what_was_tried(self):
|
||||
res, _ = self.run_tune(lambda a: 4.5)
|
||||
text = " ".join(res["lines"])
|
||||
self.assertIn("Tried (tokens a second): standard 4.5", text)
|
||||
self.assertIn("the drafter on (DSpark) 4.5", text)
|
||||
|
||||
def test_a_single_timing_says_there_was_nothing_to_compare(self):
|
||||
def only_baseline(a):
|
||||
return 4.5 if "--dspark" in a and a[a.index("--dspark") + 1] == "auto" and "--cpu-threads" not in a else None
|
||||
res, _ = self.run_tune(only_baseline)
|
||||
self.assertIn("nothing to compare", " ".join(res["lines"]))
|
||||
|
||||
def test_noise_changes_nothing(self):
|
||||
before = self.cfg.read_text()
|
||||
res, _ = self.run_tune(lambda a: 4.5 + 0.1 * (len(a) % 2))
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
"""pack_gguf must never take an Engram file's metadata for the model's: ISTA-DASLab's final Engram says general.architecture 'deepseek41-engram'
|
||||
(the first release's said 'engram'). The fixture is the real header of DeepSeek-V4.1-Flash-Engram-IQ4_NL.gguf (its 416 bytes: metadata and the tensor
|
||||
directory, no data)."""
|
||||
from __future__ import annotations
|
||||
|
||||
import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[2]
|
||||
sys.path.insert(0, str(ROOT / "tools" / "dsv41"))
|
||||
import pack_gguf as PG # noqa: E402
|
||||
|
||||
FIXTURE = ROOT / "tests" / "fixtures" / "dsv41" / "engram-final-header.gguf"
|
||||
|
||||
|
||||
def tiny_gguf(path: Path, arch: str, extra: dict | None = None) -> Path:
|
||||
"""A GGUF with only metadata (string and uint32 values), no tensors."""
|
||||
kv = {"general.architecture": arch, **(extra or {})}
|
||||
out = bytearray(b"GGUF" + struct.pack("<IQQ", 3, 0, len(kv)))
|
||||
for k, v in kv.items():
|
||||
out += struct.pack("<Q", len(k)) + k.encode()
|
||||
if isinstance(v, str):
|
||||
out += struct.pack("<I", 8) + struct.pack("<Q", len(v)) + v.encode()
|
||||
else:
|
||||
out += struct.pack("<I", 4) + struct.pack("<I", v)
|
||||
out += b"\0" * (-len(out) % 32)
|
||||
path.write_bytes(bytes(out))
|
||||
return path
|
||||
|
||||
|
||||
class EngramHeader(unittest.TestCase):
|
||||
def test_the_real_final_engram_header_is_an_engram_file(self):
|
||||
g = PG.Gguf(FIXTURE)
|
||||
self.assertEqual(g.kv["general.architecture"], "deepseek41-engram")
|
||||
self.assertTrue(PG.is_engram_file(g))
|
||||
self.assertEqual(len(g.tensors), 2)
|
||||
self.assertEqual(g.data_start, 416)
|
||||
|
||||
def test_it_is_never_the_group_the_model_metadata_comes_from(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
d = Path(d)
|
||||
shard = PG.Gguf(tiny_gguf(d / "model-00001-of-00004.gguf", "deepseek41", {"split.count": 4}))
|
||||
engram = PG.Gguf(FIXTURE)
|
||||
for order in ([engram, shard], [shard, engram]):
|
||||
kv = PG.model_kv(order)
|
||||
self.assertIsNotNone(kv)
|
||||
self.assertEqual(kv["general.architecture"], "deepseek41")
|
||||
self.assertIsNone(PG.model_kv([engram])) # an Engram alone is not a model
|
||||
|
||||
def test_the_first_releases_engram_is_one_too(self):
|
||||
with tempfile.TemporaryDirectory() as d:
|
||||
self.assertTrue(PG.is_engram_file(PG.Gguf(tiny_gguf(Path(d) / "e.gguf", "engram"))))
|
||||
self.assertFalse(PG.is_engram_file(PG.Gguf(tiny_gguf(Path(d) / "m.gguf", "deepseek41"))))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -44,6 +44,34 @@ class EngineExitIsExplained(unittest.TestCase):
|
||||
self.assertIn("render group", nxt)
|
||||
self.assertIn(str(log), nxt)
|
||||
|
||||
def test_a_gpu_runtime_start_failure_gets_a_plain_sentence_and_keeps_the_runtime_text_out_of_it(self):
|
||||
cfg, log = self.config_with_log(["strata generate: loading", "terminate called after throwing an instance of 'rocr::AMD::hsa_exception'",
|
||||
" what(): "])
|
||||
text, nxt = R.explain_engine_exit({"state": "failed", "error": "server_exited", "engine_exit_code": 134}, cfg)
|
||||
self.assertIn("stopped while it was loading the model (exit code 134)", text)
|
||||
self.assertNotIn("hsa_exception", text + nxt)
|
||||
self.assertNotIn("terminate called", text + nxt)
|
||||
self.assertIn("graphics card was not ready yet", nxt)
|
||||
self.assertIn("wait a few seconds", nxt)
|
||||
self.assertIn("restart the PC", nxt)
|
||||
self.assertIn(str(log), nxt)
|
||||
text, nxt = R.explain_engine_exit({"error": "server_exited", "engine_exit_code": 134,
|
||||
"log_tail": "terminate called after throwing an instance of 'rocr::AMD::hsa_exception' | what():"}, None)
|
||||
self.assertNotIn("hsa_exception", text)
|
||||
self.assertIn("graphics card was not ready yet", nxt)
|
||||
|
||||
def test_a_real_cause_in_the_same_log_wins_over_the_gpu_runtime_start_failure(self):
|
||||
cfg, log = self.config_with_log(["strata generate: CUDA error: out of memory",
|
||||
"terminate called after throwing an instance of 'rocr::AMD::hsa_exception'", " what(): "])
|
||||
text, nxt = R.explain_engine_exit({"state": "failed", "error": "server_exited", "engine_exit_code": 134}, cfg)
|
||||
self.assertIn("out of memory", text)
|
||||
self.assertIn("--context 16k", nxt)
|
||||
self.assertNotIn("graphics card was not ready", nxt)
|
||||
cfg, _ = self.config_with_log(["Permission denied: /dev/dri/renderD128", "terminate called after throwing an instance of 'rocr::AMD::hsa_exception'"])
|
||||
self.assertIn("render group", R.explain_engine_exit({"error": "server_exited", "engine_exit_code": 134}, cfg)[1])
|
||||
cfg, _ = self.config_with_log(["hsaKmtOpenKFD ok", "strata generate: CUDA error: out of memory"])
|
||||
self.assertNotIn("graphics card was not ready", R.explain_engine_exit({"error": "server_exited"}, cfg)[1])
|
||||
|
||||
def test_out_of_memory_and_old_engine_get_their_own_next_step(self):
|
||||
cfg, _ = self.config_with_log(["strata generate: CUDA error: out of memory"])
|
||||
self.assertIn("--context 16k", R.explain_engine_exit({"error": "server_exited"}, cfg)[1])
|
||||
|
||||
Reference in new issue
Block a user