fastframes-l-video-components / validate_refiner.py
gatilin's picture
Document FastFrames-L component bundle and tests
be2154d verified
Raw History Blame Contribute Delete
1.55 kB
import json,sys,pathlib,torch
from safetensors.torch import load_file
sys.path.insert(0,str(pathlib.Path(__file__).resolve().parent))
from fastframes.models.kv_refinement import KVRefinementNetwork
root=pathlib.Path(__file__).resolve().parent;torch.manual_seed(11);torch.set_num_threads(4)
with torch.device('meta'):m=KVRefinementNetwork(dim=5120,num_heads=40,head_dim=128,num_blocks=40)
s=load_file(str(root/'kv_refiner.safetensors'));res=m.load_state_dict(s,strict=True,assign=True);assert not res.missing_keys and not res.unexpected_keys;m=m.eval()
with torch.inference_mode(),torch.autocast('cpu',dtype=torch.bfloat16):
e=m.embed_timestep(500,1,'cpu',torch.bfloat16);phi=m.compute_phi(torch.randn(1,2,5120,dtype=torch.bfloat16),e);nk=torch.randn(40,2,5120,dtype=torch.bfloat16);nv=torch.randn(40,2,5120,dtype=torch.bfloat16);k,v=m.repair_all(nk,nv,phi,e);assert k.shape==v.shape==nk.shape and torch.isfinite(k).all() and torch.isfinite(v).all()
report={'passed':True,'scope':'FastFrames-L KV refinement network only','strict_load':True,'tensors':len(s),'source_full_file_sha256':'841047b9226cf770ca19f99ef718edcb57db29c29ee58a64f9ae5dc1d6fbdf74','phi_shape':list(phi.shape),'cache_shape':list(k.shape),'mean_key_change':float((k.float()-nk.float()).abs().mean()),'mean_value_change':float((v.float()-nv.float()).abs().mean()),'device':'CPU BF16 autocast','inputs':'synthetic latent and cache tensors','full_dit_forward_tested':False};(root/'validation_refiner.json').write_text(json.dumps(report,indent=2)+'\n');print(json.dumps(report),flush=True)