PaddleOCR-VL / code /tt_paddleocr /tt /weights.py
changh95's picture
tt-model push paddleocr-vl (container)
22e0325 verified
Raw History Blame Contribute Delete
750 Bytes
# 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