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

相关推荐
IvorySQL5 分钟前
深度拆解 IvorySQL 去 O 核心解决方案
数据库·人工智能·postgresql
般若-波罗蜜20 分钟前
MinerU高级用法,避坑指南(持续更新)
人工智能·python·语言模型·自然语言处理
安卓修改大师22 分钟前
安卓修改大师 vs MT管理器:反编译工具终极对决与全景解析
android·人工智能·机器翻译
A153625522 分钟前
国内好用的WMS仓储管理系统有哪些?万里牛WMS深度评测
大数据·数据库·人工智能
杀生丸学AI31 分钟前
【三维重建】ArtiFixer:自回归扩散增强与扩展3DGS(NVIDIA)
人工智能·3d·数据挖掘·aigc·三维重建·扩散模型·视觉大模型
用户8356290780511 小时前
使用 Python 对 PDF 文档进行数字签名的方法
后端·python
爱勇宝1 小时前
DeepSeek实习生日薪5500:真正恐怖的不是工资
人工智能·深度学习·面试
Feisy1 小时前
出口锂电池-无人机等危险品的拍摄多张外包装申报照片的落地方案
深度学习·手机自动拍照·照片采集·电池外观拍摄·出口电池
ShareCreators1 小时前
在华企业如何填补AI人才缺口数据基建:Share Creators 如何以 AI 驱动的数字资产管理重塑工业研发效能从人
人工智能·汽车·blueberry
中微极客1 小时前
LangChain vs LlamaIndex:RAG框架选型深度对比
人工智能·langchain