v2: SS_RATE 0.25->0.35, gen tests step_35000/50000/post-bump step_5000, bf16 memmap gen loader (GitHub 71eb492)
b64b9c1 verified Download scripts/ckpt_to_bf16raw.py from thefinalboss/fractus-cte-atom: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/thefinalboss/fractus-cte-atom/resolve/main/scripts/ckpt_to_bf16raw.py
- Command line
-
hf download hf://thefinalboss/fractus-cte-atom/scripts/ckpt_to_bf16raw.py
-
curl -L -o ckpt_to_bf16raw.py https://huggingface.co/thefinalboss/fractus-cte-atom/resolve/main/scripts/ckpt_to_bf16raw.py
1.03 kB
| """Stream an fp32 Fractus checkpoint (.pt/.bin, {'model_state','config'}) into a raw bf16 blob + JSON index, | |
| one tensor at a time (low anon RSS). gen_block.py loads it via np.memmap (file-backed pages, no OOM risk). | |
| Usage: python3 scripts/ckpt_to_bf16raw.py IN.pt OUT_DIR""" | |
| import sys,os,json,torch,numpy as np | |
| src,dst=sys.argv[1],sys.argv[2]; os.makedirs(dst,exist_ok=True) | |
| ck=torch.load(src,map_location='cpu',weights_only=False,mmap=True) | |
| sd=ck['model_state']; idx={'config':ck['config'],'tensors':{}}; off=0 | |
| with open(os.path.join(dst,'weights.bf16'),'wb') as f: | |
| for k,t in sd.items(): | |
| if t.is_floating_point(): b=t.detach().to(torch.bfloat16).contiguous().view(torch.int16); dt='bfloat16' | |
| else: b=t.detach().contiguous(); dt=str(t.dtype).split('.')[-1] | |
| a=b.numpy(); f.write(a.tobytes()); n=a.nbytes | |
| idx['tensors'][k]={'off':off,'nbytes':n,'shape':list(t.shape),'dtype':dt}; off+=n; del b,a | |
| json.dump(idx,open(os.path.join(dst,'index.json'),'w')) | |
| print('wrote',off,'bytes',len(sd),'tensors') | |