llama大模型部署

看模型加载的参数设置.

复制代码
import torch

# 初始化Half Tensor
h = torch.tensor([1.0,2.0,3.0], dtype=torch.half)
# h = torch.tensor([1.0,2.0,3.0], dtype=torch.float16) # 跟上面一行一样.

# 查看数据类型
print(h.dtype)
import accelerate
import bitsandbytes
from transformers import AutoTokenizer, AutoModelForCausalLM,TextIteratorStreamer
from transformers import AlbertTokenizer, AlbertModel
model = AlbertModel.from_pretrained('./albert',device_map='auto',torch_dtype=torch.float16,load_in_8bit=True,low_cpu_mem_usage=True)
# torch_dtype 模型本身的类型, 不写的话就自己根据权重文件查询出来.这个是权重文件本身决定的,一般在config.json里面
# load_in_8bit 会把模型转化为8bit类型.这个可以自己设置.

print(1)
  • low_cpu_mem_usage algorithm:

    复制代码
    This is an experimental function that loads the model using ~1x model size CPU memory
    
      Here is how it works:
    
      1. save which state_dict keys we have
      2. drop state_dict before the model is created, since the latter takes 1x model size CPU memory
      3. after the model has been instantiated switch to the meta device all params/buffers that
      are going to be replaced from the loaded state_dict
      4. load state_dict 2nd time
      5. replace the params/buffers from the state_dict
    
      Currently, it can't handle deepspeed ZeRO stage 3 and ignores loading errors

这个算法low_cpu_mem 如果设置True

那么他会进行.

把权重字典的keys保存下来.

然后把state_dict删除.

初始化模型.把需要加载的参数位置放到meta device里面.

再加载state_dict

可以节省cpu内存. 小内存时候需要打开.

相关推荐
红姐跨境书2 分钟前
亚马逊广告接入 ChatGPT 后,卖家该如何布局 AI 电商营销?
人工智能·chatgpt
田里的水稻3 分钟前
IL_策略训练---Mamba\SSM神经网络种类六
人工智能·深度学习·神经网络·机器学习
天天代码码天天4 分钟前
把老动画带给新一代孩子:用 C# WinForms、APISR 和 Vulkan 做一个视频超分工具
人工智能
空堂与归5 分钟前
清华VPP2登顶RoboDojo:凭预测解耦突围GPT-6
人工智能·gpt·ai·具身智能
AliCloudROS5 分钟前
MiniMax-H3 视频生成模型 — 一键部署与使用指南
人工智能·音视频
vx_Biye_Design5 分钟前
springboot旅游管理系统18006-计算机课程设计、毕业设计
java·spring boot·后端·python·elasticsearch·django·课程设计
云端设计台8 分钟前
技术方案评审画图难?AI文本可视化工具实测
人工智能
见闻小天地12 分钟前
数据中心柴发出口保护怎么选?Emax 与 Tmax XT 的定位与分工
大数据·运维·人工智能·业界资讯
半亩码田13 分钟前
C#转Python第4.7篇:logging:Python 的标准日志库
开发语言·python·c#
IT_陈寒14 分钟前
为什么我的React组件一直在意外重渲染?
前端·人工智能·后端