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

Method forward_with_cache

cake-core/src/models/common/transformer.rs:49–68  ·  view source on GitHub ↗

Forward pass with external cache (for VibeVoice TTS).

(
        &self,
        x: &Tensor,
        index_pos: usize,
        block_idx: usize,
        cache: &mut super::Cache,
    )

Source from the content-addressed store, hash-verified

47
48 /// Forward pass with external cache (for VibeVoice TTS).
49 pub fn forward_with_cache(
50 &self,
51 x: &Tensor,
52 index_pos: usize,
53 block_idx: usize,
54 cache: &mut super::Cache,
55 ) -> anyhow::Result<Tensor> {
56 let residual = x;
57 let h = self.backend.rms_norm(x, &self.rms_1_weight, self.rms_eps)
58 .map_err(|e| anyhow!("rms_1: {e}"))?;
59 let h = (self.attn.forward(&h, index_pos, block_idx, cache)
60 .map_err(|e| anyhow!("attn: {e}"))? + residual)
61 .map_err(|e| anyhow!("residual: {e}"))?;
62 let residual = &h;
63 let h = self.backend.rms_norm(&h, &self.rms_2_weight, self.rms_eps)
64 .map_err(|e| anyhow!("rms_2: {e}"))?;
65 let h = (self.mlp.forward(&h).map_err(|e| anyhow!("mlp: {e}"))? + residual)
66 .map_err(|e| anyhow!("mlp_residual: {e}"))?;
67 Ok(h)
68 }
69}
70
71impl std::fmt::Display for Transformer {

Calls 2

rms_normMethod · 0.45
forwardMethod · 0.45