okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
ffb3d9b31
main
1"""The app's setup, the app's first load and the Terminal's start pick the same drafter for Auto (lane APP-LIN 0.2.14 item 7). 2 3Before: the app prepared every DFlash2-capable model for DFlash2 (the host's own rule), so on a card where Control's Auto means the MTP the setup skipped the MTP layer and the 4first load ran undrafted. Now the app asks `strata drafting plan` at the install (no run config yet: --family/--model) and at the load (--config). This pins that both answers 5equal the start's own decision (drafting.choice_of, what serve/server.py's drafting.apply runs) on the card classes where they differ: a 12 GB CUDA card streaming IQ3_S (MTP) 6and a 24 GB one (DFlash2). 7 8Plain unittest, no pytest fixtures (tmp_path, capsys, monkeypatch): the Windows gate of f-0214-app reported both cases as ERROR at setup with the pytest version. 9""" 10import argparse 11import contextlib 12import io 13import json 14import tempfile 15import unittest 16from pathlib import Path 17from unittest import mock 18 19from strata_cli import drafting_cmd 20from strata_control import drafting 21 22 23def _plan (** kw )-> dict : 24a = argparse .Namespace (drafting_command = "plan" ,data_dir = None ,config = None ,family = None ,model = None ,mode = None ,no_split = False , 25engines_unloading = False ,output = "json" ) 26for k ,v in kw .items (): 27setattr (a ,k ,v ) 28out = io .StringIO () 29with contextlib .redirect_stdout (out ): 30code = drafting_cmd .run (a ) 31assert code == 0 ,out .getvalue () 32return json .loads (out .getvalue ().strip ().splitlines ()[- 1 ]) 33 34 35class SetupFirstLoadAndStartAgree (unittest .TestCase ): 36def test_on_a_12_gb_and_a_24_gb_cuda_card (self ): 37for vram_mib ,expected in ((12288 ,"mtp" ), (24576 ,"dflash2" )): 38with self .subTest (vram_mib = vram_mib ),tempfile .TemporaryDirectory ()as tmp , \ 39mock .patch .object (drafting_cmd ,"_hardware" ,return_value = ("cuda" , ["sm_86" ])), \ 40mock .patch .object (drafting ,"card_vram_mib" ,return_value = float (vram_mib )), \ 41mock .patch .object (drafting_cmd ,"_split_expected" ,return_value = False ), \ 42mock .patch .object (drafting_cmd ,"_installed_dflash2_configs" ,return_value = []): 43data = Path (tmp )/ "data" 44mtp = data / "mtp" / "rt" 45mtp .mkdir (parents = True ) 46# 1. the app's setup: no run config yet 47self .assertEqual (_plan (family = "qwen" ,model = "IQ3_S" ,mode = "auto" ,data_dir = str (data ))["choice" ],expected ) 48# 2. the app's first load: the run config setup wrote (Auto: no "drafting" key) 49 (mtp / "experts.bin" ).write_bytes (b"x" * 2048 ) 50cfg = {"model_name" :"qwen3.8-flash-next-iq3_s" ,"backend" :"cuda" , 51"args" : ["--pack" ,str (data / "packs" / "iq3_s" ),"--native" ,str (Path (tmp )/ "IQ3_S-00001-of-00002.gguf" ),"--mtp" ,str (mtp ),"--max-context" ,"131072" ]} 52path = Path (tmp )/ "strata-iq3_s.json" 53path .write_text (json .dumps (cfg ),encoding = "utf-8" ) 54self .assertEqual (_plan (config = str (path ))["choice" ],expected ) 55# 3. the start (serve/server.py runs drafting.apply on the same config): the same choice 56self .assertEqual (drafting .choice_of ("auto" ,model_name = cfg ["model_name" ],backend = "cuda" ,archs = ["sm_86" ],args = cfg ["args" ],vram_mib = float (vram_mib )),expected ) 57 58 59if __name__ == "__main__" : 60unittest .main ()