"""Local component loading from the exact private snapshot; not the answer pipeline. This relocates paths for a downloaded asset repository. It does not replace the frozen image bootstrap, flags, router, sampler, prompts or observer. """ import argparse,hashlib,importlib.util,json from pathlib import Path HERE=Path(__file__).resolve().parent MAIN_SOURCE_SHA256='7a4df6453eba63c01e7638a5ea402e78653a47f83fb7e25d4cf53f030ef06cf6' PUBLIC_QWEN_IMAGE_PATH='/app/.cache/huggingface/hub/models--Qwen--Qwen3-VL-8B-Instruct/snapshots/0c351dd01ed87e9c1b53cbc748cba10e6187ff3b' def local_module(path,name,expected=None): b=path.read_bytes() if expected and hashlib.sha256(b).hexdigest()!=expected:raise ValueError('Component source identity differs') spec=importlib.util.spec_from_file_location(name,path);m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m);return m def load_components(root,manifest,component='all'): root=Path(root).absolute() verifier=local_module(HERE/'verify_assets.py','_segment_hf_asset_verifier') custody=verifier.verify(root,Path(manifest)) # Tensor libraries are imported only after all50 exact local byte checks. import torch from transformers import AutoProcessor,AutoModelForImageTextToText,Owlv2Processor,Owlv2ForObjectDetection from peft import PeftModel qwen=root/'upstream/qwen3-vl-8b-instruct' loaded={};report={'custody':custody,'scope':'Component loading only; no answer-path/platform equivalence claim.'} if component in ('all','main'): main=local_module(HERE/'component_source/segment_unmerged_main.py','_segment_hf_exact_main',MAIN_SOURCE_SHA256) # Relocate only two path constants in this fresh local module. Exact source # bytes, verification, parameter/adapter checks and arithmetic stay unchanged. main.MODEL_ROOT=root;main.BASE_PATH=str(qwen) model,processor,health=main.load_main();loaded['main']=(model,processor);report['main']=health if component in ('all','temporal'): apath=root/'temporal_adapter';cfg=json.loads((apath/'adapter_config.json').read_text()) if cfg['base_model_name_or_path']!=PUBLIC_QWEN_IMAGE_PATH:raise ValueError('Temporal config public-base identity differs') # Same operation/argument sequence as frozen segment_temporal_seam.py: only # base_id and apath refer to their fully verified local snapshot locations. base_id=str(qwen) processor=AutoProcessor.from_pretrained(base_id,trust_remote_code=True,local_files_only=True) base=AutoModelForImageTextToText.from_pretrained(base_id,torch_dtype=torch.bfloat16,device_map='cuda',attn_implementation='sdpa',trust_remote_code=True,local_files_only=True) model=PeftModel.from_pretrained(base,apath,local_files_only=True).merge_and_unload() model.eval();loaded['temporal']=(model,processor) report['temporal']={'parameters':sum(p.numel() for p in model.parameters()),'merged_once':True,'selected_adapter_sha256':'87fc446ac0d8cf6a3d6147f3d959ec21bdee1c806e00dc74f5a1ffe9e6ac7878'} if report['temporal']['parameters']!=8767123696:raise ValueError('Temporal parameter count differs') if component in ('all','owlv2'): model_id=str(root/'upstream/owlv2-large-patch14-ensemble') processor=Owlv2Processor.from_pretrained(model_id,local_files_only=True) model=Owlv2ForObjectDetection.from_pretrained(model_id,local_files_only=True).to('cuda') model.eval();loaded['owlv2']=(model,processor) report['owlv2']={'parameters':sum(p.numel() for p in model.parameters()),'dtype':str(next(model.parameters()).dtype)} if report['owlv2']!={'parameters':437610760,'dtype':'torch.float32'}:raise ValueError('OWLv2 parameter/dtype identity differs') return loaded,report def main(): p=argparse.ArgumentParser();p.add_argument('--root',required=True);p.add_argument('--manifest',required=True);p.add_argument('--component',choices=['all','main','temporal','owlv2'],default='all');a=p.parse_args();loaded,report=load_components(a.root,a.manifest,a.component);print(json.dumps(report,sort_keys=True,indent=2));return loaded if __name__=='__main__':main()