57 lines
4.1 KiB
Python
57 lines
4.1 KiB
Python
"""Prepare pinned SVC weights/runtime without activating Deck or a GPU."""
|
|
import argparse,hashlib,json,os,shutil,subprocess,sys,tarfile,urllib.request
|
|
from pathlib import Path
|
|
REV='81aeb3ae772c70093c3de74dc23c92d983801ae4'
|
|
SOURCE_SHA256='b1a1e9615f8832012396aa306a5de5a6157f4c193c4ce08b3ee35a7983dcee7b'
|
|
HERE=Path(__file__).resolve().parent
|
|
|
|
def digest(p):
|
|
h=hashlib.sha256()
|
|
with p.open('rb') as f:
|
|
for b in iter(lambda:f.read(8*1024*1024),b''):h.update(b)
|
|
return h.hexdigest()
|
|
|
|
def download(url,p,sha=None,size=None):
|
|
if p.exists() and (size is None or p.stat().st_size==size) and (sha is None or digest(p)==sha):return
|
|
p.parent.mkdir(parents=True,exist_ok=True);part=p.with_suffix(p.suffix+'.part')
|
|
print('Download:',p.name,flush=True)
|
|
with urllib.request.urlopen(url,timeout=120) as r,part.open('wb') as f:shutil.copyfileobj(r,f,8*1024*1024)
|
|
if size is not None and part.stat().st_size!=size:raise RuntimeError('Size mismatch: '+p.name)
|
|
if sha and digest(part)!=sha:raise RuntimeError('SHA256 mismatch: '+p.name)
|
|
part.replace(p)
|
|
|
|
def main():
|
|
parser=argparse.ArgumentParser();parser.add_argument('root',type=Path);args=parser.parse_args();root=args.root.resolve();root.mkdir(parents=True,exist_ok=True)
|
|
if shutil.disk_usage(root).free<20*1024**3:raise RuntimeError('Preparation needs 20 GiB free; no existing files are deleted.')
|
|
source=root/'source';assets=root/'assets';venv=root/'python';tmp=root/'tmp';tmp.mkdir(exist_ok=True)
|
|
ready=root/'ready.json';ready.unlink(missing_ok=True)
|
|
if not source.exists():
|
|
archive=root/'source.tar.gz';download('https://codeload.github.com/Soul-AILab/SoulX-Singer/tar.gz/'+REV,archive,SOURCE_SHA256)
|
|
with tarfile.open(archive) as tar:tar.extractall(tmp,filter='data')
|
|
(tmp/('SoulX-Singer-'+REV)).rename(source);archive.unlink()
|
|
marker=source/'.athena-source-revision'
|
|
if marker.exists() and marker.read_text().strip()!=REV:raise RuntimeError('Different source revision; do not overwrite.')
|
|
marker.write_text(REV+'\n')
|
|
# Upstream hardcodes a floating Whisper repo. Use the pinned local asset instead.
|
|
encoder=source/'soulxsinger/models/modules/whisper_encoder.py';text=encoder.read_text()
|
|
if 'SOULX_WHISPER_PATH' not in text:
|
|
if text.count('"openai/whisper-base"')!=2:raise RuntimeError('Upstream Whisper constructor changed.')
|
|
text=text.replace('import torch\n','import torch\nimport os\n',1).replace('"openai/whisper-base"','os.environ["SOULX_WHISPER_PATH"]');encoder.write_text(text)
|
|
manifest=json.loads((HERE/'assets.json').read_text())
|
|
for item in manifest:
|
|
dest=assets/('whisper-base' if item['repo']=='openai/whisper-base' else 'preprocess' if item['repo'].endswith('Preprocess') else 'soulx')/item['filename']
|
|
download('https://huggingface.co/'+item['repo']+'/resolve/'+item['revision']+'/'+item['filename'],dest,item['sha256'],item['size'])
|
|
item['sha256']=digest(dest)
|
|
(root/'assets-manifest.json').write_text(json.dumps(manifest,indent=2)+'\n')
|
|
env=dict(os.environ,CUDA_VISIBLE_DEVICES='',OMP_NUM_THREADS='2',MKL_NUM_THREADS='2',TMPDIR=str(tmp),SOULX_WHISPER_PATH=str(assets/'whisper-base'),HF_HUB_OFFLINE='1')
|
|
if not venv.exists():subprocess.run([sys.executable,'-m','venv',str(venv)],check=True)
|
|
python=venv/'bin/python'
|
|
subprocess.run([str(python),'-m','pip','install','--no-cache-dir','torch==2.8.0','torchaudio==2.8.0','--index-url','https://download.pytorch.org/whl/cu128'],check=True,env=env)
|
|
subprocess.run([str(python),'-m','pip','install','--no-cache-dir','-r',str(HERE/'requirements.lock' if (HERE/'requirements.lock').exists() else HERE/'requirements.txt')],check=True,env=env)
|
|
subprocess.run([str(python),'-m','pip','check'],check=True,env=env)
|
|
lock=subprocess.check_output([str(python),'-m','pip','freeze'],text=True,env=env);(root/'requirements.lock').write_text(lock)
|
|
subprocess.run([str(python),str(HERE/'verify.py'),str(root)],check=True,env=env,cwd=source)
|
|
ready.write_text(json.dumps({'source_revision':REV,'verification':'CPU strict checkpoint load, F0 and decoder smoke tests','active':False},indent=2)+'\n')
|
|
print('READY: weights and isolated runtime prepared; no service/profile/GPU activated.',flush=True)
|
|
if __name__=='__main__':main()
|