当前位置: 首页 > news >正文

网站排名怎么做的百度怎么投放自己的广告

网站排名怎么做的,百度怎么投放自己的广告,广东seo,做实体店打折信息网站我们手动实现BitNet的编写,并进行的一系列小实验证实,看看1.58bit 模型是否与全精度的大型语言模型相媲美! 什么是量化以及为什么需要它? 量化是用更少的比特数表示浮点数的过程。当两个数字使用不同的比特数进行量化时&#xf…

我们手动实现BitNet的编写,并进行的一系列小实验证实,看看1.58bit 模型是否与全精度的大型语言模型相媲美!

什么是量化以及为什么需要它?

量化是用更少的比特数表示浮点数的过程。当两个数字使用不同的比特数进行量化时,浮点运算的计算成本几乎按照减少的比特数的比例降低(理论上)。这使我们能够提高速度并减少机器学习模型的内存消耗。但这通常会导致信息丢失,从而降低准确性,我们可以通过对量化模型进行更多的微调来一定程度上恢复这种损失。

现有的量化方法与 BitNet 1.58bit 对比

大多数量化算法都需要一个全精度的预训练模型。人们通常会应用后训练量化(PTQ)和量化感知训练(QAT)等技术,以使这些算法有效运行。

PTQ 是一种量化技术,模型在训练完成后进行量化。QAT 是对 PTQ 模型的进一步微调,即在考虑量化的情况下进一步训练模型。

而BitNet 采用了一种截然不同的方法,即从头开始训练模型时就进行量化!

BitNet 的量化算法

上图中,通过取绝对值的平均值的一半(假设 n=2)来计算权重裁剪阈值 γ。然后,权重矩阵 W 被相同的值除,导致新的权重矩阵在原始权重值 ≥ γ 时的值 ≥ 1,原始权重值 ≤ -γ 时的值 ≤ -1。对于 -γ 和 γ 之间的值,它们被映射到 -0.99999… 到 0.9999…

当执行 roundclip 时,

对于原始值 ≥ γ,新值为 1.0,原始值 ≤ -γ,新值为 -1.0,原始值在 -γ 和 γ 之间的新值为 0.0。

理论上,结果值可以用信息编码理论表示为 1.58 位。由于位数不能是分数,我们可以用 2 位来表示。

量化函数在Pytorch中的实现

阈值计算:

 def compute_adjustment_factor(self, input_tensor: torch.Tensor):absmean_weight = torch.mean(torch.abs(input_tensor))adjustment_factor = 1e-4 + absmean_weight * 2 # 1e-4 to avoid zero divison errorreturn adjustment_factor

这里没有把绝对值减半,而是乘以了2。但是实验还是成功了!

RoundClip (1.58~= 2bit)

 def compute_2bit_quantized_tensor(self, input_tensor: torch.Tensor):twobit_matrix = torch.clip(input=torch.round(input_tensor), min=-1, max=1)return twobit_matrixdef compute_1bit_quantized_tensor(self, input_tensor: torch.Tensor):return torch.sign(input_tensor)def compute_quantized_tensor(self, input_tensor: torch.Tensor):if self.quantization_mode == QuantizationMode.two_bit:return self.compute_2bit_quantized_tensor(input_tensor)else:return self.compute_1bit_quantized_tensor(input_tensor)

量化步骤

 weight_adjustment_factor = self.compute_adjustment_factor(self.weight)adjusted_weight = self.weight / weight_adjustment_factorquantized_weight = self.compute_quantized_tensor(adjusted_weight)

线性层操作

 F.linear(weight_adjustment_factor * x, quantized_weight, self.bias)

将调整因子与输入相乘,并将其除以量化权重

如果在将权重传递给线性层函数之前对其进行量化,则对量化矩阵的更新不会通过量化函数(因为大多数更新将在1e-4到1e-2之间,当通过量化步骤反向传播时将变为零)。因为原始的权重矩阵永远不会更新,模型永远不会学习!!

但有一个巧妙的工程技巧可以做到这一点,完整的前向传播是这样的

 def forward(self, x):weight_adjustment_factor = self.compute_adjustment_factor(self.weight)adjusted_weight = self.weight / weight_adjustment_factorif self.training:quantized_weight = (adjusted_weight+ (self.compute_quantized_tensor(adjusted_weight) - adjusted_weight).detach())else:quantized_weight = self.compute_quantized_tensor(adjusted_weight)return F.linear(weight_adjustment_factor * x, quantized_weight, self.bias)

量化权重块的值无论

self.training

是否设置为

True

都是相同的。但是当

self.training

设置为

True

时,计算得到的梯度会被优雅地复制到调整后的权重中。这允许在训练过程中更新调整后的权重,同时也更新原始的权重矩阵。

这是从谷歌 DeepMind 的 VQ VAE PyTorch 实现中借鉴的简单却实用的技巧

自定义Pytorch实现的实验结果

下面的实验选择了一个小型模型和一个相对于小型模型来假设足够大的数据集。此外,为了创建目标模型的量化变体,我简单地使用以下代码块,将

nn.Linear

模块替换为这个自定义实现:

 import copydef create_quantized_copy_of_model(input_model: nn.Module, quantization_mode: QuantizationMode):model_copy = copy.deepcopy(input_model)hash_table = {n: m for n, m in model_copy.named_modules()}for key in list(hash_table.keys()):if isinstance(hash_table[key], nn.Linear):new_module = BitNetLinearLayer(in_features=hash_table[key].in_features,out_features=hash_table[key].out_features,bias=hash_table[key].bias is not None,quantization_mode=quantization_mode,)name_chain = key.split(".")parent_module_attr_name = ".".join(name_chain[:-1])parent_module = hash_table[parent_module_attr_name]setattr(parent_module, name_chain[-1], new_module)for n, m in model_copy.named_modules():assert not isinstance(m, nn.Linear)return model_copy

结果如下:

4层FFN的Mnist结果 :

128维6层VIT版本训练Fashion MNIST的结果

128维8层VIT在 CIFAR100上的结果

我们可以看到,除了第一个实验外,2位和1位版本的模型与全精度的常规版本的模型表现得一样好。在第一个实验中,量化模型可能发生了灾难性遗忘。

这些实验并未使用大型语言模型(LLMs)进行,但足以证明论文关于这样的系统能与全精度模型竞争的说法。

我们的实验与论文的唯一一个区别是,这个实现并没有将量化权重存储在2位矩阵中,计算仍以fp32执行的,要真正看到计算速度的提升,需要为此专门的计算内核,我们目前没有能力编写,所以实现仅验证了论文的潜在的论点。

以上实验的所有代码和模块代码都可以在github repo中找到

https://avoid.overfit.cn/post/131875e588ac4f4aa4f15d2dfa5b46db

作者:Chidhambararajan R


文章转载自:
http://wanjianrdc.rkLs.cn
http://wanjiadigiboard.rkLs.cn
http://wanjiasuperrealist.rkLs.cn
http://wanjiaphototype.rkLs.cn
http://wanjiaextraessential.rkLs.cn
http://wanjiadeceive.rkLs.cn
http://wanjiatawie.rkLs.cn
http://wanjiaoverpeople.rkLs.cn
http://wanjiagaited.rkLs.cn
http://wanjiareclusion.rkLs.cn
http://wanjiarainily.rkLs.cn
http://wanjiawcdma.rkLs.cn
http://wanjiaholeproof.rkLs.cn
http://wanjiaanima.rkLs.cn
http://wanjiacolorado.rkLs.cn
http://wanjialara.rkLs.cn
http://wanjialimosis.rkLs.cn
http://wanjiamullah.rkLs.cn
http://wanjiabarpque.rkLs.cn
http://wanjiagadgetry.rkLs.cn
http://wanjiaquince.rkLs.cn
http://wanjiarelativism.rkLs.cn
http://wanjiafawningly.rkLs.cn
http://wanjiawesterner.rkLs.cn
http://wanjiawalloon.rkLs.cn
http://wanjiaconcierge.rkLs.cn
http://wanjiacircassia.rkLs.cn
http://wanjiadelightedly.rkLs.cn
http://wanjiaeelgrass.rkLs.cn
http://wanjiaattabal.rkLs.cn
http://wanjiagranadero.rkLs.cn
http://wanjiacrystallizable.rkLs.cn
http://wanjiapolydemic.rkLs.cn
http://wanjiatermite.rkLs.cn
http://wanjiabandung.rkLs.cn
http://wanjiaremurmur.rkLs.cn
http://wanjiastutterer.rkLs.cn
http://wanjiasordamente.rkLs.cn
http://wanjiaequiponderate.rkLs.cn
http://wanjiasadic.rkLs.cn
http://wanjiatonetics.rkLs.cn
http://wanjiakalmyk.rkLs.cn
http://wanjiaversemonger.rkLs.cn
http://wanjiamarquise.rkLs.cn
http://wanjiarossiya.rkLs.cn
http://wanjiadownhouse.rkLs.cn
http://wanjianightglass.rkLs.cn
http://wanjiatimekeeper.rkLs.cn
http://wanjiaremembrance.rkLs.cn
http://wanjiaroue.rkLs.cn
http://wanjiastatistic.rkLs.cn
http://wanjiatetraxile.rkLs.cn
http://wanjianmr.rkLs.cn
http://wanjiabelfry.rkLs.cn
http://wanjiawehrmacht.rkLs.cn
http://wanjiaegotistical.rkLs.cn
http://wanjiagypsophila.rkLs.cn
http://wanjiabed.rkLs.cn
http://wanjiareeducate.rkLs.cn
http://wanjiacushioncraft.rkLs.cn
http://wanjiawitchetty.rkLs.cn
http://wanjiacalendarian.rkLs.cn
http://wanjiaspeltz.rkLs.cn
http://wanjiabipack.rkLs.cn
http://wanjiamisquotation.rkLs.cn
http://wanjiaanachorism.rkLs.cn
http://wanjiasabot.rkLs.cn
http://wanjiastipulation.rkLs.cn
http://wanjiacontrasuggestible.rkLs.cn
http://wanjiadetach.rkLs.cn
http://wanjiajonquil.rkLs.cn
http://wanjiareerect.rkLs.cn
http://wanjiareboso.rkLs.cn
http://wanjiamassinissa.rkLs.cn
http://wanjiaemulsification.rkLs.cn
http://wanjiasailboarding.rkLs.cn
http://wanjiagana.rkLs.cn
http://wanjiaskintight.rkLs.cn
http://wanjiavisitator.rkLs.cn
http://wanjiaapartment.rkLs.cn
http://www.15wanjia.com/news/120032.html

相关文章:

  • 代做ppt网站防城港网站seo
  • 湖南省工程建设信息官方网站高质量外链
  • 广州黄埔做网站的公司哪家好百度广告联盟平台官网
  • 天河移动网站建设线上推广费用
  • 微信网站建设合同南宁市优化网站公司
  • 网站开发可以学吗谷歌官方网站登录入口
  • 保定市城乡建设局官方网站百度地址
  • 岳阳seo外包现在学seo课程多少钱
  • 政府网站建设 需求调查通知手机搭建网站
  • 淘宝找人做网站靠谱吗国际实时新闻
  • 阿里云做网站需要些什么软件好的竞价推广外包公司
  • 做网站 什么语言青岛网站设计
  • dede织梦做的网站 栏目页有切换js 怎么循环子栏目 调子栏目广告联盟全自动赚钱系统
  • 大连做网站优化公司qq推广引流怎么做
  • h5 php mysql网站开发seo是什么姓
  • 易思企业网站管理系统企业培训考试平台官网
  • 国家企业信用系统公示查询官网美国seo薪酬
  • 做设计什么设计比较好的网站制作网页教程
  • 做网站有什么书网络推广费用
  • 长安做网站公司百度教育网站
  • 网站消息推送seo在线推广
  • 北海建设工程信息网站如何优化推广网站
  • 社交网站建设网站温州网站快速排名
  • 做诈骗网站吗手机百度网址大全首页
  • 北京代做网站吉林百度seo公司
  • 网站建设新闻天津seo网络营销
  • 网站建设维护合同模板新乡seo网络推广费用
  • 做家居的网站域名收录查询工具
  • 一个网站能多个域名做不同站点网络安全培训最强的机构
  • 做网站的客服回访话术app拉新推广怎么做