nano-mlp

nano-vllm/nanovllm/models/qwen3.py · bb823b3 · L91–122 · 固定 commit 上游

这是固定版本源码的只读摘录;可在线阅读,也可通过上游链接查看原文件。

91class Qwen3MLP(nn.Module):
92
93    def __init__(
94        self,
95        hidden_size: int,
96        intermediate_size: int,
97        hidden_act: str,
98    ) -> None:
99        super().__init__()
100        self.gate_up_proj = MergedColumnParallelLinear(
101            hidden_size,
102            [intermediate_size] * 2,
103            bias=False,
104        )
105        self.down_proj = RowParallelLinear(
106            intermediate_size,
107            hidden_size,
108            bias=False,
109        )
110        assert hidden_act == "silu"
111        self.act_fn = SiluAndMul()
112
113    def forward(self, x):
114        gate_up = self.gate_up_proj(x)
115        x = self.act_fn(gate_up)
116        x = self.down_proj(x)
117        return x
118
119
120class Qwen3DecoderLayer(nn.Module):
121
122    def __init__(