阿里大模型Qwen2.5-14B-Chat模型结构及代码解析

通义千问语言模型Qwen2.5架构详解 此外,将基于API的模型 Qwen-Plus 与领先的专有和开源模型进行了对比,包括 GPT4-o、Claude-3.5-Sonnet、Llama-3.1-405B和DeepSeek-V2.5。Qwen2.5-Math-72B-Instruct的整体性能超越了Qwen2-Math-72B-Instruct和GPT4-o,甚至是非常小的专业模型如 Qwen2.5-Math-1.5B-Instruct也能在与大型语言模型的竞争中取得高度竞争力的表现。近来也出现了明显的转向小型语言模型(SLMs)的趋势。 阅读详情
AI摘要

本文介绍了Qwen2.5 - 14B - Chat和Qwen2.5 - 14B - Base模型结构,包括主干模块、Qwen2Model模块等,还阐述了各模块代码实现要点。同时,作为资深码农分享大模型学习经验,提供AGI大模型系统学习路线、视频教程等资料,强调学习大模型的前景和价值。

1、模型结构:

Qwen2.5-14B-Chat和Qwen2.5-14B-Base模型结构一样,与Qwen1.5-14B-Chat代码也一样,不同点在于Qwen2.5-14B-Chat是48层transformer,比Qwen1.5-14B多8层,比之前的更深,模型结构如下:

img

模型代码链接:

https://github.com/huggingface/transformers/blob/main/src/transformers/models/qwen2/modeling_qwen2.py

2、主干模块Qwen2ForCausalLM,模型入口

模型结构中,每个虚线框的名字对应代码的类名,最外层的Qwen2ForCausalLM,继承于Qwen2PreTrainedModel类,而Qwen2PreTrainedModel主要是在transformer的类(PreTrainedModel)上进行了一个简单的封装,无重要逻辑代码,Qwen2ForCausalLM主要实现如下:

class Qwen2ForCausalLM(Qwen2PreTrainedModel):
    _tied_weights_keys = ["lm_head.weight"]

    def __init__(self, config):
        super().__init__(config)
        self.model = Qwen2Model(config)
        self.vocab_size = config.vocab_size
        self.lm_head = nn.Linear(config.hidden_size, config.vocab_size, bias=False)

        # Initialize weights and apply final processing
        self.post_init()

模型初始化__init__方法中,主要初始化Qwen2Model和输出层lm_head线性层,lm_head层的输入是size是hidden_size,输出是词表大小,主要作用就是将模型的输出,映射到token,输出的token会经过tokenizer的decode得到文本(英文就是单词,中文就是汉字)。

class Qwen2ForCausalLM(Qwen2PreTrainedModel):
    _tied_weights_keys = ["lm_head.weight"]

    @replace_return_docstrings(output_type=CausalLMOutputWithPast, config_class=_CONFIG_FOR_DOC)
    def forward(
        self,
        input_ids: torch.LongTensor = None,
        attention_mask: Optional[torch.Tensor] = None,
        position_ids: Optional[torch.LongTensor] = None,
        past_key_values: Optional[List[torch.FloatTensor]] = None,
        inputs_embeds: Optional[torch.FloatTensor] = None,
        labels: Optional[torch.LongTensor] = None,
        use_cache: Optional[bool] = None,
        output_attentions: Optional[bool] = None,
        output_hidden_states: Optional[bool] = None,
        return_dict: Optional[bool] = None,
        cache_position: Optional[torch.LongTensor] = None,
        num_logits_to_keep: int = 0,
    )
 -> Union[Tuple, CausalLMOutputWithPast]:
        output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
        output_hidden_states = (
            output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
        )
        return_dict = return_dict if return_dict is not None else self.config.use_return_dict

        # decoder outputs consists of (dec_features, layer_state, dec_hidden, dec_attn)
        outputs = self.model(
            input_ids=input_ids,
            attention_mask=attention_mask,
            position_ids=position_ids,
            past_key_values=past_key_values,
            inputs_embeds=inputs_embeds,
            use_cache=use_cache,
            output_attentions=output_attentions,
            output_hidden_states=output_hidden_states,
            return_dict=return_dict,
            cache_position=cache_position,
        )

        hidden_states = outputs[0]
        if labels is None and not is_torchdynamo_compiling():
            logger.warning_once(
                "Starting from v4.46, the `logits` model output will have the same type as the model (except at train time, where it will always be FP32)"
            )
        # Only compute necessary logits, and do not upcast them to float if we are not computing the loss
        # TODO: remove the float() operation in v4.46
        logits = self.lm_head(hidden_states[:, -num_logits_to_keep:, :]).float()

        loss = None
        if labels is not None:
            # Upcast to float if we need to compute the loss to avoid potential precision issues
            logits = logits.float()
            # Shift so that tokens < n predict n
            shift_logits = logits[..., :-1, :].contiguous()
            shift_labels = labels[..., 1:].contiguous()
            # Flatten the tokens
            loss_fct = CrossEntropyLoss()
            shift_logits = shift_logits.view(-1, self.config.vocab_size)
            shift_labels = shift_labels.view(-1)
            # Enable model parallelism
            shift_labels = shift_labels.to(shift_logits.device)
            loss = loss_fct(shift_logits, shift_labels)

        if not return_dict:
            output = (logits,) + outputs[1:]
            return (loss,) + output if loss is not None else output

        return CausalLMOutputWithPast(
            loss=loss,
            logits=logits,
            past_key_values=outputs.past_key_values,
            hidden_states=outputs.hidden_states,
            attentions=outputs.attentions,
        )

forword中,有几个稍微有点绕的参数,稍微解释下,一个是num_logits_to_keep

解释:
lm_head: 语言模型的头部是模型的最后一层,负责将模型内部的表示转换为词汇表上的概率分布。简单来说,它将模型学到的信息转化为对下一个词的预测。
num_logits_to_keep: 这个参数决定在采样下一个词的时候,保留多少个最高概率的词作为候选。
原理:
语言模型处理输入序列后,lm_head 会输出一个logits向量,表示词汇表中每个词的得分。
通常,我们会将 logits 向量通过 softmax 函数转换为概率分布。
在生成文本时,我们并不总是选择概率最高的词。为了增加文本的多样性,可以使用采样策略。
num_logits_to_keep 参数就限制了采样范围。如果设置为5,那么只会从概率最高的5个词中进行采样。
作用:
控制输出多样性: num_logits_to_keep 越小,采样范围越窄,生成的文本可能更稳定、更接近高概率的词,但多样性会降低。
平衡创造力与准确性: 较大的 num_logits_to_keep 允许模型探索更多低概率词,增加文本的创造性和意外性,但也可能导致语法错误或不连贯的句子。
例子:
假设词汇表是 ["我", "爱", "学习", "机器学习", "人工智能"],lm_head 输出的 logits 向量是 [0.1, 0.2, 0.3, 0.8, 0.6]。
如果 num_logits_to_keep 设置为 2,那么只会考虑 "机器学习" 和 "人工智能" 两个词进行采样。
如果 num_logits_to_keep 设置为 5,那么所有词都会被考虑。
希望这个解释能够帮助你理解 lm_head 和 num_logits_to_keep 的含义。

另一个是loss计算:logits中的shift_logits,

shift_logits[..., :-1, :]:

shift_logits 是一个多维张量,这里使用了省略号 ... 来表示所有前面的维度。
:-1 表示取最后一个维度(通常是序列长度)的所有元素,除了最后一个元素。
: 表示取其他所有维度的所有元素。
这行代码的效果是将 shift_logits 在最后一个维度上向左移动一位,丢弃最后一个元素。
shift_logits[..., 1:]:

与 shift_logits 类似,labels 也是一个多维张量。
1: 表示取最后一个维度从第二个元素开始的所有元素。
这行代码的效果是将 labels 在最后一个维度上向右移动一位,丢弃第一个元素。
.contiguous():

contiguous() 方法用于确保张量在内存中是连续存储的。
在进行切片操作后,新生成的张量可能引用原始张量中不连续的内存块,使用 .contiguous() 方法可以将这些内存块重新排列,使张量元素在内存中连续存储。
代码目的:

import torch
logits = torch.tensor([[[1, 2, 3],
                       [4, 5, 6]],
                      [[7, 8, 9],
                       [10, 11, 12]]])
labels = torch.tensor([[1, 2],
                      [3, 4]])

shift_logits = logits[..., :-1, :].contiguous()
shift_labels = labels[..., 1:].contiguous()

print(f"shift_logits: \n{shift_logits}")
print(f"shift_labels: \n{shift_labels}")
输出:
shift_logits: 
tensor([[[1, 2],
         [4, 5]],

        [[7, 8],
         [10, 11]]])
shift_labels: 
tensor([[2],
        [4]])
可以看到,shift_logits 相对于 logits 缺少了最后一个元素,而 shift_labels 相对于 labels 缺少了第一个元素,并且两者都保持了在内存中的连续存储。

3、Qwen2Model模块

img

Qwen2Model与Qwen1.5的主要区别也在这儿,这是48层

class Qwen2Model(Qwen2PreTrainedModel):
    """
    Transformer decoder consisting of *config.num_hidden_layers* layers. Each layer is a [`Qwen2DecoderLayer`]

    Args:
        config: Qwen2Config
    """

    def __init__(self, config: Qwen2Config):
        super().__init__(config)
        self.padding_idx = config.pad_token_id
        self.vocab_size = config.vocab_size

        self.embed_tokens = nn.Embedding(config.vocab_size, config.hidden_size, self.padding_idx)
        self.layers = nn.ModuleList(
            [Qwen2DecoderLayer(config, layer_idx) for layer_idx in range(config.num_hidden_layers)]
        )
        self._attn_implementation = config._attn_implementation
        self.norm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
        self.rotary_emb = Qwen2RotaryEmbedding(config=config)

        self.gradient_checkpointing = False
        # Initialize weights and apply final processing
        self.post_init()

初始化方法中,主要就是初始化token词表的embedding、transformer的layers和归一化层norm的Qwen2RMSNorm,forward中的核心代码:

class Qwen2Model(Qwen2PreTrainedModel):
    def forward(
        self,
        input_ids: torch.LongTensor = None,
        attention_mask: Optional[torch.Tensor] = None,
        position_ids: Optional[torch.LongTensor] = None,
        past_key_values: Optional[List[torch.FloatTensor]] = None,
        inputs_embeds: Optional[torch.FloatTensor] = None,
        use_cache: Optional[bool] = None,
        output_attentions: Optional[bool] = None,
        output_hidden_states: Optional[bool] = None,
        return_dict: Optional[bool] = None,
        cache_position: Optional[torch.LongTensor] = None,
    ) -> Union[Tuple, BaseModelOutputWithPast]:
        output_attentions = output_attentions if output_attentions is not None else self.config.output_attentions
        output_hidden_states = (
            output_hidden_states if output_hidden_states is not None else self.config.output_hidden_states
        )
        # ....

        if inputs_embeds is None:
            inputs_embeds = self.embed_tokens(input_ids)
            
        if cache_position is None:
            past_seen_tokens = past_key_values.get_seq_length() if past_key_values is not None else 0
            cache_position = torch.arange(
                past_seen_tokens, past_seen_tokens + inputs_embeds.shape[1], device=inputs_embeds.device
            )
        if position_ids is None:
            position_ids = cache_position.unsqueeze(0)

        causal_mask = self._update_causal_mask(
            attention_mask, inputs_embeds, cache_position, past_key_values, output_attentions
        )
        for decoder_layer in self.layers:
            if output_hidden_states:
                all_hidden_states += (hidden_states,)

            if self.gradient_checkpointing and self.training:
                layer_outputs = self._gradient_checkpointing_func(
                    decoder_layer.__call__,
                    hidden_states,
                    causal_mask,
                    position_ids,
                    past_key_values,
                    output_attentions,
                    use_cache,
                    cache_position,
                    position_embeddings,
                )
            else:
                layer_outputs = decoder_layer(
                    hidden_states,
                    attention_mask=causal_mask,
                    position_ids=position_ids,
                    past_key_value=past_key_values,
                    output_attentions=output_attentions,
                    use_cache=use_cache,
                    cache_position=cache_position,
                    position_embeddings=position_embeddings,
                )

            hidden_states = layer_outputs[0]

            if use_cache:
                next_decoder_cache = layer_outputs[2 if output_attentions else 1]

            if output_attentions:
                all_self_attns += (layer_outputs[1],)

        hidden_states = self.norm(hidden_states)

        # add hidden states from the last decoder layer
        if output_hidden_states:
            all_hidden_states += (hidden_states,)

主要从input_ids变为inputs_embeds,position_ids位置编码的构建(之前序列长度开始past_seen_tokens到past_seen_tokens + inputs_embeds.shape[1]当前序列长度结束),最后一个就是causal_mask(主要采用torch.triu(causal_mask, diagonal=1)创建一个上三角矩阵,同时把padding部分的逻辑加上)构建

4、Qwen2DecoderLayer部分

img

初始化如下:

class Qwen2DecoderLayer(nn.Module):
    def __init__(self, config: Qwen2Config, layer_idx: int):
        super().__init__()
        self.hidden_size = config.hidden_size

        if config.sliding_window and config._attn_implementation != "flash_attention_2":
            logger.warning_once(
                f"Sliding Window Attention is enabled but not implemented for `{config._attn_implementation}`; "
                "unexpected results may be encountered."
            )
        self.self_attn = QWEN2_ATTENTION_CLASSES[config._attn_implementation](config, layer_idx)

        self.mlp = Qwen2MLP(config)
        self.input_layernorm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)
        self.post_attention_layernorm = Qwen2RMSNorm(config.hidden_size, eps=config.rms_norm_eps)

QWEN2_ATTENTION_CLASSES中包含了Qwen2Attention、Qwen2FlashAttention2和Qwen2SdpaAttention注意力机制算法,

    def forward(
        self,
        hidden_states: torch.Tensor,
        attention_mask: Optional[torch.Tensor] = None,
        position_ids: Optional[torch.LongTensor] = None,
        past_key_value: Optional[Tuple[torch.Tensor]] = None,
        output_attentions: Optional[bool] = False,
        use_cache: Optional[bool] = False,
        cache_position: Optional[torch.LongTensor] = None,
        position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,  # will become mandatory in v4.46
        **kwargs,
    ) -> Tuple[torch.FloatTensor, Optional[Tuple[torch.FloatTensor, torch.FloatTensor]]]:
        """
        Args:
            hidden_states (`torch.FloatTensor`): input to the layer of shape `(batch, seq_len, embed_dim)`
            attention_mask (`torch.FloatTensor`, *optional*): attention mask of size
                `(batch, sequence_length)` where padding elements are indicated by 0.
            output_attentions (`bool`, *optional*):
                Whether or not to return the attentions tensors of all attention layers. See `attentions` under
                returned tensors for more detail.
            use_cache (`bool`, *optional*):
                If set to `True`, `past_key_values` key value states are returned and can be used to speed up decoding
                (see `past_key_values`).
            past_key_value (`Tuple(torch.FloatTensor)`, *optional*): cached past key and value projection states
            cache_position (`torch.LongTensor` of shape `(sequence_length)`, *optional*):
                Indices depicting the position of the input sequence tokens in the sequence.
            position_embeddings (`Tuple[torch.FloatTensor, torch.FloatTensor]`, *optional*):
                Tuple containing the cosine and sine positional embeddings of shape `(batch_size, seq_len, head_dim)`,
                with `head_dim` being the embedding dimension of each attention head.
            kwargs (`dict`, *optional*):
                Arbitrary kwargs to be ignored, used for FSDP and other methods that injects code
                into the model
        """

        residual = hidden_states

        hidden_states = self.input_layernorm(hidden_states)

        # Self Attention
        hidden_states, self_attn_weights, present_key_value = self.self_attn(
            hidden_states=hidden_states,
            attention_mask=attention_mask,
            position_ids=position_ids,
            past_key_value=past_key_value,
            output_attentions=output_attentions,
            use_cache=use_cache,
            cache_position=cache_position,
            position_embeddings=position_embeddings,
        )
        hidden_states = residual + hidden_states

        # Fully Connected
        residual = hidden_states
        hidden_states = self.post_attention_layernorm(hidden_states)
        hidden_states = self.mlp(hidden_states)
        hidden_states = residual + hidden_states

        outputs = (hidden_states,)

        if output_attentions:
            outputs += (self_attn_weights,)

        if use_cache:
            outputs += (present_key_value,)

        return outputs

hidden_states会进过第一个block,过rmslayernorm、attention,之后加残差hidden_states = residual + hidden_states,再经过layernorm,进入mlp,最后再残差hidden_states = residual + hidden_states

5、Attention模块:

在这里插入图片描述

最核心的模块,

class Qwen2Attention(nn.Module):
    """
    Multi-headed attention from 'Attention Is All You Need' paper. Modified to use sliding window attention: Longformer
    and "Generating Long Sequences with Sparse Transformers".
    """

    def __init__(self, config: Qwen2Config, layer_idx: Optional[int] = None):
        super().__init__()
        self.config = config
        self.layer_idx = layer_idx
        if layer_idx is None:
            logger.warning_once(
                f"Instantiating {self.__class__.__name__} without passing `layer_idx` is not recommended and will "
                "to errors during the forward call, if caching is used. Please make sure to provide a `layer_idx` "
                "when creating this class."
            )

        self.hidden_size = config.hidden_size
        self.num_heads = config.num_attention_heads
        self.head_dim = self.hidden_size // self.num_heads
        self.num_key_value_heads = config.num_key_value_heads
        self.num_key_value_groups = self.num_heads // self.num_key_value_heads
        self.rope_theta = config.rope_theta
        self.is_causal = True
        self.attention_dropout = config.attention_dropout

        if (self.head_dim * self.num_heads) != self.hidden_size:
            raise ValueError(
                f"hidden_size must be divisible by num_heads (got `hidden_size`: {self.hidden_size}"
                f" and `num_heads`: {self.num_heads})."
            )
        self.q_proj = nn.Linear(self.hidden_size, self.num_heads * self.head_dim, bias=True)
        self.k_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True)
        self.v_proj = nn.Linear(self.hidden_size, self.num_key_value_heads * self.head_dim, bias=True)
        self.o_proj = nn.Linear(self.num_heads * self.head_dim, self.hidden_size, bias=False)

        self.rotary_emb = Qwen2RotaryEmbedding(config=self.config)

主要初始化q、k、v及输出的映射线性Linear层,另外就是RoPE的位置位置编码Embedding层

    def forward(
        self,
        hidden_states: torch.Tensor,
        attention_mask: Optional[torch.Tensor] = None,
        position_ids: Optional[torch.LongTensor] = None,
        past_key_value: Optional[Cache] = None,
        output_attentions: bool = False,
        use_cache: bool = False,
        cache_position: Optional[torch.LongTensor] = None,
        position_embeddings: Optional[Tuple[torch.Tensor, torch.Tensor]] = None,  # will become mandatory in v4.46
    ) -> Tuple[torch.Tensor, Optional[torch.Tensor], Optional[Tuple[torch.Tensor]]]:
        bsz, q_len, _ = hidden_states.size()

        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)

        if position_embeddings is None:
            logger.warning_once(
                "The attention layers in this model are transitioning from computing the RoPE embeddings internally "
                "through `position_ids` (2D tensor with the indexes of the tokens), to using externally computed "
                "`position_embeddings` (Tuple of tensors, containing cos and sin). In v4.46 `position_ids` will be "
                "removed and `position_embeddings` will be mandatory."
            )
            cos, sin = self.rotary_emb(value_states, position_ids)
        else:
            cos, sin = position_embeddings
        query_states, key_states = apply_rotary_pos_emb(query_states, key_states, cos, sin)

        if past_key_value is not None:
            cache_kwargs = {"sin": sin, "cos": cos, "cache_position": cache_position}  # Specific to RoPE models
            key_states, value_states = past_key_value.update(key_states, value_states, self.layer_idx, cache_kwargs)

        # repeat k/v heads if n_kv_heads < n_heads
        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)
        if attention_mask is not None:  # no matter the length, we just slice it
            causal_mask = attention_mask[:, :, :, : key_states.shape[-2]]
            attn_weights = attn_weights + causal_mask
        # upcast attention to fp32
        attn_weights = nn.functional.softmax(attn_weights, dim=-1, dtype=torch.float32).to(query_states.dtype)
        attn_weights = nn.functional.dropout(attn_weights, p=self.attention_dropout, training=self.training)
        attn_output = torch.matmul(attn_weights, value_states)

        if attn_output.size() != (bsz, self.num_heads, q_len, self.head_dim):
            raise ValueError(
                f"`attn_output` should be of size {(bsz, self.num_heads, q_len, self.head_dim)}, but is"
                f" {attn_output.size()}"
            )

        attn_output = attn_output.transpose(1, 2).contiguous()
        attn_output = attn_output.reshape(bsz, q_len, self.hidden_size)

        attn_output = self.o_proj(attn_output)

        if not output_attentions:
            attn_weights = None

        return attn_output, attn_weights, past_key_value

q、k、v经过线性层映射后,k和v分别加上position embeding,算attn_weights,这里有一个技巧attn_weights = attn_weights + causal_mask,不是采用乘法的方式(减少计算量),而是采用加法,causal_mask是一个上三角矩阵,里面存储一个非常小的数,加上这个数后attn_weights中上三角矩阵中的值也会非常小,再经过softmax后,attn_weights也很小,对于的物理意义在同一句话中,保证模型了偷看看不到未来的信息,都是用之前的信息预估下一个token,这里最后再经过线性层o_proj输出,保持维度一致。

​

如何学习大模型

现在社会上大模型越来越普及了,已经有很多人都想往这里面扎,但是却找不到适合的方法去学习。

作为一名资深码农,初入大模型时也吃了很多亏,踩了无数坑。现在我想把我的经验和知识分享给你们,帮助你们学习AI大模型,能够解决你们学习中的困难。

下面这些都是我当初辛苦整理和花钱购买的资料,现在我已将重要的AI大模型资料包括市面上AI大模型各大白皮书、AGI大模型系统学习路线、AI大模型视频教程、实战学习,等录播视频免费分享出来,需要的小伙伴可以扫取。

一、AGI大模型系统学习路线

很多人学习大模型的时候没有方向,东学一点西学一点,像只无头苍蝇乱撞,我下面分享的这个学习路线希望能够帮助到你们学习AI大模型。

在这里插入图片描述

二、AI大模型视频教程

在这里插入图片描述

三、AI大模型各大学习书籍

在这里插入图片描述

四、AI大模型各大场景实战案例

在这里插入图片描述

五、结束语

学习AI大模型是当前科技发展的趋势,它不仅能够为我们提供更多的机会和挑战,还能够让我们更好地理解和应用人工智能技术。通过学习AI大模型,我们可以深入了解深度学习、神经网络等核心概念,并将其应用于自然语言处理、计算机视觉、语音识别等领域。同时,掌握AI大模型还能够为我们的职业发展增添竞争力,成为未来技术领域的领导者。

再者,学习AI大模型也能为我们自己创造更多的价值,提供更多的岗位以及副业创收,让自己的生活更上一层楼。

因此,学习AI大模型是一项有前景且值得投入的时间和精力的重要选择。

QWEN 2.5模型结构解析与代码解读 对Qwen2.5大模型的代码进行研究 阅读详情

相关推荐

阿里语音交互大模型Fun-Audio-Chat-8B解析

阿里巴巴通义实验室(FunAudio Team)于最近祭出了新的语音交互大模型——,不同于传统级联方案(ASR+LLM+TTS)的拼凑感,也不同于早期 Audio-LLM 的高延迟,Fun-Audio-Chat 通过双分辨率语音表征(DRSR)核心鸡尾酒疗法训练(Core-Cocktail Training)以及多任务 DPO,在 8B 参数规模下实现了低延迟、高情感感知和全双工交互。本文将从架构设计到训练范式,全方位拆解这一“语音版 Qwen”的技术内核。

kakaZhui的博客 1131

大模型版本区分

是一个通用的大型语言模型,适用于各种自然语言处理任务。是在通用模型基础上经过指令微调的版本,特别适合处理指令式的任务。选择哪个版本取决于你的具体需求。如果你需要一个通用的模型来处理多种任务,可以选择。如果你的任务涉及大量指令式的操作,建议使用。参考链接。

AI智能,无处不在 1万+

笔记本运行270亿参数大模型:Qwen3.8-27B与Atomic Chat本地部署实战

大语言模型(LLM)的本地部署是当前AI工程实践的热点,其核心在于通过模型量化与高效推理框架,在有限硬件资源下实现性能与效率的平衡。量化技术通过降低模型权重的数值精度,大幅压缩模型体积与内存占用,而GGUF格式与llama.cpp等推理框架则实现了CPU/GPU混合计算,让大模型在消费级硬件上运行成为可能。这项技术的价值在于为开发者提供了低成本、高隐私、离线的AI能力验证与原型开发环境,尤其适用于代码辅助、文档分析等场景。本文以Qwen3.8-27B模型和Atomic Chat工具为例,详细解析如何在RTX

weixin_30788239的博客 1436

autodl运行模型报错

autodl V100 运行HuaTuo-o1,报错。报错了,是因为gpu资源,改用半精度就解决了。

mmdsl083的博客 1466

Sliding Window Attention is enabled but not implemented for `sdpa`; unexpected results may be encoun

Scaled Dot-Product Attention 是一种用于计算输入序列中元素之间注意力分数的方法。给定查询(Query,QQQ)、键(Key,KKK)和值(Value,VVVAttentionQKVsoftmaxQKTdkVAttentionQKVsoftmaxdk​​QKT​V其中,QQQ是形状为ndk(n, d_k)ndk​的矩阵,KKK是形状为mdk(m, d_k)mdk​的矩阵,VVV。

ZhangJiqun&191cm&85kg 1435

数模【Mathematica(安装、入门方法、基本计算、基本图形、创建互动模型、利用数据、幻灯片演示、完整实例)】

Mathematica(安装and激活、入门方法、基本计算、基本图形、创建互动模型、利用数据、幻灯片演示、完整实例) Mathematica_11.3.0 安装教程 Mathematica11.3 激活 P1 笔记本 P2 入门方法 P3 基本计算 P4 基本图形 P5 创建互动模型 P6 利用数据 P7 演示 P8 完整实例

upward 12万+

基于Qwen2.5-7B-Chat的本地化部署实战——从模型原理到企业级应用

本文详细介绍阿里通义千问Qwen2.5-7B-Chat模型的本地部署方案。针对企业数据安全与成本控制需求,采用Ollama框架结合vLLM推理加速,构建离线智能对话系统。内容包括技术原理、环境配置、模型部署、应用搭建及性能优化等完整流程。实测单卡RTX4090环境下推理速度达53.76tokens/秒,提供Gradio Web界面和FastAPI服务方案,支持企业级应用集成。文章包含详细代码实现、故障排查指南及智能客服、知识库问答等实践案例,为中小企业提供经济高效的大模型私有化部署方案。

七夜zippoe的博客 1412

红外小目标检测新思路:当DETR遇上Mamba状态空间模型,速度提升3倍

本文探讨了将Mamba状态空间模型与DETR框架结合,用于解决红外小目标检测的难题。该创新方案通过线性复杂度的Mamba模块替代传统Transformer的自注意力机制,在保持高检测精度的同时,显著提升了推理速度,实现了实时性能的突破,为无人机巡检、安防监控等场景提供了高效解决方案。

hhh00的博客 665

Qwen2.5-1.5B开源大模型实战:Streamlit界面+官方chat template全适配解析

本文介绍了如何在星图GPU平台上自动化部署🧠Qwen2.5-1.5B本地智能对话助手镜像,快速搭建私有化AI应用。该方案基于轻量级开源大模型,通过Streamlit构建了直观的网页聊天界面,适用于本地代码解释、文案创作等智能对话场景,保障数据隐私与安全。

weixin_36238982的博客 602

本地部署 Bolt.new - 小学生都能轻松搭建AI编程环境

本地部署 Bolt.new - 小学生都能轻松搭建AI编程环境

engchina的专栏 8625

微信小程序 - 下单账号和支付账号不一致,请核实后再支付(微信小程序或微信H5页面/微信公众号网页支付时报错:“下单账号和支付账号不一致,请核实后再支付”,买家微信支付时提示错误)详细排查和解决方案!

微信支付出现 “下单账号与支付账号不一致,请核实后再支付”微信小程序下单账号与支付账号不一致不让支付,微信公众号网页 微信H5页面JS-SDK支付时出现错误:下单账号和支付账号不一致,请核实后再支付,openId导致的微信中“下单账号和支付账号不一致”原因及解决办法,调用统一下单所传openId与实际支付用户的openId不一致,微信支付jssdk报错,检查了没有不一致依然报错怎么办,微信支付下单账号和支付账号不一致,请核实后再支付,微信支付功能用JSAPI支付,H5页面负责下单并支付jsapi,微信调起支

🏆 前端领域优质创作者 5330

Qwen2.5-14B-Instruct实战:高效部署147亿参数指令大模型

Qwen2.5-14B-Instruct作为阿里云最新发布的147亿参数指令微调大语言模型,在代码生成、数学推理和多语言处理方面展现出卓越性能。该模型基于先进的Transformer架构,支持131,072 tokens上下文长度和8,192 tokens生成长度,为开发者提供了强大的AI助手解决方案。 ## 一、核心价值与快速部署方案 ### 模型定位与应用场景 Qwen2.5-14B-In

gitblog_00309的博客 709

大数据学习指南从入门到精通

利用框架的力量,看懂游戏规则,才是入行的前提大多数人不懂,不会,不做,才是你的机会,你得行动,不能畏首畏尾选择才是拉差距关键,风向,比你流的汗水重要一万倍,逆风划船要累死人的为什么选择学习大数据开发,不选择Java开发?借棋弈做比喻,智商高的不要选择五子琪,要选择围棋,它能长久地吸引你。不都是在棋盘上一颗黑子一颗白子地下吗?因为围棋更复杂,能够掌握如此复杂的技艺、产生稳定输出的棋手、让我们更佩服。选择学习大数据开发也如此,能让你的职业生涯走得更远,少走弯路。

Lansonli(蓝深李)的博客 2万+

你的RTX 4090终于有用了!保姆级教程,5分钟在本地跑起Qwen-14B-Chat,效果惊人

你的RTX 4090终于有用了!保姆级教程,5分钟在本地跑起Qwen-14B-Chat,效果惊人 【免费下载链接】Qwen-14B-Chat 阿里云研发的Qwen-14B大模型,基于Transformer架构,预训练数据涵盖网络文本、书籍、代码等,打造出会聊天的AI助手Qwen-14B-Chat。支持多轮对话,理解丰富语...

gitblog_02558的博客 664

2025 华为OD机试真题e卷 C语言 实现【竖直四子棋】

竖直四子棋的棋盘是竖立起来的,双方轮流选择棋盘的一列下子,棋子因重力落到棋盘底部或者其他棋子之上,当一列的棋子放满时,无法再在这列上下子。

MISAYAONE的博客 1417

196、NPU的编译器开发:教程与示例代码编写

NPU编译器开发实战指南 摘要:本文分享了NPU编译器开发中的核心挑战与实战经验,通过具体代码示例展示了关键实现技术: 指令生成:必须考虑硬件特性(如地址对齐)和芯片配置抽象化 图优化:重点处理常见冗余结构(Reshape合并、BN融合),并注意数值稳定性 算子拆分:采用分块计算策略适配有限SRAM,需特别注意边界条件处理 内存分配:基于张量使用频率的贪心算法优化SRAM使用效率 文中包含多个真实踩坑案例: DMA地址未对齐导致硬件错误 BN融合时的除零风险 tile边界处理不当引起的精度下降 这些经验为开

m0_50546716的博客 85

一文掌握Qwen系列:大模型学习总结与核心能力解析

Qwen系列(阿里达摩院)包括多个子模型如 Qwen-Chat、Qwen-VL、Qwen-Coder,它们虽然基于类似的 Transformer 架构,但在 模型结构、预训练任务和输入输出格式等方面存在本质区别,不仅仅是应用场景不同。

2401_85154887的博客 1336

人工智能大语言模型微调技术:SFT 监督微调、LoRA 微调方法、P-tuning v2 微调方法、Freeze 监督微调方法

人工智能大语言模型微调技术:SFT 监督微调、LoRA 微调方法、P-tuning v2 微调方法、Freeze 监督微调方法

丨汀、的博客 4万+

阿里通义千问轻量版:Qwen1.5-0.5B-Chat性能解析

本文介绍了基于星图GPU平台自动化部署🧠 Qwen1.5-0.5B-Chat 轻量级智能对话服务的技术方案。该平台支持一键拉取镜像并快速构建本地化AI应用,适用于模型微调、私有化问答系统及边缘设备部署等场景,兼顾低资源消耗与高效推理,助力开发者轻松实现轻量级大模型的落地应用。

weixin_30951515的博客 422

假人有限元模型

假人模型,车辆碰撞假人有限元模型,适合做乘员安全的研究者利用

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

轻量级对话模型Qwen1.5-0.5B-Chat技术深度解析

本文介绍了基于星图GPU平台自动化部署🧠 Qwen1.5-0.5B-Chat 轻量级智能对话服务的技术实践,该镜像专为低资源环境优化,适用于模型微调、AI客服开发等场景,结合ModelScope生态实现高效推理与快速原型验证。

weixin_28922227的博客 813

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

Qwen1.5-0.5B-Chat模型压缩技术:轻量化实现原理

本文介绍了基于星图GPU平台自动化部署🧠 Qwen1.5-0.5B-Chat 轻量级智能对话服务的技术实践,结合模型压缩与CPU优化策略,实现低资源消耗的高效推理,适用于AI应用开发、模型微调及轻量级智能客服等场景,助力开发者快速构建可落地的轻量化对话系统。

weixin_32005771的博客 926

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

EVA-01入门必看:Qwen2.5-VL-7B与Qwen-VL-Chat的区别及EVA-01选型依据

本文介绍了如何在星图GPU平台上自动化部署🟣 EVA-01: VISUAL NEURAL SYNC SYSTEM镜像,快速搭建一个深度视觉交互终端。该镜像基于Qwen2.5-VL-7B多模态大模型,能够精准理解图片内容、分析图表数据并回答复杂问题,典型应用于智能分析设计图纸、解读复杂图表等场景,实现高效的视觉信息处理。

GreyWolf12的博客 897

Qwen2.5-1.5B-Instruct-ptpc-Quark-ts:阿里云开源的高效1.5B参数大语言模型全面解析

在人工智能快速发展的今天,阿里云推出的Qwen2.5-1.5B-Instruct-ptpc-Quark-ts模型为开发者和研究者提供了一个轻量级但功能强大的大语言模型解决方案。这款仅有15亿参数的模型通过先进的量化技术实现了出色的性能与效率平衡,特别适合资源受限的环境和实时应用场景。 ## 🚀 项目概述与核心优势 Qwen2.5-1.5B-Instruct-ptpc-Quark-ts是阿里云

gitblog_01085的博客 1068

阿里云Qwen2.5-14B-Instruct大语言模型完整部署指南:从零开始快速上手

想要快速上手阿里云最新发布的Qwen2.5-14B-Instruct大语言模型吗?作为拥有147亿参数的强大指令微调模型,Qwen2.5-14B-Instruct在多语言理解、代码生成和数学推理方面表现出色。本指南将带你用最简单的方式从零开始部署这个先进的AI助手,解决你在安装和配置过程中遇到的所有问题! ## 项目概述:为什么选择Qwen2.5-14B-Instruct? Qwen2.5-1

gitblog_01170的博客 430

Qwen2.5-14B-Instruct 实战部署与深度配置完整指南

Qwen2.5-14B-Instruct是阿里云推出的147亿参数指令微调大语言模型,具备强大的多语言支持和代码生成能力。本指南将深入解析其架构特性,并提供从基础部署到高级优化的完整实战方案。 ## 核心概念:理解Qwen2.5-14B-Instruct的核心特性 Qwen2.5-14B-Instruct作为新一代指令微调模型,相比前代在知识丰富度、代码能力和数学推理方面有显著提升。该模型基于

gitblog_00075的博客 797

Qwen1.5-14B-Chat模型完整指南:从架构创新到多语言能力突破的终极解析

Qwen1.5-14B-Chat是阿里云推出的140亿参数对话大语言模型,作为Qwen2的测试版本,在性能表现和多语言支持方面实现了显著突破。这款先进的AI对话模型基于Transformer架构,集成了多项技术创新,为开发者和企业用户提供了强大的自然语言处理能力。在前100个字内,核心关键词"Qwen1.5-14B-Chat模型"已经自然融入,为SEO优化奠定基础。 ## 🚀 Qwen1.5-

gitblog_01034的博客 418
上一篇: 实现高效机器人执行的多模态大语言模型动态推理
下一篇: 这本大模型书真绝!《自然语言处理新范式:基于预训练模型的方法》真的不要太强(附PDF)
AI_小站
博客等级 码龄3年 6255粉丝 1152原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值