Files

60 lines
3.0 KiB
Python

"""Pinned public Audio8 assets and an own CPU-only venv; no production writes."""
from pathlib import Path
import hashlib
import json
import os
import subprocess
import sys
import time
import urllib.request
ROOT = Path('/data/athena-audio8-cpu-20261027')
meta = json.loads((ROOT/'model-source.json').read_text())
assert meta['id'] == 'Edge0/audio8-TTS-0.1B-ONNX-INT8'
revision = '317c12d4e0da83847b594fcf8bd74bf2c76615ec'
assert meta['sha'] == revision
allowed = {'config.json', 'runtime_manifest.json', 'tokenizer/tokenizer.json',
'reference_codes.npy', 'registration/registration_manifest.json'}
rows = []
for item in meta['siblings']:
name = item['rfilename']
if name not in allowed and not name.endswith(('.onnx', '.onnx.data')):
continue
path = ROOT/'model'/name
path.parent.mkdir(parents=True, exist_ok=True)
expected = item.get('lfs', {}).get('sha256')
def digest(p):
with p.open('rb') as stream:
return hashlib.file_digest(stream, 'sha256').hexdigest()
if not path.exists() or path.stat().st_size != item['size'] or expected and digest(path) != expected:
tmp = path.with_name(path.name+'.partial')
url = f'https://huggingface.co/{meta["id"]}/resolve/{revision}/{name}?download=1'
start = time.monotonic()
with urllib.request.urlopen(url, timeout=90) as response, tmp.open('wb') as stream:
while chunk := response.read(1024*1024):
stream.write(chunk)
assert tmp.stat().st_size == item['size'], name
actual = digest(tmp)
assert not expected or actual == expected, name
tmp.replace(path)
print(json.dumps({'downloaded': name, 'bytes': path.stat().st_size,
'seconds': time.monotonic()-start}), flush=True)
actual = digest(path)
rows.append(dict(path=name, size=path.stat().st_size, sha256=actual,
publisher_lfs_verified=bool(expected)))
(ROOT/'download-manifest.json').write_text(json.dumps(rows, indent=2))
if not (ROOT/'venv/bin/python').exists():
subprocess.run([sys.executable, '-m', 'venv', str(ROOT/'venv')], check=True)
environment = os.environ.copy()
environment.update(PIP_DISABLE_PIP_VERSION_CHECK='1', PIP_NO_INPUT='1',
PIP_CACHE_DIR=str(ROOT/'pip-cache'))
subprocess.run([str(ROOT/'venv/bin/python'), '-m', 'pip', 'install', '--only-binary=:all:',
'numpy==2.2.6', 'onnxruntime==1.23.2', 'tokenizers==0.22.1',
'soundfile==0.13.1', 'scipy==1.16.3'], check=True, env=environment)
subprocess.run([str(ROOT/'venv/bin/python'), '-m', 'pip', 'check'], check=True, env=environment)
freeze = subprocess.check_output([str(ROOT/'venv/bin/python'), '-m', 'pip', 'freeze'], text=True)
(ROOT/'requirements.txt').write_text(freeze)
assert not any(n in freeze.lower() for n in ['torch==', 'onnxruntime-gpu', 'nvidia-'])
(ROOT/'prepared.json').write_text(json.dumps({'ok':True, 'model_revision':revision,
'files':len(rows)}, indent=2))
print('PREPARED', flush=True)