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

六盘水网站设计企业形象通用网站

六盘水网站设计,企业形象通用网站,mysql网站后台管理系统下载,中英文网站前端怎么做从代码角度进行Llama 架构分析 Llama 架构分析前言Llama 架构分析分词网络主干DecoderLayerAttentionMLP 下游任务因果推理文本分类 Llama 架构分析 前言 Meta 开发并公开发布了 Llama系列大型语言模型 (LLM)#xff0c;这是一组经过预训练和微调的生成文本模型#xff0c;参… 从代码角度进行Llama 架构分析 Llama 架构分析前言Llama 架构分析分词网络主干DecoderLayerAttentionMLP 下游任务因果推理文本分类 Llama 架构分析 前言 Meta 开发并公开发布了 Llama系列大型语言模型 (LLM)这是一组经过预训练和微调的生成文本模型参数规模从 70 亿到 700 亿不等。 在大多数任务中LLaMA-13B要比GPT-3(175B)的性能要好LLaMA-65B和组好的模型Chinchilla-70B以及PaLM-540B的实力相当。 Llama 架构分析 分词 分词部分主要做的是利用文本分词器对文本进行分词 tokenizer AutoTokenizer.from_pretrained(PATH_TO_CONVERTED_TOKENIZER) text Hey, are you conscious? Can you talk to me? inputs tokenizer(text, return_tensorspt)网络主干 主干网络部分主要是将分词得到的input_ids输入到embedding层中进行文本向量化得到hidden_states中间结果然后输入到layers层中得到hidden_states中间结果用于下游任务。 self.embed_tokens nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)self.layers nn.ModuleList([MixtralDecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)])self._use_flash_attention_2 config._attn_implementation flash_attention_2self.norm MixtralRMSNorm(config.hidden_size, epsconfig.rms_norm_eps)DecoderLayer 主干网络的layers层就是由多个DecoderLayer组成的由num_hidden_layers参数决定一般我们说的模型量级就取决于这个数量7b的模型DecoderLayer层的数量是32。 DecoderLayer层中又包含了Attention层和MLP层主要的一个思想是利用了残差结构。 如下图所示分为两个部分 第一部分 首先将hidden_states文本向量化的结构进行复制即残差归一化注意力层残差相加 第二部分 首先将第一部分得到的hidden_states进行复制即残差归一化MLP层残差相加 外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传 #复制一份 residual hidden_states #归一化 hidden_states self.input_layernorm(hidden_states)#注意力层 hidden_states, self_attn_weights, present_key_value self.self_attn(hidden_stateshidden_states,attention_maskattention_mask,position_idsposition_ids,past_key_valuepast_key_value,output_attentionsoutput_attentions,use_cacheuse_cache,padding_maskpadding_mask, ) #加上残差 hidden_states residual hidden_states#复制一份 residual hidden_states #归一化 hidden_states self.post_attention_layernorm(hidden_states) #mlp hidden_states self.mlp(hidden_states) #加上残差 hidden_states residual hidden_statesoutputs (hidden_states,)if output_attentions:outputs (self_attn_weights,)if use_cache:outputs (present_key_value,)return outputsAttention 进行位置编码让模型更好的捕捉上下文信息 #经过线性层 query_states self.q_proj(hidden_states) key_states self.k_proj(hidden_states) value_states self.v_proj(hidden_states)#多头注意力形状变换 query_states query_states.view(bsz, q_len, self.num_heads, self.head_dim).transpose(1, 2) key_states key_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2) value_states value_states.view(bsz, q_len, self.num_key_value_heads, self.head_dim).transpose(1, 2) kv_seq_len key_states.shape[-2]#计算cos、sin #计算旋转位置嵌入 cos, sin self.rotary_emb(value_states, seq_lenkv_seq_len) query_states, key_states apply_rotary_pos_emb(query_states, key_states, cos, sin, position_ids)#计算权重 key_states repeat_kv(key_states, self.num_key_value_groups) value_states repeat_kv(value_states, self.num_key_value_groups) attn_weights torch.matmul(query_states, key_states.transpose(2, 3)) / math.sqrt(self.head_dim)#加上掩码 attn_weights attn_weights attention_mask #计算softmax attn_weights nn.functional.softmax(attn_weights, dim-1, dtypetorch.float32).to(query_states.dtype) attn_output torch.matmul(attn_weights, value_states)attn_output self.o_proj(attn_output) MLP mlp层的主要作用是应用非线性激活函数和线性投影。 首先将attention层得到的结果经过两个线性层得到gate_proj和up_projgate_proj经过激活函数再和up_proj相乘最后经过一个线性层得到最后的结果 self.gate_proj nn.Linear(self.hidden_size, self.intermediate_size, biasFalse) self.up_proj nn.Linear(self.hidden_size, self.intermediate_size, biasFalse) self.down_proj nn.Linear(self.intermediate_size, self.hidden_size, biasFalse) self.act_fn ACT2FN[config.hidden_act] down_proj self.down_proj(self.act_fn(self.gate_proj(x)) * self.up_proj(x))下游任务 因果推理 所谓因果推理就是回归任务。 self.lm_head nn.Linear(config.hidden_size, config.vocab_size, biasFalse)文本分类 即分类任务 self.score nn.Linear(config.hidden_size, self.num_labels, biasFalse)
http://www.hkea.cn/news/14444705/

相关文章:

  • 网站代码 输入文字 跳出内容给医院做网站赚钱吗
  • 水果网站建设规划书网站开发 进度表
  • 海东营销网站建设公司网站建设技术优势
  • 建设网站招标文件二级域名怎么做网站
  • 乡村生态旅游网站建设方案在线编辑
  • 上海住远建设工程监理公司网站群晖wordpress插件
  • 3d云打印网站开发网站设计的尺寸
  • 北京网站建设签约免费好用的网站制作
  • 网站域名到期惠州市企业网站seo点击软件
  • 企业网站建设方式立即关注公众号
  • 给企业做网站的公司专业的外贸网站建设公司
  • 网站优化建设安徽发广告去哪个平台
  • 辽宁网站备案小型个人网站制作
  • 内部网站建设拓扑wordpress自适应手机端
  • 企业网站管理系统排名如何建设小网站
  • 什么软件能看网站?aso如何优化
  • 入门网站分析应该怎么做WordPress怎么去掉主题也没
  • 网站开发与管理课程seo推广是什么工作
  • 连云港建设局官方网站网站专题建设方案
  • 江苏省建设厅网站查询多钱网网站
  • 北京天海网站建设公司网站设计多少钱市场价
  • 动图制作网站手机个别网页打不开
  • php网站登录系统怎么做wordpress 头像插件
  • 运城网站建设瑞安哪里有做百度的网站
  • 广州网站建设好公司深圳公司网站建设哪家好
  • 单位网站建设工作功劳asp网站开发实训
  • 永康物流网站中国建筑网招聘信息
  • 旅游网站wordpress集团做网站需要多大的带宽
  • 关于网站建设的简历网站推广论坛
  • 深圳建设银行网站首页页面设计快捷键