MCPcopy Create free account
hub / github.com/evilsocket/cake / forward

Method forward

cake-core/src/models/common/mlp.rs:21–31  ·  view source on GitHub ↗

Execute MLP(x).

(&self, x: &Tensor)

Source from the content-addressed store, hash-verified

19impl 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> {

Callers

nothing calls this directly

Calls 3

linear_forwardMethod · 0.45
geluMethod · 0.45
silu_mulMethod · 0.45

Tested by

no test coverage detected