当前位置: 首页 > news >正文

海淀区企业网站建设网络整合营销

海淀区企业网站建设,网络整合营销,你自己做的网站怎么发布到网上,龙岗区政府在线住房建设局网站Hugging Face, EleutherAI, StabilityAI 用的多 介绍 文件形式 header,体现其特性。如果强行将pickle或者空软连接 打开,会出现报错。解决详见:debug 连接到其他教程结构和参数 安装 with pip:Copied pip install safetensors with con…

Hugging Face, EleutherAI, StabilityAI 用的多

介绍

文件形式

  • header,体现其特性。如果强行将pickle或者空软连接 打开,会出现报错。解决详见:debug 连接到其他教程
  • 结构和参数
    数据结构

安装

with pip:Copied
pip install safetensors
with conda:Copied
conda install -c huggingface safetensors

Usage

文档: https://huggingface.co/docs/safetensors/index
github: https://github.com/huggingface/safetensors

测试安装

import torch
from safetensors import safe_open
from safetensors.torch import save_filetensors = {"weight1": torch.zeros((1024, 1024)),"weight2": torch.zeros((1024, 1024))
}
save_file(tensors, "model.safetensors")tensors = {}
with safe_open("model.safetensors", framework="pt", device="cpu") as f:for key in f.keys():tensors[key] = f.get_tensor(key)

加载

文档 https://huggingface.co/docs/diffusers/using-diffusers/using_safetensors

from diffusers import StableDiffusionPipelinepipeline = StableDiffusionPipeline.from_single_file("https://huggingface.co/WarriorMama777/OrangeMixs/blob/main/Models/AbyssOrangeMix/AbyssOrangeMix.safetensors"
)

Load tensors


from safetensors import safe_opentensors = {}
with safe_open("model.safetensors", framework="pt", device=0) as f:for k in f.keys():tensors[k] = f.get_tensor(k)
# Loading only part of the tensors (interesting when running on multiple GPU)from safetensors import safe_opentensors = {}
with safe_open("model.safetensors", framework="pt", device=0) as f:tensor_slice = f.get_slice("embedding")vocab_size, hidden_dim = tensor_slice.get_shape()tensor = tensor_slice[:, :hidden_dim]

保存


import torch
from safetensors.torch import save_filetensors = {"embedding": torch.zeros((2, 2)),"attention": torch.zeros((2, 3))
}
save_file(tensors, "model.safetensors")

转换到safetensor

  • 在线,利用hugging face

The easiest way to convert your model weights is to use the Convert Space, given your model weights are already stored on the Hub. The Convert Space downloads the pickled weights, converts them, and opens a Pull Request to upload the newly converted .safetensors file to your repository.

  • 本地 运行
    see 转换代码 convert.py
# 主函数
def convert_file(pt_filename: str,sf_filename: str,
):loaded = torch.load(pt_filename, map_location="cpu")if "state_dict" in loaded:loaded = loaded["state_dict"]shared = shared_pointers(loaded)for shared_weights in shared:for name in shared_weights[1:]:loaded.pop(name)# For tensors to be contiguousloaded = {k: v.contiguous() for k, v in loaded.items()}dirname = os.path.dirname(sf_filename)os.makedirs(dirname, exist_ok=True)save_file(loaded, sf_filename, metadata={"format": "pt"})check_file_size(sf_filename, pt_filename)reloaded = load_file(sf_filename)for k in loaded:pt_tensor = loaded[k]sf_tensor = reloaded[k]if not torch.equal(pt_tensor, sf_tensor):raise RuntimeError(f"The output tensors do not match for key {k}")

例子

解析

import requests # pip install requests
import structdef parse_single_file(url):# Fetch the first 8 bytes of the fileheaders = {'Range': 'bytes=0-7'}response = requests.get(url, headers=headers)# Interpret the bytes as a little-endian unsigned 64-bit integerlength_of_header = struct.unpack('<Q', response.content)[0]# Fetch length_of_header bytes starting from the 9th byteheaders = {'Range': f'bytes=8-{7 + length_of_header}'}response = requests.get(url, headers=headers)# Interpret the response as a JSON objectheader = response.json()return headerurl = "https://huggingface.co/gpt2/resolve/main/model.safetensors"
header = parse_single_file(url)print(header)
http://www.zhongyajixie.com/news/5684.html

相关文章:

  • 做网站至少多少钱品牌公关具体要做些什么
  • java哪种语言适合网站开发上海好的网络推广公司
  • 如何构建https 网站我要恢复百度
  • 当今弹幕网站建设情况在线优化seo
  • 手机网站静态模板下载站长之家下载
  • 湖北建设厅官网seo sem关键词优化
  • 福州建网站公司可口可乐网络营销策划方案
  • 试用型网站怎么做友情链接只有链接
  • 设计师网站模版邹平县seo网页优化外包
  • 网站建设属于什么服务网站优化公司哪个好
  • 拐个娇妻做晚餐在哪个网站连载呢网络广告有哪些
  • 网站怎么做后台百度关键词价格查询软件
  • 门户网站建设厂商名录品牌营销策划案例ppt
  • windows虚拟主机苏州网络推广seo服务
  • 佛山专业的网站建设公司获客
  • 徐州人才网官方网站合肥瑶海区
  • 昆山网站制作seo宣传
  • 国外有没有做问卷调查的网站百度图片识别
  • 企业管理网站系统百度联盟
  • 上海临时工400元一天武汉seo哪家好
  • 济南微信网站开发宁波seo入门教程
  • 东莞九江网站制作网站开发培训
  • 建站网址打不开营销策划公司简介
  • 网站开发是BS架构吗百度金融
  • 电子商务网站推广的界定免费网页代码大全
  • 客户端下载大地seo视频
  • 一级a做愛网站体验区seo综合查询
  • 网站建设收费价格今日足球赛事推荐
  • 内网网站模板百度收录工具
  • 江门推广平台排行榜seo全称英文怎么说