qLoRA的双量化Double Quantization-原创详解

一背景介绍

继LoRA之后,qLoRA继续大火,进一步降低了对显存的要求,简直是平民福利。但是目前网上的很多资料对其中双量化部分的讲解并不清楚,很多只是对原文的翻译,不易于理解。经过个人分析和验证,特发此文详解与大家分享。

二相关链接

paper地址:https://arxiv.org/pdf/2305.14314.pdf

code地址:GitHub - artidoro/qlora: QLoRA: Efficient Finetuning of Quantized LLMs

三双量化部分的原文

Double Quantization
We introduce Double Quantization (DQ), the process of quantizing the
quantization constants for additional memory savings. While a small blocksize is required for precise 4-bit quantization [ 13 ], it also has a considerable memory overhead. For example, using 32-bit constants and a blocksize of 64 for W , quantization constants add 32/64 = 0.5 bits per parameter on average. Double Quantization helps reduce the memory footprint of quantization constants.
More specifically, Double Quantization treats quantization constants c^{fp32}_2 of the first quantization as inputs to a second quantization. This second step yields the quantized quantization constants c_{2}^{fp8} and the second level of quantization constants c_{1}^{fp32}. We use 8-bit Floats with a blocksize of 256 for the second quantization as no performance degradation is observed for 8-bit quantization, in line with results from Dettmers and Zettl emoyer [13]. Since the c^{fp32}_2are positive, we subtract the mean from c2 before quantization to center the values around zero and make use of symmetric quantization. On average, for a blocksize of 64, this quantization reduces the memory footprint per parameter from 32 / 64 = 0 . 5 bits, to 8/64+32/(64·256)=0.127 bits, a reduction of 0.373 bits per parameter.

四解读

首先,列出关键词的解释

Quantization量化
bit比特,8比特为1字节
c^{fp32}_2第一次量化中,为了能反量化保存的32为浮点数
c^{fp8}_2第二次量化中,量化后的8位浮点数
c^{fp32}_1第二次量化中,为了能反量化保存的32为浮点数
根据前文提出的量化方法,假设权重近似服从均值为0的正态分布,因此可以用其标准差表示其分布。所以,将一个权重张量进行量化后,不仅需要将保存量化后的张量,还需要额外一个32位的浮点数以表示其标准差(即 c^{fp32}_2,其占用32个比特的空间。因此,如果只做第一次量化,则需要额外存储的空间(除了存储量化张量以外)为32个比特,假如张量的大小(blocksize,即张量各个维度的乘积)为64,则其实就是对64个数字进行量化,那 额外需要的32比特平均到每个数字上,就是32/64=0.5比特
作者为了把这个额外空间进一步降低,将 c^{fp32}_2进行进一步的量化。假如我们用64*256个数字需要量化,那就将其分为256个block,每64个数字划分到一个block中,对64个block中进行量化会产生256个c^{fp32}_2。为了降低额外空间,需要对这256个c^{fp32}_2进行第二次量化。具体做法是将其量化到8比特的浮点数格式(c_FP8_2),并且再用一个FP32表示这256个c^{fp32}_2的标准差,即为c_{1}^{fp32}。所以,对64*256个数字进行量化所需要的额外空间为(8*256+32)/(64*256)=8/64+32/(64*256)=0.127比特,量化每个数字所需要的额外空间从0.5减少到0.127,所以减少了0.373注意不是每个权重值量化所需要的空间,而是所需要的额外空间。
  • 5
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值