luxfer / runtime /training /streaming /runtime.py
mdxss's picture
Publish Luxfer early beta with runnable weights and language metadata
7b6f2cc verified
Raw History Blame Contribute Delete
1.73 kB
"""Load exact trained sparse overlays, without loading optimizer pickle in inference."""
import json
from pathlib import Path
from language_adapters.source_decoder import load_decoder_adapters
from weights.identity import checkpoint_fingerprint,file_sha256
from training.streaming.state import verify_snapshot,TileStore
from training.streaming.sparse import attach_sparse
def install_overlay(engine,checkpoint):
checkpoint=Path(checkpoint)
if not (checkpoint/'manifest.json').exists():
pointer='BEST.json' if (checkpoint/'BEST.json').exists() else 'LATEST.json'
record=json.loads((checkpoint/pointer).read_text());name=record['checkpoint']
if Path(name).name!=name:raise ValueError('Invalid snapshot pointer')
checkpoint=checkpoint/'recovery'/name
manifest,runtime,store=verify_snapshot(checkpoint)
identity=manifest['identity']
if identity['base_weight_sha256']!=checkpoint_fingerprint(engine.path) or identity['base_config_sha256']!=file_sha256(engine.path/'config.json') or identity['tokenizer_sha256']!=file_sha256(engine.path/'tokenizer.jsonl'):raise ValueError('Overlay base identity differs')
bank,config=load_decoder_adapters(checkpoint/'focus');bank.install(engine.model);expansions,router=attach_sparse(engine.model,bank,store)
router.allowed_routes=set(identity['scope_pairs'])
engine.decoder_router=router;engine.decoder_adapter_config=config
engine.training_overlay_info=dict(step=runtime['step'],scope_pairs=identity['scope_pairs'],partial=runtime.get('scope',{}).get('partial',True),quality='Research overlay; no automatic promotion')
return dict(step=runtime['step'],trained_tiles=len(store.catalog),bank=bank,store=store,expansions=expansions)