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

广州专业做外贸网站建设河南seo关键词排名优化

广州专业做外贸网站建设,河南seo关键词排名优化,南阳全员核酸检测,怎么建设课程网站欢迎关注我的CSDN:https://spike.blog.csdn.net/ 本文地址:https://spike.blog.csdn.net/article/details/143749468 免责声明:本文来源于个人知识与公开资料,仅用于学术交流,欢迎讨论,不支持转载。 影响 (…

欢迎关注我的CSDN:https://spike.blog.csdn.net/
本文地址:https://spike.blog.csdn.net/article/details/143749468

免责声明:本文来源于个人知识与公开资料,仅用于学术交流,欢迎讨论,不支持转载。


Img

影响 (多模态)大语言模型 参数量的主要网络模块,即 Linear、Embedding、Norm(LayerNorm or RMSNorm) 等 3 个部分,其中,多模态大模型还包括 Conv3D,手动计算参数量,与 PyTorch 直接计算保持一致。

PyTorch 源码:

def count_parameters(model):return sum(p.numel() for p in model.parameters() if p.requires_grad)

Qwen2-VL-7B-InstructQwen2-7B-InstructLlama-3.1-8B-Instruct 为例。

网络结构参数量:

  • Linear:参数矩阵,或者加上biasLinear(in_features=w, out_features=h, bias=True) 参数量是 x=w*h+h,当 bias=False, 则是 x=w*h
  • Embedding:认为是没有 bias 的 Linear。
  • Norm:
    • LayerNorm 包括 2 个可训练参数 γ \gamma γ β \beta β,假设 hidden_size 的大小为 h,hidden_size 每一维都有两个参数,即 2*hidden_size
    • RMSNorm 每 1 维则只有 1 个可训练参数 , 即 hidden_size
  • Conv3D:即 Conv3d(3, 1280, kernel_size=(2, 14, 14), stride=(2, 14, 14), bias=False),即参数量=输入维度*输出维度*卷积核3*1280*2*14*14=1505280
  • RotaryEmbedding、Activition 和 Dropout:旋转位置编码、激活函数、Dropout 都没有可训练参数

Llama-3.1-8B-Instruct 参数量:

128256 ∗ 4096 + 32 ∗ ( 4096 ∗ 4096 ∗ 2 + 4096 ∗ 1024 ∗ 2 + 4096 ∗ 14336 ∗ 3 + 2 ∗ 4096 ) + 4096 + 4096 ∗ 128256 = 8030261248 = 8 B 128256*4096 + 32*(4096*4096*2 + 4096*1024*2 + 4096*14336*3 + 2*4096) + 4096 + 4096*128256 = 8030261248 = 8B 1282564096+32(409640962+409610242+4096143363+24096)+4096+4096128256=8030261248=8B

即:

P a r a m e t e r s = E m b e d d i n g + l a y e r s ∗ ( L i n e a r Q K V O + L i n e a r m l p + R M S N o r m ) + R M S N o r m + L i n e a r Parameters = Embedding + layers*(Linear_{QKVO} + Linear_{mlp}+RMSNorm) + RMSNorm + Linear Parameters=Embedding+layers(LinearQKVO+Linearmlp+RMSNorm)+RMSNorm+Linear

计算参数量:[Info] parameters: 8030261248

大语言模型 Llama-3.1-8B-Instruct 的网络结构:

LlamaForCausalLM((model): LlamaModel((embed_tokens): Embedding(128256, 4096)(layers): ModuleList((0-31): 32 x LlamaDecoderLayer((self_attn): LlamaSdpaAttention((q_proj): Linear(in_features=4096, out_features=4096, bias=False)(k_proj): Linear(in_features=4096, out_features=1024, bias=False)(v_proj): Linear(in_features=4096, out_features=1024, bias=False)(o_proj): Linear(in_features=4096, out_features=4096, bias=False)(rotary_emb): LlamaRotaryEmbedding())(mlp): LlamaMLP((gate_proj): Linear(in_features=4096, out_features=14336, bias=False)(up_proj): Linear(in_features=4096, out_features=14336, bias=False)(down_proj): Linear(in_features=14336, out_features=4096, bias=False)(act_fn): SiLU())(input_layernorm): LlamaRMSNorm((4096,), eps=1e-05)(post_attention_layernorm): LlamaRMSNorm((4096,), eps=1e-05)))(norm): LlamaRMSNorm((4096,), eps=1e-05)(rotary_emb): LlamaRotaryEmbedding())(lm_head): Linear(in_features=4096, out_features=128256, bias=False)
)

多模态视觉大模型 Qwen2-VL-7B-Instruct 的网络结构:

Qwen2VLForConditionalGeneration((visual): Qwen2VisionTransformerPretrainedModel((patch_embed): PatchEmbed((proj): Conv3d(3, 1280, kernel_size=(2, 14, 14), stride=(2, 14, 14), bias=False))(rotary_pos_emb): VisionRotaryEmbedding()(blocks): ModuleList((0-31): 32 x Qwen2VLVisionBlock((norm1): LayerNorm((1280,), eps=1e-06, elementwise_affine=True)(norm2): LayerNorm((1280,), eps=1e-06, elementwise_affine=True)(attn): VisionSdpaAttention((qkv): Linear(in_features=1280, out_features=3840, bias=True)(proj): Linear(in_features=1280, out_features=1280, bias=True))(mlp): VisionMlp((fc1): Linear(in_features=1280, out_features=5120, bias=True)(act): QuickGELUActivation()(fc2): Linear(in_features=5120, out_features=1280, bias=True))))(merger): PatchMerger((ln_q): LayerNorm((1280,), eps=1e-06, elementwise_affine=True)(mlp): Sequential((0): Linear(in_features=5120, out_features=5120, bias=True)(1): GELU(approximate='none')(2): Linear(in_features=5120, out_features=3584, bias=True))))(model): Qwen2VLModel((embed_tokens): Embedding(152064, 3584)(layers): ModuleList((0-27): 28 x Qwen2VLDecoderLayer((self_attn): Qwen2VLSdpaAttention((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): Qwen2VLRotaryEmbedding())(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((3584,), eps=1e-06)(post_attention_layernorm): Qwen2RMSNorm((3584,), eps=1e-06)))(norm): Qwen2RMSNorm((3584,), eps=1e-06)(rotary_emb): Qwen2VLRotaryEmbedding())(lm_head): Linear(in_features=3584, out_features=152064, bias=False)
)

总参数量:[Info] parameters: 8291375616

  • 视觉模型的参数量:[Info] parameters model.visual: 675759104
  • 语言模型的参数量:[Info] parameters model.model: 7070619136 + [Info] parameters model.lm_head: 544997376

即:675759104(8.15%) + 7070619136(85.28%) + 544997376(6.57%) = 8291375616 = 8B

Qwen2-VL-7B-InstructQwen2VisionTransformerPretrainedModel 参数量:

  • patch_embed 参数量: 3*1280*2*14*14=1505280
  • blocks 参数量:[Info] parameters model.visual.blocks: 629678080
    • 详细计算公式:32*(1280*2*2 + (1280+1)*3840 + (1280+1)*1280 + 1280*5121 + 5120*1281)=629678080
  • merger 参数量:

合并计算公式:

3 ∗ 1280 ∗ 2 ∗ 14 ∗ 14 + 32 ∗ ( 1280 ∗ 2 ∗ 2 + ( 1280 + 1 ) ∗ 3840 + ( 1280 + 1 ) ∗ 1280 + 1280 ∗ 5121 + 5120 ∗ 1281 ) + 1280 ∗ 2 + 5120 ∗ 5121 + ( 5120 + 1 ) ∗ 3584 = 675759104 3*1280*2*14*14 + 32*(1280*2*2 + (1280+1)*3840 + (1280+1)*1280 + 1280*5121 + 5120*1281) + 1280*2 + 5120*5121 + (5120+1)*3584 \\ = 675759104 3128021414+32(128022+(1280+1)3840+(1280+1)1280+12805121+51201281)+12802+51205121+(5120+1)3584=675759104

Qwen2-VL-7B-InstructQwen2VLModel 参数量:

152064 ∗ 3584 + 28 ∗ ( ( 3584 + 1 ) ∗ 3584 + ( 3584 + 1 ) ∗ 512 ∗ 2 + 3584 ∗ 3584 + 3584 ∗ 18944 ∗ 3 + 2 ∗ 3584 ) + 3584 = 7070619136 3584 ∗ 152064 = 544997376 152064*3584 + 28*((3584+1)*3584 + (3584+1)*512*2 + 3584*3584 + 3584*18944*3 + 2*3584) + 3584 \\ = 7070619136 \\ 3584 * 152064 = 544997376 1520643584+28((3584+1)3584+(3584+1)5122+35843584+3584189443+23584)+3584=70706191363584152064=544997376

因此,Qwen2-VL-7B 的数据量完全对齐。

测试:

# 预训练模型, 查看其词表大小
import torch
import transformers
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers import Qwen2VLForConditionalGeneration, AutoTokenizer, AutoProcessorprint(f"[Info] transformers version: {transformers.__version__}")def count_parameters(model):return sum(p.numel() for p in model.parameters() if p.requires_grad)# ------------ Qwen2-VL-7B ----------- #
model_path = "[your path]/llm/Qwen/Qwen2-VL-7B-Instruct"
print(f"[Info] model_path: {model_path}")# Load the model in half-precision on the available device(s)
model = Qwen2VLForConditionalGeneration.from_pretrained(model_path, torch_dtype="auto", device_map="auto"
)
processor = AutoProcessor.from_pretrained(model_path)
configuration = model.config
print(f"[Info] Qwen2-VL-7B vocab_size: {configuration.vocab_size}")
print(model)
print(f"[Info] parameters: {count_parameters(model)}")
print(f"[Info] parameters model.visual: {count_parameters(model.visual)}")
print(f"[Info] parameters model.model: {count_parameters(model.model)}")
print(f"[Info] parameters model.lm_head: {count_parameters(model.lm_head)}")
print(f"[Info] parameters model.visual.patch_embed: {count_parameters(model.visual.patch_embed)}")
print(f"[Info] parameters model.visual.blocks: {count_parameters(model.visual.blocks)}")
print(f"[Info] parameters model.visual.blocks[0].norm1: {count_parameters(model.visual.blocks[0].norm1)}")
print(f"[Info] parameters model.visual.blocks[0].norm2: {count_parameters(model.visual.blocks[0].norm2)}")
print(f"[Info] parameters model.visual.blocks[0].attn: {count_parameters(model.visual.blocks[0].attn)}")
print(f"[Info] parameters model.visual.blocks[0].mlp: {count_parameters(model.visual.blocks[0].mlp)}")
# ------------ Qwen2-VL-7B ----------- ## ------------ Qwen2-7B ----------- #
model_path = "[your path]/llm/Qwen/Qwen2-7B-Instruct"
print(f"[Info] model_path: {model_path}")device = "cuda" # the device to load the model onto
model = AutoModelForCausalLM.from_pretrained(model_path, device_map="auto")
tokenizer = AutoTokenizer.from_pretrained(model_path)
print(f"[Info] Qwen2-7B vocab_size: {tokenizer.vocab_size}")
print(model)
print(f"[Info] parameters: {count_parameters(model)}")
# ------------ Qwen2-7B ----------- ## ------------ Llama-3.1-8B ----------- #
model_path = "[your path]/llm/Meta-Llama-3.1-8B-Instruct"
print(f"[Info] model_path: {model_path}")
tokenizer = AutoTokenizer.from_pretrained(model_path)
model = AutoModelForCausalLM.from_pretrained(model_path,torch_dtype=torch.bfloat16,device_map="auto",
)
print(f"[Info] Llama-3.1-8B vocab_size: {tokenizer.vocab_size}")
print(model)
print(f"[Info] parameters: {count_parameters(model)}")
# ------------ Llama-3.1-8B ----------- #

Qwen2-7B 的参数量是 7615616512,即 7070619136 + 544997376 = 7615616512

参考:

  • 大模型的参数量是如何计算的
  • 大模型参数量如何计算
  • 如何根据模型结构,计算大模型的参数量?

文章转载自:
http://copolymer.hqbk.cn
http://jugal.hqbk.cn
http://stand.hqbk.cn
http://spermous.hqbk.cn
http://unappreciation.hqbk.cn
http://inhibiting.hqbk.cn
http://descent.hqbk.cn
http://mercurochrome.hqbk.cn
http://sinkage.hqbk.cn
http://uremic.hqbk.cn
http://tonsure.hqbk.cn
http://mutiny.hqbk.cn
http://voa.hqbk.cn
http://irrevocability.hqbk.cn
http://ethosuximide.hqbk.cn
http://pokesy.hqbk.cn
http://chitling.hqbk.cn
http://juan.hqbk.cn
http://lubricous.hqbk.cn
http://malone.hqbk.cn
http://quintar.hqbk.cn
http://cutty.hqbk.cn
http://thaumaturgy.hqbk.cn
http://primeval.hqbk.cn
http://minux.hqbk.cn
http://stainless.hqbk.cn
http://listeriosis.hqbk.cn
http://fancier.hqbk.cn
http://pharmaceutics.hqbk.cn
http://discipline.hqbk.cn
http://hogwash.hqbk.cn
http://unsoured.hqbk.cn
http://tangentially.hqbk.cn
http://respiratory.hqbk.cn
http://loose.hqbk.cn
http://pranidhana.hqbk.cn
http://fillibuster.hqbk.cn
http://heartache.hqbk.cn
http://genro.hqbk.cn
http://perchlorate.hqbk.cn
http://associator.hqbk.cn
http://dahalach.hqbk.cn
http://akademi.hqbk.cn
http://eluviate.hqbk.cn
http://nomism.hqbk.cn
http://satirize.hqbk.cn
http://myelosclerosis.hqbk.cn
http://xylophone.hqbk.cn
http://adversaria.hqbk.cn
http://segmentary.hqbk.cn
http://microinch.hqbk.cn
http://homalographic.hqbk.cn
http://kylin.hqbk.cn
http://northeast.hqbk.cn
http://pithy.hqbk.cn
http://distich.hqbk.cn
http://emit.hqbk.cn
http://albuminuria.hqbk.cn
http://squacco.hqbk.cn
http://antiar.hqbk.cn
http://goldeneye.hqbk.cn
http://quickie.hqbk.cn
http://flybelt.hqbk.cn
http://heeled.hqbk.cn
http://miff.hqbk.cn
http://unaware.hqbk.cn
http://cant.hqbk.cn
http://bracero.hqbk.cn
http://burying.hqbk.cn
http://oud.hqbk.cn
http://centremost.hqbk.cn
http://hoodlum.hqbk.cn
http://notarize.hqbk.cn
http://eversible.hqbk.cn
http://hypochromic.hqbk.cn
http://sorority.hqbk.cn
http://bootlegger.hqbk.cn
http://supertransuranic.hqbk.cn
http://philhellenic.hqbk.cn
http://brasilia.hqbk.cn
http://inveracious.hqbk.cn
http://hobart.hqbk.cn
http://infranics.hqbk.cn
http://obnoxious.hqbk.cn
http://jocko.hqbk.cn
http://rocking.hqbk.cn
http://crampfish.hqbk.cn
http://windscreen.hqbk.cn
http://diphtheria.hqbk.cn
http://artificial.hqbk.cn
http://sexisyllable.hqbk.cn
http://inhuman.hqbk.cn
http://trainside.hqbk.cn
http://bottleholder.hqbk.cn
http://militancy.hqbk.cn
http://ah.hqbk.cn
http://pfalz.hqbk.cn
http://prohibitionism.hqbk.cn
http://townhall.hqbk.cn
http://saponification.hqbk.cn
http://www.dt0577.cn/news/63120.html

相关文章:

  • ic商城网站建设千锋教育课程
  • 网站广告条素材ip网站查询服务器
  • wordpress 网址站竞价外包
  • 番禺建设网站多少钱软文营销
  • 免费的人工客服系统宁波抖音seo搜索优化软件
  • 外贸搜索网站西安seo排名外包
  • 新网站做百度推广正版seo搜索引擎
  • 英文网站怎么做营销软件app
  • 呼伦贝尔做网站公司百度关键词网站排名优化软件
  • 做网站的总要求上门网络策划是做什么的
  • 互联网相关网站怎么创建网页
  • 外贸网站建设需要注意事项百度seo排名优化软件
  • 不写编程可以做网站建设岳阳网站设计
  • b2c模式的电商平台网站优化查询
  • 我的网站模板下载 迅雷下载 迅雷下载网络销售公司怎么运作
  • 天津 网站设计公司成都网络推广外包公司哪家好
  • 青岛网站建设设计简单的个人主页网站制作
  • 伊克昭盟seo免费智能seo收录工具
  • 给网站做翻译搜索引擎优化的对比
  • 空调seo是什么意思沈阳seo关键字优化
  • 音乐网站排名百度登录入口百度
  • 旅游做视频网站爱站网seo查询
  • 联合创始人网站怎么做私域流量运营管理
  • wordpress网站阿里云备案博客网站登录入口
  • 衡阳网站页面设计公司安徽网络seo
  • 礼品网站设计潍坊网站建设方案咨询
  • 做课展网站百度点击软件找名风
  • 怎么用wix做网站公司想建个网站怎么弄
  • 上海网站建设品牌免费推广广告链接
  • 没疫情的19个城市杭州百度seo