Detach legacy model mounts and migrate verified GGUF references

This commit is contained in:
Mikei386 committed 2026-10-06 17:02:26 +02:00
1 parent 08e70c9113
commit 8cefa0b043
7 files changed
+260 -7

No files matched your search

+5 -5
View File
@@ -160,15 +160,15 @@ def launch(config):
args += ['--mount','type=bind,src=/run/athena-deck-docker,dst=/run/athena-deck-docker,readonly','-e','DECK_DOCKER_HELPER_SOCKET=/run/athena-deck-docker/control.sock']
if config['gpu_telemetry']:
args += ['--gpus','all','-e','NVIDIA_DRIVER_CAPABILITIES=compute,utility']
if Path('/data/models').is_dir():
args+=['--mount','type=bind,src=/data/models,dst=/host/models,readonly','-e','DECK_HOST_DATA_DISK=/host/models']
# Model storage belongs to Deck. Never silently attach a legacy router tree.
args+=['-e','DECK_HOST_DATA_DISK=/var/lib/deck','-e','DECK_REFERENCE_MODELS=/var/lib/deck/reference-models']
if Path('/data/emergency-backups').is_dir():
args+=['--mount','type=bind,src=/data/emergency-backups,dst=/host/backups,readonly']
if config.get('reference_models'):
for folder,filename in [('qwen3.8-27b-iq4-mix','Qwen3.8-27B-IQ4-MIX.gguf'),('qwen3.8-27b-iq4-xs-pure','qwen3.8-27b-IQ4_XS-pure.gguf'),('qwen3.8-27b-abliterated','Qwen3.8-27B-ABLITERATED-Q4_K_M.gguf')]:
source=Path('/data/models')/folder/filename
if not source.is_file():raise RuntimeError('Referenzmodell fehlt; keine Ersatzpfade.')
args+=['--mount','type=bind,src='+str(source)+',dst=/reference-models/'+filename+',readonly']
source=base/'state/reference-models'/filename
if not source.is_file() or not source.resolve().is_relative_to((base/'state/models').resolve()):
raise RuntimeError('Deck-Referenzmodell fehlt; zuerst deploy/migrate_reference_models.py ausführen.')
args.append(config['image'])
run(*args)
+97
View File
@@ -0,0 +1,97 @@
"""Import verified legacy reference weights into Deck; no GPU or service changes."""
import argparse
import hashlib
import json
import os
from pathlib import Path
import shutil
import time
import urllib.parse
import urllib.request
def digest(path):
result = hashlib.sha256()
with path.open('rb') as stream:
for block in iter(lambda: stream.read(8 * 1024 * 1024), b''):
result.update(block)
return result.hexdigest()
def verify(path, source):
if path.is_symlink() or not path.is_file() or path.stat().st_size != source['size'] or digest(path) != source['sha256']:
raise ValueError('Modelldatei stimmt nicht mit Original überein: ' + str(path))
def migrate(state, legacy, sources):
models = state / 'models'
models.mkdir(parents=True, exist_ok=True)
refs = state / 'reference-models'
refs.mkdir(exist_ok=True)
report = []
for source in sources:
ident = hashlib.sha256((source['repo'] + source['revision'] + source['file']).encode()).hexdigest()
target = models / ident
target.mkdir(exist_ok=True)
weight = target / 'model.gguf'
url = 'https://huggingface.co/' + source['repo'] + '/resolve/' + source['revision'] + '/' + urllib.parse.quote(source['file'], safe='/')
upstream = json.load(urllib.request.urlopen('https://huggingface.co/api/models/' + source['repo'] + '/revision/' + source['revision'] + '?blobs=true', timeout=30))
item = next(x for x in upstream['siblings'] if x['rfilename'] == source['file'])
if upstream['sha'] != source['revision'] or item['size'] != source['size'] or item['lfs']['sha256'] != source['sha256']:
raise ValueError('Originalquelle stimmt nicht überein: ' + source['repo'])
action = 'already_present'
if not weight.exists():
if shutil.disk_usage(models).free < source['size'] + 10 * 1024**3:
raise ValueError('Zu wenig Speicher für Modellübernahme.')
partial = target / 'migration.partial'
if partial.exists():
raise ValueError('Unvollständige Übernahme vorhanden: ' + str(partial))
old = legacy / source['folder'] / source['file']
try:
if old.is_file():
verify(old, source)
shutil.copyfile(old, partial)
action = 'copied'
else:
with urllib.request.urlopen(url, timeout=60) as remote, partial.open('xb') as output:
shutil.copyfileobj(remote, output, 8 * 1024 * 1024)
action = 'downloaded'
verify(partial, source)
partial.replace(weight)
finally:
partial.unlink(missing_ok=True)
else:
verify(weight, source)
entry = target / 'entry.json'
if not entry.exists():
metadata = {k: source[k] for k in ('repo', 'revision', 'file', 'size', 'sha256')}
metadata.update(kind='chat', state='downloaded', runtime_ready=False, upstream_hash_verified=True, downloaded_at=time.time())
temp = target / 'entry.tmp'
temp.write_text(json.dumps(metadata, indent=2) + '\n')
temp.replace(entry)
else:
metadata = json.loads(entry.read_text())
if any(metadata.get(k) != source[k] for k in ('repo', 'revision', 'file', 'size', 'sha256')):
raise ValueError('Metadatenkonflikt: ' + str(entry))
if source['reference']:
link = refs / source['file']
relative = Path('..') / 'models' / ident / 'model.gguf'
if link.is_symlink():
if os.readlink(link) != str(relative):
raise ValueError('Referenzkonflikt: ' + str(link))
elif link.exists():
raise ValueError('Referenzkonflikt: ' + str(link))
else:
link.symlink_to(relative)
report.append(dict(file=source['file'], model_id=ident, action=action, sha256=source['sha256'], url=url))
print(source['file'] + ': ' + action + ', checksum verified', flush=True)
(state / 'reference-model-migration.json').write_text(json.dumps(report, indent=2) + '\n')
return report
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--state', type=Path, required=True)
parser.add_argument('--legacy', type=Path, default=Path('/data/models'))
args = parser.parse_args()
migrate(args.state, args.legacy, json.loads(Path(__file__).with_name('reference_model_sources.json').read_text()))
+61
View File
@@ -0,0 +1,61 @@
"""Recreate Deck with its existing image to detach verified legacy model mounts.
Requires an explicitly authorized maintenance window. Uses the same installer
launch recipe and restores the original container if startup fails.
"""
import argparse
import json
from pathlib import Path
import shutil
import time
import install
def rebind(base):
config = install.load_manifest(base)
previous = install.owned(config['name'], base)
if not previous:
raise RuntimeError('Deck-Container fehlt.')
if not any(m['Source'].startswith('/data/models') for m in previous['Mounts']):
print('Keine alten Modell-Mounts vorhanden.')
return
report = json.loads((base / 'state/reference-model-migration.json').read_text())
if len(report) != 4:
raise RuntimeError('Modellübernahme ist nicht vollständig.')
for row in report:
entry = base / 'state/models' / row['model_id']
metadata = json.loads((entry / 'entry.json').read_text())
if metadata['sha256'] != row['sha256'] or (entry / 'model.gguf').stat().st_size != metadata['size']:
raise RuntimeError('Modellübernahme stimmt nicht mit Metadaten überein.')
fallback = config['name'] + '-before-model-rebind'
if install.inspect(fallback):
raise RuntimeError('Rückfall-Containername belegt.')
shutil.copyfile(base / 'installation.json', base / ('installation-before-model-rebind-' + str(time.time_ns()) + '.json'))
was_running = previous['State']['Running']
if was_running:
install.run('docker', 'stop', '--time', '30', config['name'])
install.run('docker', 'rename', config['name'], fallback)
try:
install.launch(config)
install.ready(config)
current = install.owned(config['name'], base)
if any(m['Source'].startswith('/data/models') for m in current['Mounts']):
raise RuntimeError('Alte Modelle weiterhin eingebunden.')
except Exception:
if install.owned(config['name'], base):
install.run('docker', 'rm', '-f', config['name'])
install.run('docker', 'rename', fallback, config['name'])
if was_running:
install.run('docker', 'start', config['name'])
raise
install.run('docker', 'rm', fallback)
print('Deck mit unverändertem App-Image neu gestartet; alte Modell-Mounts entfernt.')
if __name__ == '__main__':
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--directory', type=Path, required=True)
parser.add_argument('--maintenance-window-approved', action='store_true', required=True)
args = parser.parse_args()
rebind(args.directory)
+6
View File
@@ -0,0 +1,6 @@
[
{"folder":"qwen3.8-27b-iq4-mix","repo":"vmarcelo/Qwen3.8-27B-MIX_GGUF","revision":"f922f9d9bbe67ede1c49e364d71737b8f067e49b","file":"Qwen3.8-27B-IQ4-MIX.gguf","size":14111614400,"sha256":"54879ae8738d5938f46cb3b8cbf16bf42b8c85b7d68d7c73f062b612ec183e36","reference":true},
{"folder":"qwen3.8-27b-iq4-xs-pure","repo":"jpetrina/Qwen3.8-27B-IQ4_XS-pure-GGUF","revision":"5a285a6217024a96be7064d6caf0a06121630ee1","file":"qwen3.8-27b-IQ4_XS-pure.gguf","size":14534384640,"sha256":"ea5a3c45d407f9b9e5d2c0d647f0ea600f486f6b86b92b56d0823ba073dae675","reference":true},
{"folder":"qwen3.8-27b-abliterated","repo":"Blackfrost-AI/Qwen3.8-27B-ABLITERATED-GGUF","revision":"994bb4e69663ec880a4d9a61604e6debc3a49b9a","file":"Qwen3.8-27B-ABLITERATED-Q4_K_M.gguf","size":16810716384,"sha256":"5d53637a59cfcd3a4d8354e254ffd44943e5a693da2405a3e228c62962355509","reference":true},
{"folder":"qwen3.8-27b-abliterated","repo":"Blackfrost-AI/Qwen3.8-27B-ABLITERATED-GGUF","revision":"994bb4e69663ec880a4d9a61604e6debc3a49b9a","file":"mmproj-Qwen3.8-27B-ABLITERATED-F16.gguf","size":927607424,"sha256":"2284099ce864f1023d721e6ef5eaef32bb56abdbc1dc561c6d91300f12ef2e4b","reference":false}
]