llama2模型部署方案的简单调研-GPU显存占用(2023年7月25日版)

具有惊人 480B 参数的开源企业级大型语言模型 Snowflake AI Research 推出了 Arctic,这是一款专为企业 AI 应用程序设计的尖端开源大型语言模型 (LLM),为成本效益和可访问性设定了新标准。该模型利用独特的 Dense-MoE 混合转换器架构来有效地处理 SQL 生成、编码和遵循指令。凭借其在较低计算预算下运行的能力,Arctic 为希望集成高级 AI 的企业提供了高性能解决方案,而无需通常涉及大量成本。 阅读详情
AI摘要

文章详细列出了全精度和不同量化级别下Llama模型对显存的需求,如28GBforfullprecisioninferenceand14GBforhalfprecision.提供了几个轻量化部署方案,包括Llama-2-70B-chat-GPTQ、GGML和exllama,这些项目支持int4或int8量化以降低内存占用,并适用于不同的硬件平台,如GPU和AppleM系列芯片。此外,还提及了一个名为text-Generation-webui的WebUI工具,用于大模型的本地推理。

先说结论

全精度llama2 7B最低显存要求:28GB
全精度llama2 13B最低显存要求:52GB
全精度llama2 70B最低显存要求:280GB

16精度llama2 7B预测最低显存要求:14GB
16精度llama2 13B预测最低显存要求:26GB
16精度llama2 70B预测最低显存要求:140GB

8精度llama2 7B预测最低显存要求:7GB
8精度llama2 13B预测最低显存要求:13GB
8精度llama2 70B预测最低显存要求:70GB

4精度llama2 7B预测最低显存要求:3.5GB
4精度llama2 13B预测最低显存要求:6.5GB
4精度llama2 70B预测最低显存要求:35GB

理论基础

引用用户nielsr的结论

in full precision (float32), every parameter of the model is stored in 32 bits or 4 bytes. Hence 4 bytes / parameter * 7 billion parameters = 28 billion bytes = 28 GB of GPU memory required, for inference only. In half precision, each parameter would be stored in 16 bits, or 2 bytes. Hence you would need 14 GB for inference. There are now also 8 bit and 4 bit algorithms, so with 4 bits (or half a byte) per parameter you would need 3.5 GB of memory for inference.
For training, it depends on the optimizer you use.
In case you use regular AdamW, then you need 8 bytes per parameter (as it not only stores the parameters, but also their gradients and second order gradients). Hence, for a 7B model you would need 8 bytes per parameter * 7 billion parameters = 56 GB of GPU memory. If you use AdaFactor, then you need 4 bytes per parameter, or 28 GB of GPU memory. With the optimizers of bitsandbytes (like 8 bit AdamW), you would need 2 bytes per parameter, or 14 GB of GPU memory.

翻译如下

在全精度(float32)下,模型的每个参数都以 32 位或 4 个字节存储。
因此,4 字节/参数 * 70 亿个参数 = 280 亿字节 = 需要 28 GB GPU 内存,仅用于推理。
在半精度下,每个参数将以 16 位或 2 个字节存储。因此需要 14 GB 来进行推理。
现在还有 8 位和 4 位算法,因此每个参数 4 位(或半个字节)时,将需要 3.5 GB 内存用于推理。
对于训练,这取决于使用的优化器。
如果使用常规 AdamW,则每个参数需要 8 个字节(因为它不仅存储参数,还存储它们的梯度和二阶梯度)。
因此,对于 7B 模型,每个参数需要 8 个字节 * 70 亿个参数 = 56 GB GPU 内存。
如果使用 AdaFactor,则每个参数需要 4 个字节,或 28 GB 的 GPU 内存。
使用位和字节优化器(如 8 位 AdamW),每个参数需要 2 个字节,或 14 GB 的 GPU 内存。

详情见HuggingFace对于单卡GPU推理的介绍:Anatomy of Model’s Memory ,

根据对exllama、Llama-2-70B-chat-GPTQ等模型量化项目用户的反馈与llama2论文的研究,发现显存计算规律符合nielsr的结论。

可选部署方案

1、Llama-2-70B-chat-GPTQ

项目连接:Llama-2-70B-chat-GPTQ
开源协议:Meta AI对于llama2的用户协议
优点:可直接部署运行,可实现上下文记忆
缺点:int4量化,精度下降,目前仅支持70B-chat模型,等待作者后续开放更多型号的轻量化版本。

此项目是对llama2-70B-chat进行了int4量化,显存占用达到了预估水准。

+---------------------------------------------------------------------------------------+
LLaMA 2 和 QianWen-14B LLaMA 2 运行时还需要足够的CPU处理能力和内存支持,例如运行LLaMA-30B模型的最低RAM要求是32 GB,但对于更大数据集或更长文本序列可能需要更多的RAM,推荐使用64 GB或128 GB。总体来说,LLaMA 2 和 QianWen 都是各自团队在自然语言处理领域的先进技术代表,两者在功能和性能方面具有竞争性,而具体的差异则更多体现在背后的研发策略、优化技术和特定应用场景的适应性上。LLaMA 2 系列模型有不同的参数量版本,如7B、13B和70B等。 阅读详情

相关推荐

Vicuna-13B本地部署实战:llama.cpp+FastAPI轻量级生产方案

大语言模型(LLM)本地化部署正成为企业AI落地的关键路径,其核心在于平衡推理性能、硬件兼容性与工程可控性。基于llama.cpp的GGUF量化技术可将13B级模型压缩至5GB以内,实现CPU端稳定推理;FastAPI与Uvicorn组合则提供高并发、自文档化的RESTful接口能力。该方案规避了PyTorch显存瓶颈、Ollama黑盒封装及Flask GIL限制,特别适合知识库问答、智能客服、技术文档摘要等中低延迟业务场景。本文聚焦Vicuna-13B在消费级设备(如M1 Mac)上的端到端部署,涵盖4-

weixin_34050519的博客 394

Vicuna开源对话模型:基于Llama-13B的轻量高效微调实践

对话模型是大语言模型落地应用的核心形态,其技术本质是通过指令微调(SFT)实现人类意图与模型响应的对齐。Vicuna作为开源社区标杆,以Llama-13B为底座,验证了小数据(7万条高质量ShareGPT对话)、单阶段监督微调、QLoRA低秩适配等轻量化路径的有效性。它不依赖强化学习(RLHF)或海量语料,而是聚焦信息密度筛选、上下文感知格式构造与可复现训练配置,在消费级硬件(如双卡3090)上达成逼近ChatGPT-3.5的综合表现。该范式显著降低了开源对话模型的研发门槛与部署成本,适用于企业知识问答、垂

weixin_30431923的博客 273

双卡3090消费级显卡推理微调OpenBuddy-LLaMA2-70B最佳实践

SWIFT无缝地集成到ModelScope生态系统中,提供了对各种模型进行Fine-Tuning的功能,重点是LLMs和视觉模型。模型链接:https://modelscope.cn/models/OpenBuddy/openbuddy-llama2-70b-v10.1-bf16。它集成了各种高效的Fine-Tuning方法的实现,采用参数高效、内存高效和时间高效的方法。对openbuddy-llama2-70b的微调,使用魔搭ModelScope社区的微调框架swift。语义深度理解、认知能力。

具身机器人和通用AI 1549

Android逆向分析

Android 逆向开发是指对已发布的 Android 应用进行分析和破解,以了解应用程序的内部工作原理,获取应用程序的敏感信息,或者修改应用程序的行为。Android应用 Java编写的,利用Android SDK编译代码,并并且把所有的数据和资源文件打包成一个APK(Android Package)文件这是一个后缀名为.apk的压缩文件,apk文件中包含了一个Anddroid应用程序的所有内容,是Android平台用于安装应用程序的文件。

qq_51598534的博客 6305

Unreal 5 MetaHuman插件全流程:从安装到角色动画生成

本文详细介绍了Unreal 5中MetaHuman插件的全流程使用指南,从安装配置到角色动画生成。通过Quixel Bridge下载预设角色,利用面部捕捉技术赋予数字人模型生命力,并提供材质编辑、性能优化等进阶技巧,帮助用户快速创建照片级真实的虚拟角色。

weixin_29009081的博客 839

从摄像头选型到PCB布线:搞懂MIPI CSI带宽计算,避免你的嵌入式项目翻车

本文详细解析了MIPI CSI带宽计算在嵌入式项目中的关键作用,从摄像头选型到PCB布线提供全流程指导。通过实际案例和计算公式,帮助工程师准确计算带宽需求,避免图像丢帧和系统崩溃问题,同时优化PCB设计确保信号完整性。

weixin_30533109的博客 383

Adams Car——Adams car与Simulink联合仿真

Adams与simulink悬架联合仿真

Mr.邹的博客 2131

qcc514x-qcc304x调试笔记

qcc514x-qcc304x调试笔记-1-QCC514x系列 qcc514x-qcc304x调试笔记-2-开发环境搭建 qcc514x-qcc304x调试笔记-3-如何修改蓝牙名称 qcc514x-qcc304x调试笔记-4-如何修改蓝牙地址 qcc514x-qcc304x调试笔记-5-如何区分左右耳 qcc514x-qcc304x调试笔记-6-PIO相关操作 ...

leezs的博客 1247

2023华为od机试C卷【推荐多样性】Java&Go 实现

推荐多样性需要从多个列表中选择元素,一次性要返回N屏数据(窗口数量),每屏展示K个元素(窗口大小),选择策略1.各个列表元素需要做穿插处理,即先从第一个列表中为每屏选择一元素,再从第二个列表中为每屏选择一个元素,依次类推2.每个列表的元素尽量均分为N份,如果不够N个,也要全部分配完,

MISAYAONE的博客 2189

西南科技大学数字电子技术实验七(4行串行累加器设计及FPGA实现)FPGA部分

/在k=1时输入1,并在k=0时运算。//在k=1时输入0,并在k=0时运算。//在k=1时输入1,并在k=0时运算。//在k=1时输入0,并在k=0时运算。//在k=1时输入1,并在k=0时运算。//在k=1时输入1,并在k=0时运算。//在k=1时输入0,并在k=0时运算。//在k=1时输入0,并在k=0时运算。三、程序清单(每条语句必须包括注释或在开发窗口注释后截图)四、综合、管脚分配、生成输出文件、下载(所有步骤截图)五、仿真程序清单、波形(波形截图必做,截图!.k(k),//开关。

Welcome To My6n Blog 4339

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

Outlook Express 6 (OE6) for Win7/Win8/Win10

英文版 Outlook Express6.0, 兼容Win7/Win10/WinXP,解压就可用。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain&#39;s apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath(&#39;DeepLearnToolbox&#39;));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand(&#39;state&#39;,0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = &#39;sigm&#39;;%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, &#39;Too big error&#39;);```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, &#39;Too big error&#39;);```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

上一篇: 【Python+图片切割+图片合并】基于Python的图片批量切割与合并(保持原像素不变,不会出现像素大小不匹配、填充黑边的问题)
下一篇: 基于Python easyOCR的图片文字识别并在原图上框出识别位置
海皇海皇吹
博客等级 码龄8年 13粉丝 9原创
评论 9
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址