Dense MLP

Up projection

×

Map 7,168 input features to 33,792 features in parallel with the gate.

u=xffnWup{\htmlData{light=u up}{u}}={\htmlData{light=x}{x_{\mathrm{ffn}}}}W_{\mathrm{up}}
in
xffnx_{\mathrm{ffn}} [B batch, 1 position, 7168 d]
out
uu [B batch, 1 position, 33792 d_ff]
Parameters242,221,056

242,221,056 parameters per instance.

ComponentCalculationParameters
Weight matrix7,168 × 33,792242,221,056

This projection has no bias parameter.

The reference module holds the weight output by input, [out, in].

Sources

In codeself.up_proj(x)

Open pinned code ↗

Direct evidence

The dense feed-forward network: down(SiTU(gate x, up x)).

modeling_kimi_linear.py 273–301 ↗ · moonshotai/Kimi-K3 @ f831ab668142

Excerpt
class KimiMLP(nn.Module):
    def __init__(self, config: KimiLinearConfig, hidden_size=None, intermediate_size=None):
        super().__init__()
        self.config = config
        self.hidden_size = config.hidden_size if hidden_size is None else hidden_size
        self.intermediate_size = config.intermediate_size if intermediate_size is None else intermediate_size
        self.gate_proj = nn.Linear(
            self.hidden_size, self.intermediate_size, bias=False)
        self.up_proj = nn.Linear(
            self.hidden_size, self.intermediate_size, bias=False)
        self.down_proj = nn.Linear(
            self.intermediate_size, self.hidden_size, bias=False)
        if config.hidden_act == "situ":
            beta, linear_beta = _get_situ_activation_params(config)
            self.act_fn = SituAndMul(
                beta=beta,
                linear_beta=linear_beta,
            )
        else:
            self.act_fn = ACT2FN[config.hidden_act]

    def forward(self, x):
        if self.config.hidden_act == "situ":
            gate_up = torch.cat([self.gate_proj(x), self.up_proj(x)], dim=-1)
            down_proj = self.down_proj(self.act_fn(gate_up))
        else:
            down_proj = self.down_proj(self.act_fn(
                self.gate_proj(x)) * self.up_proj(x))
        return down_proj