1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#![cfg(all(feature = "metal", target_os = "macos"))]
/// Check depthformer sensitivity: feed cera's frame 1 embedding and ref's frame 1
/// embedding, compare cb2 logits to see why argmax flips.
#[test]
fn depthformer_cb2_sensitivity() {
let vocoder_path = std::path::PathBuf::from(std::env::var("HOME").expect("HOME not set"))
.join(".leap/models/LFM2.5-Audio-1.5B-Q4_0/vocoder-LFM2.5-Audio-1.5B-Q4_0.gguf");
let cera_emb_path = std::path::Path::new("/tmp/cera_frame1_emb.bin");
let ref_emb_path = std::path::Path::new("/tmp/ref_frame1_emb.bin");
if !vocoder_path.exists() || !cera_emb_path.exists() || !ref_emb_path.exists() {
eprintln!("Skipping: files not found");
return;
}
let load_emb = |path: &std::path::Path| -> Vec<f32> {
std::fs::read(path)
.unwrap()
.as_chunks::<4>()
.0
.iter()
.map(|c| f32::from_le_bytes(*c))
.collect()
};
let cera_emb = load_emb(cera_emb_path);
let ref_emb = load_emb(ref_emb_path);
let voc_gguf = cera::gguf::GgufFile::open_arc(&vocoder_path).unwrap();
let dw = cera::model::audio_decoder::AudioDecoderWeights::from_gguf(&voc_gguf).unwrap();
// Both should produce frame 1 codes [127, 1470, 457, 1422, 481, 1509, 976, 2008]
// Frame 2 codes diverge at cb2: cera=1697, ref=1400
// Run depthformer for frame 1 (to populate KV cache), then frame 2
for (label, emb) in [("cera", &cera_emb), ("ref", &ref_emb)] {
let mut df_state =
cera::model::audio_decoder::DepthformerState::new(&dw.depthformer_config);
// Frame 1 codes (both produce the same)
let codes1 =
cera::model::audio_decoder::sample_audio_frame(&dw, &mut df_state, emb, 0.0, 1);
eprintln!("{label} frame 1: {codes1:?}");
// Now feed the frame 1 codes through embed_audio_token and run depthformer for frame 2
// Actually, sample_audio_frame already ran the depthformer for 8 codebooks.
// For frame 2, we need a NEW embedding (from the LLM feedback). But we don't
// have the frame 2 embedding from ggml.
//
// Instead, let's just check: do both embeddings produce the same frame 1 codes?
}
// More detailed: manually run the depthformer for codebook 2 of frame 2
// This requires the frame 2 embedding, which we don't have.
// Instead, run frame 1 with both embeddings and compare frame 1's cb2 logits margin.
for (label, emb) in [("cera", &cera_emb), ("ref", &ref_emb)] {
let mut df_state =
cera::model::audio_decoder::DepthformerState::new(&dw.depthformer_config);
let codes = cera::model::audio_decoder::sample_audio_frame(&dw, &mut df_state, emb, 0.0, 1);
eprintln!("{label} frame 1 codes: {codes:?}");
// Check if frame 1 codes match between cera and ref embeddings
}
}