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

Function test_decoder_block_forward

cake-core/src/models/vibevoice/vae_decoder.rs:528–560  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

526
527 #[test]
528 fn test_decoder_block_forward() {
529 let ch = 32;
530 let mut map = std::collections::HashMap::new();
531 let dev = Device::Cpu;
532
533 fn mt(shape: &[usize], seed: u64) -> Tensor {
534 use rand::{Rng, SeedableRng};
535 let n: usize = shape.iter().product();
536 let mut rng = rand::rngs::StdRng::seed_from_u64(seed);
537 let d: Vec<f32> = (0..n).map(|_| rng.gen_range(-0.01..0.01)).collect();
538 Tensor::from_vec(d, shape, &Device::Cpu).unwrap()
539 }
540
541 map.insert("norm.weight".into(), Tensor::ones(ch, DType::F32, &dev).unwrap());
542 map.insert("gamma".into(), Tensor::ones(ch, DType::F32, &dev).unwrap());
543 map.insert("mixer.conv.conv.conv.weight".into(), mt(&[ch, 1, 7], 1));
544 map.insert("mixer.conv.conv.conv.bias".into(), mt(&[ch], 2));
545 map.insert("ffn_norm.weight".into(), Tensor::ones(ch, DType::F32, &dev).unwrap());
546 map.insert("ffn_gamma".into(), Tensor::ones(ch, DType::F32, &dev).unwrap());
547 map.insert("ffn.linear1.weight".into(), mt(&[ch * 4, ch], 3));
548 map.insert("ffn.linear1.bias".into(), mt(&[ch * 4], 4));
549 map.insert("ffn.linear2.weight".into(), mt(&[ch, ch * 4], 5));
550 map.insert("ffn.linear2.bias".into(), mt(&[ch], 6));
551
552 let vb = VarBuilder::from_tensors(map, DType::F32, &dev);
553 let backend = crate::backends::create_backend(&dev);
554 let block = DecoderBlock::load(vb, ch, 1e-5, backend).unwrap();
555
556 // Input: (batch=1, channels=32, seq=16)
557 let x = mt(&[1, ch, 16], 10);
558 let y = block.forward(&x).unwrap();
559 assert_eq!(y.dims(), &[1, ch, 16]);
560 }
561
562 // --- StreamingConvCache ---
563

Callers

nothing calls this directly

Calls 3

create_backendFunction · 0.85
mtFunction · 0.70
forwardMethod · 0.45

Tested by

no test coverage detected