SupremeD commited on
Commit
bf7656a
·
verified ·
1 Parent(s): 45035bc

Upload scripts/preextract.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. scripts/preextract.py +60 -0
scripts/preextract.py ADDED
@@ -0,0 +1,60 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python
2
+ """
3
+ Aether Phase-1 PRE-EXTRACT: run the frozen encoders ONCE, cache their features to disk.
4
+ This is the portability enabler — after this, alignment/adapters train on the cached
5
+ tensors with NO encoders loaded (fits 6900XT / Kaggle-T4 / Colab-T4 / any small GPU).
6
+
7
+ Writes /work/slivers_cache/<modality>/<id>.pt (raw encoder feature, pre-projection)
8
+ + /work/slivers_cache/index.jsonl ({id, modality, caption, feat_path, shape})
9
+ Encoders live only here (the big box); the cache travels.
10
+ Run on the rental MI300 (has all 3 encoders). Validated on a tiny mixed set.
11
+ """
12
+ import os, sys, json, torch
13
+ sys.path.insert(0,"/work")
14
+ import forward as F
15
+ dev=F.dev
16
+ CACHE="/work/slivers_cache"
17
+
18
+ def main():
19
+ torch.set_grad_enabled(False)
20
+ m=F.AetherPhase1().to(dev); m.eval()
21
+ os.makedirs(CACHE, exist_ok=True)
22
+ idx=[]
23
+ torch.manual_seed(42)
24
+
25
+ # ---- VISION items (image -> caption) ----
26
+ os.makedirs(f"{CACHE}/vision", exist_ok=True)
27
+ vcaps=["a red brick electrical panel on a wall","a blue ceramic coffee mug on a desk",
28
+ "three yellow pencils in a glass jar","a green circuit board with silver traces"]
29
+ for i,cap in enumerate(vcaps):
30
+ px=torch.randn(1,3,448,448) # (real pipeline: load actual Tier-A image)
31
+ feat=m.enc_vision(px).cpu() # (1025,3200) frozen features
32
+ p=f"{CACHE}/vision/v{i}.pt"; torch.save(feat,p)
33
+ idx.append({"id":f"v{i}","modality":"vision","caption":cap,"feat":p,"shape":list(feat.shape)})
34
+
35
+ # ---- AUDIO items (speech -> transcript) ----
36
+ os.makedirs(f"{CACHE}/audio", exist_ok=True)
37
+ acaps=["the meeting starts at nine tomorrow","turn off the main breaker first"]
38
+ for i,cap in enumerate(acaps):
39
+ mel=torch.randn(400,128); alen=torch.tensor([400])
40
+ feat=m.enc_audio(mel,alen).cpu() # (~100,1280)
41
+ p=f"{CACHE}/audio/a{i}.pt"; torch.save(feat,p)
42
+ idx.append({"id":f"a{i}","modality":"audio","caption":cap,"feat":p,"shape":list(feat.shape)})
43
+
44
+ # ---- 3D geometry items (mesh -> caption); pre-extract SLAT latent + voxel coords ----
45
+ os.makedirs(f"{CACHE}/geom", exist_ok=True)
46
+ gcaps=["a low-poly wooden crate","a cylindrical steel conduit fitting"]
47
+ for i,cap in enumerate(gcaps):
48
+ M=300; vz=torch.randint(0,64,(M,3)); b=torch.zeros(M,1)
49
+ coords=torch.cat([b,vz.flip(-1).float()],1); feats=torch.randn(M,1024)
50
+ gf,gc=m.enc_geom(coords,feats) # (M',8),(M',4)
51
+ gcz=(gc[:,[1,2,3]].float()/gc[:,[1,2,3]].float().max().clamp(min=1)*15).long()
52
+ p=f"{CACHE}/geom/g{i}.pt"; torch.save({"feat":gf.cpu(),"xyz":gcz.cpu()},p)
53
+ idx.append({"id":f"g{i}","modality":"geom","caption":cap,"feat":p,"shape":list(gf.shape)})
54
+
55
+ json.dump(idx, open(f"{CACHE}/index.jsonl","w"), indent=2)
56
+ print(f"PRE-EXTRACT OK: {len(idx)} items cached to {CACHE}")
57
+ for r in idx: print(" ",r["id"],r["modality"],r["shape"],"->",os.path.getsize(r["feat"])//1024,"KB")
58
+
59
+ if __name__=="__main__":
60
+ main()