//! End-to-end dense-Granite (`granite` arch) GGUF decode oracle. Ignored by //! default — needs the real ~8 GB Q8_0 checkpoint on disk. //! //! Unlike the safetensors decoders, this exercises the substrate's first //! **GGUF-file** forward ([`jouleclaw_loader_gguf::granite::Granite`]). The //! reference is `llama.cpp`: for the raw prompt "The capital of France is" //! (token ids `[791, 6864, 315, 9822, 374]`, Granite adds no BOS), greedy //! decode yields " Paris" (token id 12366) — confirmed with //! `llama-simple` and `llama-tokenize` on the same file. //! //! Run: `cargo test -p jouleclaw-loader-gguf --release --features rayon \ //! --test real_granite_oracle -- --ignored --nocapture` use jouleclaw_loader_gguf::bpe_tokenizer::BpeTokenizer; use jouleclaw_loader_gguf::granite::Granite; use jouleclaw_loader_gguf::read_gguf_file; const GG: &str = "/Volumes/macos_4TB_external_1/neuronexus_ai/model_library/granite-4.1-8b-gguf/granite-4.1-8b-Q8_0.gguf"; /// "The capital of France is" (raw, no BOS) per `llama-tokenize`. const PROMPT: [u32; 5] = [791, 6864, 315, 9822, 374]; /// " Paris" per `llama-tokenize`; the llama.cpp greedy next token. const PARIS: u32 = 12366; fn argmax(v: &[f32]) -> usize { v.iter() .enumerate() .fold((0usize, f32::NEG_INFINITY), |(bi, bv), (i, &x)| { if x > bv { (i, x) } else { (bi, bv) } }) .0 } #[test] #[ignore] fn real_granite_4_1_predicts_paris() { if !std::path::Path::new(GG).exists() { eprintln!("skip: granite-4.1 GGUF not present"); return; } let m = Granite::load(GG).expect("load granite gguf"); eprintln!( "granite: {} layers, d={}, heads={}/{}, ffn={}, vocab={}, scales(emb={},attn={},res={},logit={})", m.cfg.n_layers, m.cfg.d_model, m.cfg.n_heads, m.cfg.n_kv, m.cfg.ffn, m.cfg.vocab, m.cfg.embedding_scale, m.cfg.attention_scale, m.cfg.residual_scale, m.cfg.logit_scale ); let logits = m.forward(&PROMPT); let got = argmax(&logits); eprintln!("argmax = {got} (expected {PARIS} = ' Paris')"); assert_eq!(got, PARIS as usize, "greedy next token diverges from llama.cpp reference"); } /// Greedy continuation should read as a coherent " Paris..." completion, matching /// llama.cpp's raw greedy ("The capital of France is Paris."). #[test] #[ignore] fn real_granite_4_1_greedy_starts_with_paris() { if !std::path::Path::new(GG).exists() { eprintln!("skip: granite-4.1 GGUF not present"); return; } let m = Granite::load(GG).expect("load granite gguf"); let out = m.generate(&PROMPT, 4); eprintln!("greedy +4 ids = {out:?}"); assert_eq!(out[0], PARIS, "first generated token must be ' Paris'"); } /// Full text-in / text-out through the GGUF-embedded tokenizer: the prompt must /// tokenize to the llama.cpp ids, and greedy decode must read " Paris…". #[test] #[ignore] fn real_granite_4_1_text_roundtrip() { if !std::path::Path::new(GG).exists() { eprintln!("skip: granite-4.1 GGUF not present"); return; } let tok = BpeTokenizer::from_gguf(&read_gguf_file(GG).expect("gguf")).expect("tokenizer"); let ids = tok.encode("The capital of France is"); eprintln!("encode = {ids:?}"); assert_eq!(ids, PROMPT.to_vec(), "tokenization diverges from llama.cpp"); let m = Granite::load(GG).expect("load"); let gen_ids = m.generate(&ids, 4); let text = tok.decode(&gen_ids); eprintln!("generated text = {text:?}"); assert!(text.starts_with(" Paris"), "decode should start with ' Paris', got {text:?}"); }