Files
leleka/scripts/smoke-runtime-profile.py
T
Pavlo Ratushnyi 4013e0c9bd
Desktop foundation / core (ubuntu-latest) (push) Failing after 28s
Desktop foundation / core (macos-latest) (push) Canceled after 0s
Desktop foundation / core (windows-latest) (push) Canceled after 0s
Linux / verify (push) Canceled after 0s
Linux / keyless-cuda (push) Canceled after 0s
Linux / static-cuda-package (push) Canceled after 0s
Linux / hosted-cuda-package (push) Canceled after 0s
Linux / linux-static-cli (push) Canceled after 0s
Linux / linux-cli-container (push) Canceled after 0s
Linux / release-cli (push) Canceled after 0s
Import tracked Strata Next source snapshot
2026-10-05 18:15:08 +02:00

97 lines
6.0 KiB
Python

#!/usr/bin/env python3
"""Actual verified-GGUF provisioning; metadata admission only, synthetic CPU tensors."""
import hashlib
import http.server
import importlib.util
import json
import os
from pathlib import Path
import struct
import subprocess
import sys
import tempfile
import threading
def main():
binary = str(Path(sys.argv[1]).resolve())
spec = importlib.util.spec_from_file_location('pack_fixture', Path(__file__).with_name('smoke-native-pack.py'))
fixture = importlib.util.module_from_spec(spec); spec.loader.exec_module(fixture)
expected = {'block_count': 48, 'embedding_length': 2560, 'attention.head_count': 24,
'attention.head_count_kv': 2, 'expert_count': 512, 'expert_used_count': 10}
with tempfile.TemporaryDirectory(prefix='strata-runtime-profile-') as tmp:
root = Path(tmp).resolve(); source = root / 'http'; source.mkdir()
requests = []
class Source(http.server.SimpleHTTPRequestHandler):
def __init__(self, *args, **kwargs):
super().__init__(*args, directory=str(source), **kwargs)
def log_message(self, *_): pass
def do_GET(self):
requests.append(self.path); super().do_GET()
server = http.server.ThreadingHTTPServer(('127.0.0.1', 0), Source)
thread = threading.Thread(target=server.serve_forever, daemon=True); thread.start()
marker = root / 'started'
worker = root / 'worker.sh'
worker.write_text(f'#!/bin/sh\ntouch "{marker}"\nexit 1\n'); worker.chmod(0o700)
manifest = root / 'manifest.json'; config_path = root / 'config.json'
config = {'native_model': {'manifest': str(manifest), 'source_dir': str(root/'base'),
'output': str(root/'pack'), 'runtime_profile': 'qwen4exp-flash-next'},
'engine': {'executable': str(worker), 'max_restarts': 0}}
def publish(values, kind=4):
fields = [('qwen4exp.'+key, kind, struct.pack('<I', val)) for key,val in values.items()]
fixture.write_gguf(source/'model.gguf', fixture.fixtures(), extra_fields=fields)
data = (source/'model.gguf').read_bytes()
manifest.write_text(json.dumps({'schema_version': 1, 'files': [{'name': 'model.gguf',
'url': f'http://127.0.0.1:{server.server_port}/model.gguf',
'size': len(data), 'sha256': hashlib.sha256(data).hexdigest()}]}))
def run(cmd='provision', ok=True):
config_path.write_text(json.dumps(config))
r = subprocess.run([binary, cmd, '--config', str(config_path)], capture_output=True, timeout=30, env={'PATH': os.defpath})
assert (r.returncode == 0) == ok, (r.stdout, r.stderr)
return r
try:
publish(expected)
check = json.loads(run('check-config').stdout)
assert check['native_runtime_profile'] == 'qwen4exp-flash-next' and not check['native_runtime_profile_checked']
assert not requests and not (root/'base').exists()
config['native_model']['runtime_profile'] = 'unsupported'; run('check-config', ok=False)
assert not requests
config['native_model']['runtime_profile'] = 'qwen4exp-flash-next'
run(); assert requests == ['/model.gguf'] and not marker.exists()
receipt = (root/'pack/receipt.json').read_bytes()
original = {p.relative_to(root/'pack'):p.read_bytes() for p in (root/'pack').rglob('*') if p.is_file()}
# A validation-only profile must leave every generated byte unchanged.
config['native_model'].pop('runtime_profile'); config['native_model']['output'] = str(root/'baseline')
run(); assert requests == ['/model.gguf']
assert original == {p.relative_to(root/'baseline'):p.read_bytes() for p in (root/'baseline').rglob('*') if p.is_file()}
config['native_model']['runtime_profile'] = 'qwen4exp-flash-next'
for i, values in enumerate([{**expected, 'embedding_length': 1280},
{k:v for k,v in expected.items() if k!='block_count'},
{**expected, 'expert_used_count': 513}]):
publish(values)
config['native_model']['source_dir'] = str(root/f'bad-base-{i}')
config['native_model']['output'] = str(root/f'bad-pack-{i}')
r = run('serve', ok=False)
assert b'runtime_profile' in r.stderr
assert not (root/f'bad-pack-{i}').exists() and not (root/f'.bad-pack-{i}.native-model-lock').exists()
assert (root/'pack/receipt.json').read_bytes() == receipt and not marker.exists()
# Existing output created by the generic converter must be rechecked too.
config['native_model'].pop('runtime_profile')
run(); prior = (root/'bad-pack-2/receipt.json').read_bytes()
config['native_model']['runtime_profile'] = 'qwen4exp-flash-next'
assert b'exceeds' in run('serve', ok=False).stderr
assert (root/'bad-pack-2/receipt.json').read_bytes() == prior and not marker.exists()
# Pruned expert count is permitted without MTP, matching the engine guard.
publish({**expected, 'expert_count':256})
config['native_model']['source_dir'] = str(root/'pruned-base')
config['native_model']['output'] = str(root/'pruned-pack')
run(); n = len(requests)
server.shutdown(); server.server_close(); thread.join()
run(); assert len(requests) == n and not marker.exists()
finally:
if thread.is_alive(): server.shutdown(); server.server_close(); thread.join()
print('runtime profile passed: read-only unknown-profile rejection; verified HTTP source metadata faults before output/worker; previous version preserved; exact generated-file equality tolerance0; pruned/offline acceptance. Synthetic tensor geometry/values, no GPU or model quality qualification.')
if __name__ == '__main__': main()