60 lines
3.6 KiB
Python
60 lines
3.6 KiB
Python
"""Synthetic pinned Inkling contract, no GPU or model requests."""
|
|
import copy
|
|
import tempfile
|
|
import unittest
|
|
from pathlib import Path
|
|
from unittest.mock import Mock
|
|
from basalt_runtime import RECIPE, BasaltRuntime, validate_model
|
|
|
|
INKLING = dict(repo='jesdga/Inkling-2-Mini-Basalt',revision='6c9fbf0730a6d2e8813a1b262c2ab3548cf0239e',file='Inkling-2-Mini-NVFP4-MX8.basalt',size=19606374189,sha256='28ec70723feaa037942a02f55b9d5e898276f3e62a3b1fa083745f932a041b99')
|
|
|
|
class InklingTests(unittest.TestCase):
|
|
def test_pinned_inkling_is_accepted_without_weakening_identity(self):
|
|
self.assertEqual(validate_model(INKLING),RECIPE['additional_models']['inkling2'])
|
|
for key,value in [('repo','other/model'),('revision','0'*40),('size',1),('sha256','0'*64),('file','other.basalt')]:
|
|
with self.subTest(key=key),self.assertRaises(ValueError):validate_model({**INKLING,key:value})
|
|
validate_model(RECIPE['model'])
|
|
|
|
def test_prepared_checks_the_selected_pack_size(self):
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
catalog=Mock(root=Path(tmp)/'models');entry={**INKLING,'id':'a'*64}
|
|
path=catalog.root/entry['id']/'model.basalt';path.parent.mkdir(parents=True)
|
|
with path.open('wb') as f:f.truncate(INKLING['size'])
|
|
self.assertEqual(BasaltRuntime(Path(tmp)/'runtime',catalog).prepared(entry),path)
|
|
path.write_bytes(b'bad')
|
|
with self.assertRaises(ValueError):BasaltRuntime(Path(tmp)/'runtime',catalog).prepared(entry)
|
|
|
|
def test_inkling_configuration_does_not_inherit_qwen_flags(self):
|
|
from basalt_worker import BasaltWorker
|
|
p=dict(api_id='inkling-2-mini',parameters=dict(context=32768,slots=1))
|
|
c=BasaltWorker.configuration(p,Path('/model.basalt'),12345,700,model_family='inkling2')
|
|
self.assertEqual(c['engine']['kv'],'fp8')
|
|
self.assertEqual(c['engine']['max-context'],32768)
|
|
self.assertEqual(c['models'][0]['vision'],'off')
|
|
for flag in ('resident-experts','expert-cache','prefill'):
|
|
self.assertNotIn(flag,c['engine'])
|
|
cmd=BasaltWorker.server_command(Path('/python'),Path('/source'),Path('/worker.json'),'synthetic',model_family='inkling2')
|
|
self.assertNotIn('--expert-profile',cmd)
|
|
|
|
def test_saved_inkling_identity_reaches_worker_config_and_command(self):
|
|
import json
|
|
from unittest.mock import patch
|
|
from basalt_worker import BasaltWorker
|
|
with tempfile.TemporaryDirectory() as tmp:
|
|
catalog=Mock();catalog.entry.return_value={**INKLING,'id':'a'*64}
|
|
runtime=Mock();runtime.paths.return_value=(Path('/python'),Path('/source'));runtime.prepared.return_value=Path('/model.basalt');runtime.root=Path(tmp)/'runtime'
|
|
w=BasaltWorker(Path(tmp)/'worker',catalog,runtime)
|
|
p=dict(id='synthetic',revision=1,api_id='inkling-2-mini',model_id='a'*64,parameters=dict(context=32768,slots=1,gpu_devices=['synthetic-gpu']))
|
|
def plan(*args):w.memory_plan={'reserve_mib':[700]}
|
|
response=Mock();response.__enter__=Mock(return_value=response);response.__exit__=Mock(return_value=False)
|
|
props=dict(is_sleeping=False,total_slots=1,default_generation_settings={'n_ctx':32768},basalt=dict(version=RECIPE['version'],capabilities=[]))
|
|
with patch.object(w,'plan',side_effect=plan),patch('basalt_worker.cpu_partition.load',return_value=None),patch('basalt_worker.subprocess.Popen') as popen,patch('basalt_worker.urllib.request.urlopen',return_value=response),patch('basalt_worker.json.load',return_value=props):
|
|
popen.return_value.poll.return_value=None
|
|
w.ensure(p)
|
|
cfg=json.loads((w.root/'worker.json').read_text())
|
|
self.assertEqual(cfg['engine']['kv'],'fp8')
|
|
self.assertNotIn('--expert-profile',popen.call_args.args[0])
|
|
self.assertEqual(w.memory_plan['kv'],'fp8')
|
|
|
|
if __name__=='__main__':unittest.main()
|