Match Qwen compiled verification gate math
This commit is contained in:
1 parent
892f8a70b9
commit
57b8ac28a7
33 files changed
+1250
-40
No files matched your search
@@ -30,6 +30,8 @@ struct Manifest {
|
||||
identity: Identity,
|
||||
tag: [u8; 32],
|
||||
#[serde(default)]
|
||||
verify_gate: bool,
|
||||
#[serde(default)]
|
||||
images: Vec<crate::engine::qwen_vision::Identity>,
|
||||
tokens: Vec<i32>,
|
||||
lazy_kv: bool,
|
||||
@@ -116,6 +118,7 @@ impl LiveSession {
|
||||
check_abort(&abort)?;
|
||||
let offset = file.stream_position().map_err(|e| e.to_string())?;
|
||||
let manifest = serde_json::to_vec(&Manifest {
|
||||
verify_gate: true,
|
||||
identity,
|
||||
tag,
|
||||
images: self.current_images.clone(),
|
||||
@@ -185,6 +188,11 @@ impl LiveSession {
|
||||
if !crate::engine::qwen_vision::compatible(&manifest.images) {
|
||||
return Err("Qwen vision cache policy differs; rebuild the cache".into());
|
||||
}
|
||||
if identity.mtp && !manifest.verify_gate {
|
||||
return Err(
|
||||
"Qwen checkpoint uses obsolete MTP attention-gate math; rebuild the cache".into(),
|
||||
);
|
||||
}
|
||||
if !manifest.payload["mtp_history_snapshot"].is_null() != identity.mtp {
|
||||
return Err("Qwen checkpoint MTP payload differs".into());
|
||||
}
|
||||
@@ -433,7 +441,46 @@ fn qwen_checkpoint_roundtrip_and_failed_restore_preserve_live_state() {
|
||||
}
|
||||
assert_eq!(live.tag, [9; 32]);
|
||||
assert_eq!(fingerprint(&live), original);
|
||||
// Files predating the verify-phase law lack this field. Only MTP state
|
||||
// changed numerically; old AR files must remain exactly restorable.
|
||||
let without_gate_policy = |bytes: &[u8]| {
|
||||
let offset = u64::from_le_bytes(bytes[8..16].try_into().unwrap()) as usize;
|
||||
let mut manifest: serde_json::Value = serde_json::from_slice(&bytes[offset..]).unwrap();
|
||||
manifest.as_object_mut().unwrap().remove("verify_gate");
|
||||
let mut result = bytes[..offset].to_vec();
|
||||
result.extend(serde_json::to_vec(&manifest).unwrap());
|
||||
result
|
||||
};
|
||||
fs::write(&broken, without_gate_policy(&valid)).unwrap();
|
||||
assert!(
|
||||
live.load_checkpoint(&broken, identity, &streams, stream, |_| {}, || false)
|
||||
.unwrap_err()
|
||||
.contains("obsolete MTP attention-gate")
|
||||
);
|
||||
assert_eq!(fingerprint(&live), original);
|
||||
live.current.as_mut().unwrap().mtp = None;
|
||||
let ar_identity = Identity {
|
||||
mtp: false,
|
||||
..identity
|
||||
};
|
||||
let ar_original = fingerprint(&live);
|
||||
live.save_checkpoint(
|
||||
&path,
|
||||
ar_identity,
|
||||
[10; 32],
|
||||
&streams,
|
||||
stream,
|
||||
|_| {},
|
||||
|| false,
|
||||
)
|
||||
.unwrap();
|
||||
fs::write(&broken, without_gate_policy(&fs::read(&path).unwrap())).unwrap();
|
||||
assert!(
|
||||
live.load_checkpoint(&broken, ar_identity, &streams, stream, |_| {}, || false)
|
||||
.unwrap()
|
||||
);
|
||||
assert_eq!(fingerprint(&live), ar_original);
|
||||
println!(
|
||||
"Qwen checkpoint: exact payload roundtrip, interrupted save, incompatible/corrupt restore passed"
|
||||
"Qwen checkpoint: exact roundtrip, cancellation/corruption controls, old MTP rejected and old AR restored"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user