Download validate.py from gatilin/openvision3_base_latent_visual_encoder: direct link, hf CLI and curl.
- Browser
- Download file 3.39 kB
-
https://huggingface.co/gatilin/openvision3_base_latent_visual_encoder/resolve/main/validate.py
- Command line
-
hf download hf://gatilin/openvision3_base_latent_visual_encoder/validate.py
-
curl -L -o validate.py https://huggingface.co/gatilin/openvision3_base_latent_visual_encoder/resolve/main/validate.py
3.39 kB
| import hashlib,json,time | |
| from pathlib import Path | |
| import torch | |
| torch.set_num_threads(4) | |
| from safetensors.torch import save_file,load_file | |
| from component import load_model | |
| r=Path(__file__).parent;checks=[];start=time.monotonic() | |
| def check(name,ok,**details): | |
| assert ok,(name,details) | |
| checks.append({'name':name,'passed':True,**details});print(name,details,flush=True) | |
| src=Path('work/further_unified_1021/UCSC-VLAA--openvision3-vit-base-patch2-32/source.bin') | |
| with src.open('rb') as f:digest=hashlib.file_digest(f,'sha256').hexdigest() | |
| check('official_source_LFS_SHA256',digest=='9d55ca6e9c4bd404dfac552ad65dae673274b28aeffe8f3f00bd7047a1db465e') | |
| original=torch.load(src,map_location='cpu',weights_only=True) | |
| if 'state_dict' in original:original=original['state_dict'] | |
| if not (r/'model.safetensors').exists():save_file({k:v.contiguous() for k,v in original.items()},str(r/'model.safetensors')) | |
| selected=load_file(str(r/'model.safetensors')) | |
| hashes={} | |
| for k,v in original.items(): | |
| assert k in selected and torch.equal(v,selected[k]) and v.dtype==selected[k].dtype | |
| hashes[k]=hashlib.sha256(v.contiguous().reshape(-1).view(torch.uint8).numpy().tobytes()).hexdigest() | |
| check('all_150_tensor_values_and_dtypes',len(original)==len(selected)==150) | |
| (r/'tensor_sha256.json').write_text(json.dumps(hashes,indent=2)+'\n') | |
| del selected,original | |
| m=load_model(r) | |
| check('native_150entry_strict_load',len(m.state_dict())==150) | |
| check('16channel_latent_stem',tuple(m.conv1.weight.shape)==(768,16,2,2)) | |
| with torch.inference_mode(): | |
| z=torch.linspace(-1,1,16*32*32).reshape(1,16,32,32) | |
| pooled,tokens=m(z) | |
| check('256_patch_token_geometry',tuple(tokens.shape)==(1,256,768) and torch.isfinite(tokens).all().item()) | |
| check('finite_pooled_embedding',tuple(pooled.shape)==(1,768) and torch.isfinite(pooled).all().item()) | |
| direct=m.ln_post(tokens.mean(1))@m.proj | |
| check('native_average_pool_and_projection',torch.equal(pooled,direct)) | |
| bpool,btokens=m(torch.cat([z,z*.5])) | |
| check('batched_latent_forward',tuple(btokens.shape)==(2,256,768) and torch.isfinite(bpool).all().item()) | |
| check('batch_independence',torch.allclose(btokens[0],tokens[0],atol=3e-5,rtol=3e-5),max_abs=(btokens[0]-tokens[0]).abs().max().item()) | |
| report={'strict_load':True,'source_tensor_bytes_equal':True,'checks':checks,'smoke':{'passed':True,'device':'cpu','dtype':'float32'},'elapsed_seconds':time.monotonic()-start,'limitations':['Latent-encoder test only; it takes 16-channel 32x32 VAE latents, not RGB pixels.','No VAE or diffusion/image decoder exists in this 150-entry checkpoint.','Original RGB-to-latent preprocessing depends on an external FLUX VAE; no such extra checkpoint was downloaded for this test.','Local verification only; checkpoint weights have not been republished while their explicit license is unconfirmed.']} | |
| (r/'validation.json').write_text(json.dumps(report,indent=2)+'\n') | |
| (r/'extraction.json').write_text(json.dumps({'source_repo':'UCSC-VLAA/openvision3-vit-base-patch2-32','source_revision':'7c5fbd37faab5091a1fa29d3ab4f6760d7c87c28','source_file':'open_clip_pytorch_model.bin','source_file_lfs_sha256':digest,'source_tensor_bytes_equal':True,'tensor_count':150,'operation':'Safe weights-only torch.load followed by safetensors serialization; all original trained entries and dtype preserved.'},indent=2)+'\n') | |
| print('OPENVISION LOCAL VALIDATED',len(checks),flush=True) | |