当前位置:   article > 正文

加载 safetensors 格式模型_torch 加载safetensors

torch 加载safetensors
# coding:utf-8
# @Email: wangguisen@donews.com
# @Time: 2023/3/22 17:39
# @File: ddd.py

'''
https://github.com/huggingface/safetensors
https://huggingface.co/docs/safetensors/index

pip install safetensors
torch >= 2.0
'''
import torch
from safetensors.torch import load_file, save_file
from safetensors import safe_open

model_path = 'nutriasOtters_10.safetensors'

tensors = {}
with safe_open(model_path, framework="pt", device='cpu') as f:
    for k in f.keys():
        tensors[k] = f.get_tensor(k)

print(tensors)

# model.load_state_dict
  • 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
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小丑西瓜9/article/detail/121543?site
推荐阅读
相关标签
  

闽ICP备14008679号