#![cfg(all(
feature = "remote",
feature = "mmap",
feature = "blas",
any(target_os = "macos", target_os = "ios")
))]
mod common;
use cera::FinishReason;
use cera::bundle::BundleRepo;
use cera::engine::{BackendPreference, CeraEngine, EngineConfig};
use cera::session::{GenerateOpts, ModalitySink, SessionConfig};
const EXPECTED: &[u32] = &[
856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856, 856,
];
const PROMPT: &str = "The capital of France is";
const MAX_TOKENS: u32 = 16;
const SEED: u64 = 0;
const CTX: usize = 256;
#[test]
#[ignore = "downloads ~210 MB; set CERA_TEST_DOWNLOAD=1 and pass --ignored"]
fn blas_prefill_matches_aarch64_reference() {
if std::env::var("CERA_TEST_DOWNLOAD").is_err() {
eprintln!("skipping: CERA_TEST_DOWNLOAD not set");
return;
}
let repo = BundleRepo::new(common::download::cache_dir());
let engine = CeraEngine::from_bundle_id(
"LFM2-350M-Extract-GGUF",
"Q4_0",
EngineConfig {
context_size: CTX,
backend: BackendPreference::Cpu,
draft_model: None,
gpu_depthformer: false,
bundle_repo: Some(repo),
},
)
.expect("load engine");
let cfg = SessionConfig {
seed: Some(SEED),
ubatch_size: 0,
..Default::default()
};
let mut session = engine.new_session(cfg).unwrap();
session.append_text(PROMPT).expect("append prompt");
struct Collect(Vec<u32>);
impl ModalitySink for Collect {
fn on_text_tokens(&mut self, t: &[u32]) {
self.0.extend_from_slice(t);
}
fn on_done(&mut self, _reason: FinishReason) {}
}
let mut sink = Collect(Vec::new());
session
.generate(
&GenerateOpts {
max_tokens: MAX_TOKENS,
temperature: 0.0,
top_p: 1.0,
top_k: 1,
flush_every_tokens: 1,
flush_every_ms: 0,
..Default::default()
},
&mut sink,
)
.expect("generate");
let tokens = sink.0;
println!("tokens={tokens:?}");
if EXPECTED.is_empty() {
panic!(
"EXPECTED is empty — first run; capture the printed `tokens=[...]` \
above and paste it into EXPECTED in this file."
);
}
assert_eq!(
tokens, EXPECTED,
"BLAS produced different tokens than the aarch64+blas reference. \
If the LFM2 fixture or greedy constants changed, regenerate \
EXPECTED per the module docstring."
);
}