File size: 750 Bytes
22e0325 | 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 | # SPDX-License-Identifier: Apache-2.0
"""Checkpoint loading (CPU): model.safetensors -> {name: tensor} (bf16 as stored; the pooling head and the unused
packing position table are skipped)."""
from __future__ import annotations
import os
from typing import Dict
import torch
SKIP = ("visual.vision_model.head.", "visual.vision_model.embeddings.packing_position_embedding")
def load_weights(path: str) -> Dict[str, torch.Tensor]:
from safetensors import safe_open
p = os.path.join(path, "model.safetensors") if os.path.isdir(path) else path
out = {}
with safe_open(p, framework="pt") as f:
for k in f.keys():
if k.startswith(SKIP):
continue
out[k] = f.get_tensor(k)
return out
|