一步一步理解大模型:模型量化技术3 - GPTQ

大语言模型量化方法对比:GPTQ、GGUF、AWQ 在过去的一年里,大型语言模型(llm)有了飞速的发展,在本文中,我们将探讨几种(量化)的方式,除此以外,还会介绍分片及不同的保存和压缩策略。说明:每次加载LLM示例后,建议清除缓存,以防止出现OutOfMemory错误。如果在jupyter中无法释放显存,请重启这个jupyter notebook。 阅读详情

本文介绍专门为生成式预训练模型设计的量化技术GPTQ

GPTQ是一种一次性权重量化方法,专为生成预训练Transformer(GPT)模型设计。该方法基于近似二阶信息,旨在实现高度准确和高效。

关于GPTQ的关键点:

  1. GPTQ可以在大约四个GPU小时内量化具有1750亿参数的GPT模型,将位宽减少到每个权重的3或4位,与未压缩的基线相比,准确性降低可以忽略不计。

  2. 该方法的压缩增益是以前提出的一次性量化方法的两倍多,保持了准确性,使我们首次能够在单个GPU内执行1750亿参数的模型进行生成推断。

  3. GPTQ还表明,即使在极端量化情况下,也可以提供合理的准确性,其中权重被量化为2位甚至三元量化级别。

  4. 该方法可以用于端到端推断加速,相对于FP16,使用高端GPU(NVIDIA A100)时约为3.25倍,使用更经济实惠的GPU(NVIDIA A6000)时为4.5倍。

  5. GPTQ是首个表明可以将具有数百亿参数的极度准确的语言模型量化为每个组件3-4位的方法。之前的后训练方法只能在8位时保持准确,而之前的基于训练的技术只处理了比这小一个到两个数量级的模型。

  6. GPTQ遵循最先进的后训练量化方法的结构,通过逐层进行量化,为每一层解决相应的重建问题。

  7. 该方法基于最近提出的Optimal Brain Quantization(OBQ)方法,进行了一系列重大修改,使其能够扩展到大型语言模型,提供超过三个数量级的计算加速。

更详细的信息可以在这里查看完整的论文。

我们可以在这里找到羊驼(LLaMA)模型的GPTQ源代码:

GPTQ 和 AWQ:LLM 量化方法的比较 量化是将浮点数权重转换为低精度整数的过程,可以显著减少模型的大小和计算复杂度。GPTQ 和 AWQ 是目前最优的 LLM 量化方法之一 阅读详情

相关推荐

大模型量化技术全解析

大模型量化技术全解析,先理解线性量化的基础,再看对象/粒度/流程怎么选,最后是各种进阶招式。

酌沧 953

欺诈文本分类检测(十四):GPTQ量化模型

本文通过gptq方法分别对微调后的模型进行了8位量化和4位量化,并对比了量化前后模型的性能指标差异,8位量化模型的性能指标变化小,而4位量化模型的性能指标变异较大。

golfxiao的专栏 2367

开源模型应用落地-模型量化-AWQ vs GPTQ(三)

理解AWQ和GPTQ模型量化技术的差异

以微薄之力,予他人些许温暖. 2万+

8.3 GPTQ量化技术:4倍压缩大模型显存,精度零损失!

在讨论GPTQ之前,我们需要先理解大模型部署面临的显存困境。fill:#333;fill:black;fill:#333;53%27%13%7%模型显存占用对比FP32FP16INT8INT4传统训练后量化(Post-Training Quantization, PTQ)方法直接对权重进行线性量化,虽然能有效压缩模型,但会带来显著的精度损失。GPTQ正是为解决这一问题而生的创新性量化算法。

yonggeit的博客 3640

保姆级教程:用PyTorch从零实现SDE扩散模型(附完整代码与MNIST实战)

本文提供了一份详细的PyTorch教程,指导读者从零开始实现SDE扩散模型,并附有完整的代码示例和MNIST数据集实战。通过解释随机微分方程(SDE)的核心概念、模型架构设计、训练流程实现以及采样生成过程,帮助开发者掌握扩散模型的构建与应用。

weixin_28677005的博客 262

K-L展开 (Karhunen-Loeve expansion)

K-L变换

susan_wang1的博客 2万+

Bioinformatics2021 | FraGAT+:基于分子原始片段的多尺度图注意力机制的分子性质预测模型

Bioinformatics2021 | FraGAT:基于分子原始片段的多尺度图注意力机制的分子性质预测模型

justBeHerHero 1990

手把手教你学Simulink--基于Simulink的机械臂工业装配任务仿真建模

特点高精度要求:装配过程通常需要非常高的位置精度。多步骤操作:一个完整的装配任务可能包含多个连续的子任务,如抓取零件、移动到特定位置、装配等。动态环境:工作环境可能是动态变化的,例如其他机器人或人员在同一空间内工作。挑战复杂性管理:需要处理复杂的运动学和动力学问题,以及可能的碰撞避免。实时性:某些应用场景下需要快速响应以保证生产效率。集成度:需要与其他系统(如传感器、PLC等)无缝集成。首先明确要模拟的装配任务内容。零件的位置和尺寸。装配顺序。

MHD0815的博客 236

COMSOL介电弹性体数值仿真指南:预拉伸圆形DEA的稳态变形分析(I)

本期博客是《COMSOL介电弹性体数值仿真指南》系列博客中的一期。聚焦于介电弹性体驱动器(DEA)中最为经典的预拉伸圆形DEA驱动器构型,对其物理特性及数值仿真总体方案进行介绍与讨论。

忘了面孔的Batou 448

【异常】Cursor编辑器 “Taking longer than expected...“ 报错全链路排查与解决方案

该提示并非传统的程序崩溃或语法报错,本质是Cursor编辑器的超时预警机制——当核心任务(云端AI推理请求、本地项目索引等)的执行耗时超出系统预设阈值时,触发的用户告知类提示,核心诱因是任务执行全链路出现阻塞或性能瓶颈。以下方案按排查优先级从高到低排序,覆盖从快速急救到根因根治的全流程,可按步骤逐步验证解决。针对大仓库、多依赖项目的索引超时问题,核心是通过规则过滤无效文件,从根源降低索引负载。

奶爸的编程之路,也就一周冷个三天 3092

Python 爬虫教程:企业官网基本信息抓取

本文介绍了使用Python爬虫技术抓取企业官网信息的方法,包括公司名称、简介、联系方式、地址、产品及新闻等数据。通过Requests和BeautifulSoup库实现网页请求与解析,并利用Pandas存储数据为CSV文件。同时提供了应对反爬虫机制(如设置User-Agent、代理IP池、延迟请求等)的解决方案,帮助高效获取企业公开数据。

专注于Python爬虫开发,分享爬虫技巧、项目实战与反爬经验,使用Scrapy、BeautifulSoup等工具,解决数据抓取难题。 1856

3、结合物理学与深度学习的连续时间动力学模型

本文探讨了如何结合物理学原理与深度学习技术,构建连续时间动力学模型,以提升机器人系统对复杂动态环境的建模与控制能力。重点介绍了深度拉格朗日网络(DeLaN)和深度哈密顿神经网络(HNN)的理论基础及其在模拟与物理系统中的实验表现,并展示了其在逆向模型、前向模型以及能量控制任务上的优越性能。文章还分析了当前方法的局限性,并提出了未来研究方向,如接触处理、广义坐标学习及优化损失函数等。

linux的博客 904

深度学习工具包 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")

蓝牙模块HM-10手册

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

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

上一篇: 一步一步理解大模型:模型量化技术2-源代码
下一篇: 一步一步理解大模型:混合专家模型(MoE)简介
chattyfish
博客等级 码龄4年 32粉丝 22原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值