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内存. 小内存时候需要打开.

相关推荐
7yewh38 分钟前
SLAM 三维空间刚体运动(2)
数据结构·人工智能·机器人·嵌入式·slam
小虎AI生活1 小时前
WorkBuddy 模型选型实操:0.03 倍的 Space-Bunny 怎么用、派什么活、避什么坑
人工智能·超级个体·一人公司·青玥ai
ai小陈1 小时前
GPU服务器租用存储验收:检查点写入与磁盘吞吐实战
运维·服务器·人工智能·ai·ssh·gpu算力
微三云马玮均—GEO源码系统 私有化部署1 小时前
消费返物业费:消费+服务趋势的必然产物!
大数据·人工智能·物联网·区块链·生活
明月_清风1 小时前
Muse 登顶 App Store 第一,SDK 直接开源:AI Agent 开始进入下一个阶段
人工智能·后端
言乐61 小时前
HTML视频审核模型
python·django·virtualenv·pygame·tornado
JackSparrow4142 小时前
和AI一起将全部CSDN博文迁移到个人博客站
人工智能·程序人生·ai·github·cloudflare·astro·静态博客
55873 生态系统2 小时前
第 22 篇|社区聊天|55873 文明共建者的日常交流与协作界面
人工智能·区块链·55873全域文明生态体系·55873操作系统·55873社区聊天
搬砖的小码农_Sky2 小时前
AI Agent:如何处理Claude Code 最近版本(2026年更新)引入的模型上下文限制
人工智能·windows·ai·ai编程