//! Existing Generator rejection/rebuild path for a real pre-fix checkpoint. use super::*; use crate::engine::{Generator, metal::Executor}; use crate::settings::{ GenerationPreferences, RuntimePreferences, SpeculativePreferences, effective_settings, }; use std::sync::Arc; #[test] #[ignore = "installed model and actual pre-fix checkpoint; external memory guard required"] fn issue106_product_discards_old_checkpoint_and_recovers_cold() { let root = std::path::PathBuf::from(std::env::var_os("DS4_QWEN38_ARTIFACTS").unwrap()); let old = std::path::PathBuf::from(std::env::var_os("DS4_ISSUE106_BAD_CHECKPOINT").unwrap()); let directory = std::path::PathBuf::from(std::env::var_os("DS4_ISSUE106_DIR").unwrap()).join("product"); std::fs::create_dir_all(&directory).unwrap(); let effective = effective_settings( crate::model::ModelChoice::Qwen38FlashNext, &GenerationPreferences { context_tokens: 4096, max_generated_tokens: 1, temperature: Some(0.6), ..Default::default() }, &RuntimePreferences { speculative: SpeculativePreferences { glm_mtp: true, ..Default::default() }, ..Default::default() }, root.parent().unwrap(), ) .unwrap(); let mut settings = effective.turn; settings.seed = Some(0); settings.kv_cache.min_tokens = 0; let mut generator = Generator::open( &effective.engine, Arc::new(Metrics::new(&directory.join("metrics"))), ) .unwrap(); let path = directory.join("old.bin"); std::fs::copy(&old, &path).unwrap(); let selection = generator.select_checkpoint(&path, |_| true).unwrap(); assert!(!selection.found && selection.incompatible); assert!(!path.exists()); let Executor::QwenMtplx(owner) = &mut generator.executor else { unreachable!() }; assert!(owner.live.current.is_none() && owner.live.prefix.is_none()); let messages = [ChatTurn { user: true, tool: false, system: false, skip_previous_eos: false, reasoning: None, reasoning_complete: true, content: "Say hello.".into(), }]; let mut states = Vec::new(); for target in [&path, &directory.join("fresh.bin")] { let out = generator .generate( target, None, &messages, &settings, &AtomicBool::new(false), |_, _| {}, |_, _, _| {}, |_| {}, ) .unwrap(); assert_eq!(out.cached_tokens, 0); assert_eq!(&std::fs::read(target).unwrap()[..8], b"QWMTKV02"); let Executor::QwenMtplx(owner) = &mut generator.executor else { unreachable!() }; let saved = owner.live.current.as_ref().unwrap(); let mut hashes = Vec::new(); let payload = saved .encode_payload( 256, &owner.execution.streams, owner.execution.stream, |_, bytes| { hashes.push(crate::engine::metal::qwen_mtplx_tests::hex_digest(&bytes)); Ok(()) }, || false, ) .unwrap(); states.push(serde_json::json!({"tokens":saved.token_ids,"payload":payload,"hashes":hashes,"text":out.message.content,"reasoning":out.message.reasoning})); } assert_eq!(states[0], states[1]); println!( "{}", serde_json::json!({"case":"product_checkpoint_recovery","old_removed":true,"cold_tokens":0,"new_magic":"QWMTKV02","fresh_state_equal":true}) ); }