Execute MLP(x).
(&self, x: &Tensor)
| 19 | impl MLP { |
| 20 | /// Execute MLP(x). |
| 21 | pub fn forward(&self, x: &Tensor) -> Result<Tensor> { |
| 22 | let fused = self.backend.linear_forward(x, &self.gate_up_proj_weight, None)?; |
| 23 | let gate = fused.narrow(D::Minus1, 0, self.intermediate_size)?; |
| 24 | let up = fused.narrow(D::Minus1, self.intermediate_size, self.intermediate_size)?; |
| 25 | let x = if self.use_gelu { |
| 26 | (self.backend.gelu(&gate)? * up)? |
| 27 | } else { |
| 28 | self.backend.silu_mul(&gate.contiguous()?, &up.contiguous()?)? |
| 29 | }; |
| 30 | self.backend.linear_forward(&x, &self.down_proj_weight, None) |
| 31 | } |
| 32 | |
| 33 | /// Load this block from the VarBuilder given the specific configuration. |
| 34 | pub fn load(vb: VarBuilder, cfg: &super::Config, backend: Arc<dyn ComputeBackend>) -> Result<Self> { |
nothing calls this directly
no test coverage detected