File size: 1,324 Bytes
ec01e2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
"""Write the only EmbeddingGemma 2 tensors the stage 6 model needs that best.pt does not hold.

best.pt saves trainable parameters only (train.py weights_state). 482 audio-tower tensors stay behind in the base model: 480 clip
bounds (input_min/max, output_min/max of each Gemma4ClippableLinear, finite, used in forward) and output_proj (unused by the STT
path, kept so a strict load passes). This writes them as float32, the dtype the project's from_pretrained(dtype=float32) uses.

    python extract_tower_rest.py EG2_MODEL.safetensors BEST.pt OUT.safetensors
"""
import sys

import torch
from safetensors import safe_open
from safetensors.torch import save_file

src, ckpt, out = sys.argv[1:4]
held = {k[len("tower."):] for k in torch.load(ckpt, map_location="cpu", weights_only=False, mmap=True)["model"] if k.startswith("tower.")}
rest = {}
with safe_open(src, "pt") as f:
    for k in f.keys():
        if k.startswith("audio_tower.") and k[len("audio_tower."):] not in held:
            rest["tower." + k[len("audio_tower."):]] = f.get_tensor(k).float().clone()
save_file(rest, out, metadata={"source": "google/embeddinggemma-2 snapshot f9972ac22e696a105c482202646979e33e4b5a1e, audio_tower tensors absent from stage 6 best.pt"})
print(f"{len(rest)} tensors, {sum(t.numel() for t in rest.values())} values -> {out}")