Files
Athena-Deck/deploy/install_strata_vision.py
T

63 lines
3.0 KiB
Python

#!/usr/bin/env python3
"""Install official Strata CPU image encoder; never restart or change a worker."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import shutil
import subprocess
import urllib.request
SOURCE = {
'repo': 'ISTA-DASLab/Qwen3.8-Flash-Next-GSQ-RCO-GGUF',
'revision': 'ed59f92082b1e93c0e96d60a8b11aab089b52f09',
'file': 'mmproj-Qwen3.8-Flash-Next-BF16.gguf',
'size': 907543008,
'sha256': 'b1a82259702816a5330d7bd7607cd9676b11780e79ff7348c21103ff3ce49bd0',
}
def digest(path):
with path.open('rb') as stream:
return hashlib.file_digest(stream, 'sha256').hexdigest()
def install(runtime, storage):
runtime, storage = Path(runtime).resolve(), Path(storage).resolve()
source = runtime / 'source'
recipe = json.loads((Path(__file__).resolve().parent.parent / 'strata_sources.json').read_text())
revision = subprocess.check_output(['git', '-C', source, 'rev-parse', 'HEAD'], text=True).strip()
if revision != recipe['code']:
raise ValueError('Strata source revision differs from the Deck recipe')
target = storage / 'vision' / SOURCE['file']
target.parent.mkdir(parents=True, exist_ok=True)
valid = target.is_file() and target.stat().st_size == SOURCE['size'] and digest(target) == SOURCE['sha256']
if not valid:
partial = target.with_suffix('.gguf.partial')
url = 'https://huggingface.co/{repo}/resolve/{revision}/{file}'.format(**SOURCE)
with urllib.request.urlopen(url, timeout=120) as response, partial.open('wb') as out:
shutil.copyfileobj(response, out, 1024 * 1024)
if partial.stat().st_size != SOURCE['size'] or digest(partial) != SOURCE['sha256']:
partial.unlink(missing_ok=True)
raise ValueError('Projector size or checksum differs from original source')
os.replace(partial, target)
cmake = source / '.venv/bin/cmake'
build = source / 'build-vision-cpu'
env = dict(os.environ, PATH=str(cmake.parent) + os.pathsep + os.environ.get('PATH', ''))
subprocess.run([str(cmake), '-S', str(source / 'tools/vision'), '-B', str(build),
'-G', 'Ninja', '-DCMAKE_BUILD_TYPE=Release',
'-DLLAMA_DIR=' + str(source / 'third_party/llama.cpp'),
'-DSTRATA_VISION_CUDA=OFF', '-DSTRATA_PORTABLE=ON'], check=True, env=env)
subprocess.run([str(cmake), '--build', str(build), '--target', 'strata-vision', '-j', '2'], check=True, env=env)
executable = source / 'engine/strata-vision'
shutil.copy2(build / 'bin/strata-vision', executable)
manifest = dict(SOURCE, code=revision, device='cpu', executable=str(executable), path=str(target))
(runtime / 'vision-ready.json').write_text(json.dumps(manifest, indent=2))
print(json.dumps(manifest))
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('--runtime', required=True)
parser.add_argument('--storage', required=True)
args = parser.parse_args()
install(args.runtime, args.storage)