赞
踩
from modelscope import snapshot_download
model_dir = snapshot_download('Qwen/Qwen2-7B-Instruct')
from transformers import AutoTokenizer, AutoModelForCausalLM
model = AutoModelForCausalLM.from_pretrained(model_dir)
print(model)
Qwen2的模型结构如下
Qwen2ForCausalLM( (model): Qwen2Model( (embed_tokens): Embedding(152064, 3584) (layers): ModuleList( (0-27): 28 x Qwen2DecoderLayer( (self_attn): Qwen2SdpaAttention( (q_proj): Linear(in_features=3584, out_features=3584, bias=True) (k_proj): Linear(in_features=3584, out_features=512, bias=True) (v_proj): Linear(in_features=3584, out_features=512, bias=True) (o_proj): Linear(in_features=3584, out_features=3584, bias=False) (rotary_emb): Qwen2RotaryEmbedding() ) (mlp): Qwen2MLP( (gate_proj): Linear(in_features=3584, out_features=18944, bias=False) (up_proj): Linear(in_features=3584, out_features=18944, bias=False) (down_proj): Linear(in_features=18944, out_features=3584, bias=False) (act_fn): SiLU() ) (input_layernorm): Qwen2RMSNorm() (post_attention_layernorm): Qwen2RMSNorm() ) ) (norm): Qwen2RMSNorm() ) (lm_head): Linear(in_features=3584, out_features=152064, bias=False) )
结构图
区别
可以看到其中有的参数增加有的参数减少,猜想是:
减少的参数,并不会降低模型效果,反而能增加训练和推理效率,
增大的参数:比如MLP中的intermediate_size,参数越多,模型表达能力越明显。
Transformer Architecture with SwiGLU activation: 不多说,最主流的transformer架构,不变。但是,SwiGLU激活函数是GLU变体,可以让模型学习表达更加复杂的模式。
QKV bias:在Transformer模型中,Q、K、V分别代表查询(Query)、键(Key)和值(Value)。这些向量是通过输入向量与对应的权重矩阵相乘得到的。QKV bias表示在计算Q、K、V时添加可学习的偏置项。
GQA:Grouped-query attention,它是一种插值方法,介于多查询和多头注意力之间,可以在保持接近多头注意力的质量的同时,达到与多查询注意力相当的速度。
Mixture of SWA and Full Attention: SWA指的是Sliding Window Attention,是一种注意力模式,用于处理长序列输入的问题。而full attention则是传统的注意力机制,考虑序列中所有元素的交互。这里的mixture可能指的是这两种注意力机制的结合使用。
Improved Tokenizer Adaptive to Multiple Natural Languages and Code: 这说明模型使用了一种改进的分词器,它不仅适用于多种自然语言,还能处理代码。在自然语言处理和编程语言处理中,分词器用于将文本分解成更小的单位(如词、字符或其他符号),这是理解和处理文本的基础步骤。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。