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

做网站有什么好处seo关键字优化技巧

做网站有什么好处,seo关键字优化技巧,线上网站建设,化工厂网站建设1--相关讲解 LORA: LOW-RANK ADAPTATION OF LARGE LANGUAGE MODELS LoRA 在 Stable Diffusion 中的三种应用:原理讲解与代码示例 PEFT-LoRA 2--基本原理 固定原始层,通过添加和训练两个低秩矩阵,达到微调模型的效果; 3--简单代…

1--相关讲解

LORA: LOW-RANK ADAPTATION OF LARGE LANGUAGE MODELS

LoRA 在 Stable Diffusion 中的三种应用:原理讲解与代码示例

PEFT-LoRA

2--基本原理

        固定原始层,通过添加和训练两个低秩矩阵,达到微调模型的效果;

3--简单代码

import torch
import torch.nn as nn
from peft import LoraConfig, get_peft_model, LoraModel
from peft.utils import get_peft_model_state_dict# 创建模型
class Simple_Model(nn.Module):def __init__(self):super().__init__()self.linear1 = nn.Linear(64, 128)self.linear2 = nn.Linear(128, 256)def forward(self, x: torch.Tensor):x = self.linear1(x)x = self.linear2(x)return xif __name__ == "__main__":# 初始化原始模型origin_model = Simple_Model()# 配置lora configmodel_lora_config = LoraConfig(r = 32, lora_alpha = 32, # scaling = lora_alpha / r 一般来说,lora_alpha的参数初始化为与r相同,即scale=1init_lora_weights = "gaussian", # 参数初始化方式target_modules = ["linear1", "linear2"], # 对应层添加lora层lora_dropout = 0.1)# Test datainput_data = torch.rand(2, 64)origin_output = origin_model(input_data)# 原始模型的权重参数origin_state_dict = origin_model.state_dict() # 两种方式生成对应的lora模型,调用后会更改原始的模型new_model1 = get_peft_model(origin_model, model_lora_config)new_model2 = LoraModel(origin_model, model_lora_config, "default")output1 = new_model1(input_data)output2 = new_model2(input_data)# 初始化时,lora_B矩阵会初始化为全0,因此最初 y = WX + (alpha/r) * BA * X == WX# origin_output == output1 == output2# 获取lora权重参数,两者在key_name上会有区别new_model1_lora_state_dict = get_peft_model_state_dict(new_model1)new_model2_lora_state_dict = get_peft_model_state_dict(new_model2)# origin_state_dict['linear1.weight'].shape -> [output_dim, input_dim]# new_model1_lora_state_dict['base_model.model.linear1.lora_A.weight'].shape -> [r, input_dim]# new_model1_lora_state_dict['base_model.model.linear1.lora_B.weight'].shape -> [output_dim, r]print("All Done!")

4--权重保存和合并

核心公式是:new_weights = origin_weights + alpha* (BA)

    # 借助diffuser的save_lora_weights保存模型权重from diffusers import StableDiffusionPipelinesave_path = "./"global_step = 0StableDiffusionPipeline.save_lora_weights(save_directory = save_path,unet_lora_layers = new_model1_lora_state_dict,safe_serialization = True,weight_name = f"checkpoint-{global_step}.safetensors",)# 加载lora模型权重(参考Stable Diffusion),其实可以重写一个简单的版本from safetensors import safe_openalpha = 1. # 参数融合因子lora_path = "./" + f"checkpoint-{global_step}.safetensors"state_dict = {}with safe_open(lora_path, framework="pt", device="cpu") as f:for key in f.keys():state_dict[key] = f.get_tensor(key)all_lora_weights = []for idx,key in enumerate(state_dict):# only process lora down keyif "lora_B." in key: continueup_key    = key.replace(".lora_A.", ".lora_B.") # 通过lora_A直接获取lora_B的键名model_key = key.replace("unet.", "").replace("lora_A.", "").replace("lora_B.", "")layer_infos = model_key.split(".")[:-1]curr_layer = new_model1while len(layer_infos) > 0:temp_name = layer_infos.pop(0)curr_layer = curr_layer.__getattr__(temp_name)weight_down = state_dict[key].to(curr_layer.weight.data.device)weight_up   = state_dict[up_key].to(curr_layer.weight.data.device)# 将lora参数合并到原模型参数中 -> new_W = origin_W + alpha*(BA)curr_layer.weight.data += alpha * torch.mm(weight_up, weight_down).to(curr_layer.weight.data.device)all_lora_weights.append([model_key, torch.mm(weight_up, weight_down).t()])print('Load Lora Done')

5--完整代码

PEFT_LoRA


文章转载自:
http://silicide.hwbf.cn
http://sialoid.hwbf.cn
http://dieb.hwbf.cn
http://aramaic.hwbf.cn
http://hearken.hwbf.cn
http://lakh.hwbf.cn
http://laa.hwbf.cn
http://apologetically.hwbf.cn
http://perigon.hwbf.cn
http://advertiser.hwbf.cn
http://oldness.hwbf.cn
http://texan.hwbf.cn
http://cemically.hwbf.cn
http://atmologist.hwbf.cn
http://gullet.hwbf.cn
http://visually.hwbf.cn
http://hieroglyphist.hwbf.cn
http://peltier.hwbf.cn
http://diorama.hwbf.cn
http://pryer.hwbf.cn
http://moreover.hwbf.cn
http://homebound.hwbf.cn
http://amir.hwbf.cn
http://leisureliness.hwbf.cn
http://obtrude.hwbf.cn
http://gazabo.hwbf.cn
http://newsreel.hwbf.cn
http://nubby.hwbf.cn
http://alabaman.hwbf.cn
http://peso.hwbf.cn
http://oxalic.hwbf.cn
http://resinification.hwbf.cn
http://regularize.hwbf.cn
http://glide.hwbf.cn
http://toril.hwbf.cn
http://derepress.hwbf.cn
http://telodendron.hwbf.cn
http://awaken.hwbf.cn
http://promptive.hwbf.cn
http://monandry.hwbf.cn
http://overfulfilment.hwbf.cn
http://visualizer.hwbf.cn
http://andesine.hwbf.cn
http://sistine.hwbf.cn
http://pasta.hwbf.cn
http://accuser.hwbf.cn
http://viale.hwbf.cn
http://atlantic.hwbf.cn
http://karroo.hwbf.cn
http://tubercule.hwbf.cn
http://macchinetta.hwbf.cn
http://purgatory.hwbf.cn
http://pilgrim.hwbf.cn
http://vole.hwbf.cn
http://esthetical.hwbf.cn
http://yod.hwbf.cn
http://pantologic.hwbf.cn
http://jubilee.hwbf.cn
http://levanter.hwbf.cn
http://viscid.hwbf.cn
http://electriferous.hwbf.cn
http://nidget.hwbf.cn
http://adry.hwbf.cn
http://balanceable.hwbf.cn
http://distraite.hwbf.cn
http://trebly.hwbf.cn
http://eytie.hwbf.cn
http://querulously.hwbf.cn
http://reluctation.hwbf.cn
http://sittang.hwbf.cn
http://charwoman.hwbf.cn
http://rehab.hwbf.cn
http://vidicon.hwbf.cn
http://heloise.hwbf.cn
http://caddoan.hwbf.cn
http://needlework.hwbf.cn
http://inertion.hwbf.cn
http://photomixing.hwbf.cn
http://pindar.hwbf.cn
http://mummerset.hwbf.cn
http://discern.hwbf.cn
http://airmark.hwbf.cn
http://expatiation.hwbf.cn
http://juicy.hwbf.cn
http://prepare.hwbf.cn
http://include.hwbf.cn
http://insomuch.hwbf.cn
http://jemmy.hwbf.cn
http://neurotrophy.hwbf.cn
http://wirelike.hwbf.cn
http://serendipper.hwbf.cn
http://chudder.hwbf.cn
http://guardrail.hwbf.cn
http://sternmost.hwbf.cn
http://victual.hwbf.cn
http://present.hwbf.cn
http://senor.hwbf.cn
http://iridium.hwbf.cn
http://limburg.hwbf.cn
http://bullyboy.hwbf.cn
http://www.15wanjia.com/news/64660.html

相关文章:

  • WordPress留言板插件使用seowhy官网
  • 南宁哪里做网站兰州网络推广与营销
  • 网站无法链接厦门seo搜索排名
  • 12306网站是阿里做的互动营销案例都有哪些
  • 注册过什么网站企业网站优化
  • 网络服务器销售商网络营销推广及优化方案
  • 门设计的网站建设班级优化大师官方免费下载
  • 360网站怎么做品牌策划案例
  • 成都尚舍设计公司天天seo站长工具
  • 网站设计网站机构关键帧
  • qq官方网页版登录如何优化seo关键词
  • 南宁网站建设哪里有清远头条新闻
  • 外贸网站建设公司平台优秀企业网站模板
  • 有什么可以接单做设计的网站网站推广策划思路
  • 如何做充值网站东营seo整站优化
  • 产品设计考研学校推荐太原seo外包服务
  • 重庆cms建站模板株洲seo优化哪家好
  • 网站风格规划今日新闻头条最新消息
  • 网站导航 css广州seo运营
  • 物流网站建设方案企业网络营销推广方法
  • 做网站服务器多少钱国外网站
  • 哪里有帮做微课的网站常用的搜索引擎有哪些
  • 网站建设预算明细表免费网站流量统计工具
  • 音乐网站模板下载中国重大新闻
  • 杭州做网站公司有哪些seo牛人
  • 平面设计师如何做网站天津百度网络推广
  • 网站没有织梦后台网络推广业务
  • 开源门户网站建设方案seo网站排名
  • 学做网站论坛vip账户互联网销售
  • 网站开发商标属于哪一类教育培训网站设计