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

相关推荐
云和数据.ChenGuang4 分钟前
Golang AI 工程师路线图:从入门到实战
开发语言·人工智能·后端·golang
zyseo87 分钟前
谷歌SEO 内链地图脚本:Python 画出权重分发,揪出孤岛页
java·前端·python
破无差9 分钟前
精武会徽turtle实现
python
2601_9567436811 分钟前
上海GEO营销公司技术评估解析|以盾码无界公开产品路线为观察对象,梳理问题池构建、知识库事实锚定、内容审核与跨模型监测流程,明确现场演示和任务追溯的核验要求
大数据·人工智能·产品运营·技术分享·geo·上海
梦仔生信进阶12 分钟前
【机器学习】ACC = 1 是否意味着过拟合?还是数据泄露?一个好的模型应该是什么样的
人工智能·深度学习·机器学习
救救孩子把14 分钟前
AI面试八股文-12_11-多模态大模型面试题
人工智能·面试·职场和发展·多模态·clip·rag·llave
zxz520zmg18 分钟前
地质学笔记
人工智能·深度学习·机器学习
0春华秋实21 分钟前
团队落地 RAGAS 的五阶段路线图(13/13)
人工智能·aigc·开源软件
QinHsiu26 分钟前
5种方案、3个工程问题、1个务实路线图:AI Agent上下文管理的“战国时代”
人工智能
y = xⁿ27 分钟前
拆解cloud code记忆系统
java·人工智能·python·github