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

Method causal_trim

cake-core/src/models/vibevoice/vae_decoder.rs:384–394  ·  view source on GitHub ↗

Trim causal ConvTranspose1d output to remove extra samples. ConvTranspose1d with kernel=2*stride, stride=S, padding=0 produces: out_len = (in_len - 1) * stride + kernel = in_len * stride + stride We want: in_len * stride, so trim `stride` from the right.

(x: &Tensor, trim: usize)

Source from the content-addressed store, hash-verified

382 /// out_len = (in_len - 1) * stride + kernel = in_len * stride + stride
383 /// We want: in_len * stride, so trim `stride` from the right.
384 fn causal_trim(x: &Tensor, trim: usize) -> Result<Tensor> {
385 if trim == 0 {
386 return Ok(x.clone());
387 }
388 let len = x.dim(2)?;
389 if len > trim {
390 x.narrow(2, 0, len - trim)
391 } else {
392 Ok(x.clone())
393 }
394 }
395
396 /// Decode acoustic latents to audio waveform.
397 /// Input: (batch, vae_dim, frames) or (batch, frames, vae_dim)

Callers

nothing calls this directly

Calls 1

cloneMethod · 0.45

Tested by

no test coverage detected