File size: 3,484 Bytes
f69e160
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from pathlib import Path
import json,sys,time,torch
root=Path(__file__).resolve().parent;sys.path.insert(0,str(root.resolve()))
from component import load_model,patchify_pixels,encode_pixels,decode_codes,code_features
from native.visual import restore_spatial_structure_and_convert_to_images
torch.set_num_threads(4);checks=[];t=time.time()
def check(name,ok,**details):
 assert ok,(name,details)
 checks.append(dict(name=name,passed=True,**details));print(name,details,flush=True)
m=load_model(root);check('strict_base_codec_load',True,tensors=len(m.state_dict()))
books=m.model.visual_tokenizer.visual_bridge_model.quantizer.quantize.codebooks
check('native_shared_codebook_object',all(book is books[0] for book in books))
check('shared_codebook_storage',len({book.embed.data_ptr() for book in books})==1)
with torch.inference_mode():
 for h,w in [(112,112),(56,84)]:
  pixels=torch.linspace(0,1,3*h*w).reshape(1,3,h,w);p,grid=patchify_pixels(pixels)
  recovered=restore_spatial_structure_and_convert_to_images(p,grid,14)[0]
  mean=pixels.new_tensor([.48145466,.4578275,.40821073])[:,None,None];std=pixels.new_tensor([.26862954,.26130258,.27577711])[:,None,None]
  check(f'patch_layout_inverse_{h}x{w}',torch.equal(recovered,(pixels[0]-mean)/std),patches=list(p.shape))
  ids,g=encode_pixels(m,pixels);check(f'rvq_ids_{h}x{w}',ids.shape==(h//28*w//28,8) and ids.min()>=0 and ids.max()<16384,shape=list(ids.shape),minimum=int(ids.min()),maximum=int(ids.max()))
  features=code_features(m,ids);check(f'lookup_sum_{h}x{w}',features.shape==(h//28*w//28,3584) and torch.isfinite(features).all().item())
  images=decode_codes(m,ids,g);y=images[0];check(f'base_reconstruction_{h}x{w}',y.shape==(3,h,w) and torch.isfinite(y).all().item(),shape=list(y.shape),mse=(y-((pixels[0]-mean)/std)).square().mean().item())
 hidden=m.model.visual_tokenizer.visual_embedding_layer(torch.zeros(3,3072,dtype=torch.bfloat16));check('language_visual_embedding_interface',hidden.shape==(3,3072) and torch.isfinite(hidden).all().item())
 pixels=torch.linspace(-1,1,3*64*64).reshape(1,3,64,64);z=m.image_refiner.vae.encode(pixels).latent_dist.mode();y=m.image_refiner.vae.decode(z).sample
 check('refiner_vae_reconstruction',z.shape==(1,16,8,8) and y.shape==pixels.shape and torch.isfinite(y).all().item(),latent_shape=list(z.shape))
 c=m.image_refiner.cond_proj(torch.randn(4,3584));check('refiner_condition_projection',c.shape[0]==4 and torch.isfinite(c).all().item(),shape=list(c.shape))
aliases=json.loads((root/'alias_verification.json').read_text());check('source_shared_aliases_exact',len(aliases)==21)
check('base_source_bytes_exact',json.loads((root/'extraction.json').read_text())['source_tensor_bytes_equal'] and json.loads((root/'decoder/extraction.json').read_text())['source_tensor_bytes_equal'])
result=dict(strict_load=True,source_tensor_bytes_equal=True,checks=checks,smoke=dict(passed=True,device='cpu',visual_dtype='bfloat16',base_decoder_dtype='float32',quantizer_dtype='float32'),elapsed_seconds=time.time()-t,limitations=['This report covers the native dNaViT/RVQ/base decoder and refiner VAE/condition projection. Full flow refiner has a separate validation report.','No full LongCat text/audio backbone or VQA/T2I benchmark.','CPU compatibility uses a vendored Qwen2.5-VL window-attention implementation and preserves native decoder behavior.'])
(root/'validation.json').write_text(json.dumps(result,indent=2)+'\n');print('LONGCAT BASE VALIDATED',result['elapsed_seconds'],flush=True)