test(verify): plan layout against the real carve, split-schedule hazards, controller output invariance sweep
PlanLayout was only compared with a copy of its own arithmetic: compare it with OriginalVerifyLayout (plan span, mapped bytes, alignment) for every max_t. Pin the split schedule's hazards for every layer count, and sweep the controller over window shapes, draft noise, confidence floor, suffix lookup, EOS and max_new asserting the emitted text is the greedy continuation and the session equals the consumed tokens. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
9ea61bbba0
commit
894e2f5e21
@@ -253,6 +253,53 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plan_layout_agrees_with_the_real_arena_and_mapped_carve_for_every_max_t() {
|
||||
// not the same arithmetic twice: the real `OriginalVerifyLayout` (arena span, mapped bytes, plan_i32)
|
||||
for max_t in 2..=8usize {
|
||||
let mut g = super::super::kernels::test_geometry();
|
||||
g.max_t = max_t;
|
||||
let layout = super::super::layout::OriginalVerifyLayout::new(g).unwrap();
|
||||
let plan = PlanLayout::new(max_t * g.k);
|
||||
assert_eq!(plan.words, layout.plan_i32, "max_t {max_t}");
|
||||
// two device copies, each `words + 16` int32 apart
|
||||
assert_eq!(layout.span("plan").unwrap().bytes, 2 * plan.device_stride() * 4);
|
||||
// two mapped blocks of `words` int32 plus the 64 spare bytes of Original
|
||||
assert_eq!(layout.mapped_bytes[14], 2 * plan.mapped_stride() * 4 + 64);
|
||||
// the second group's blocks keep the u64 pointer arrays 8-byte aligned
|
||||
assert_eq!((plan.device_stride() * 4) % 8, 0);
|
||||
assert_eq!((plan.mapped_stride() * 4) % 8, 0);
|
||||
assert_eq!(plan.start2 + max_t * g.k + 2, plan.words, "start2 is the last table");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schedule_is_a_valid_stream_order_for_the_split_hazards() {
|
||||
// Every hazard of the overlapped order, for every layer count: a group's pre needs its own previous
|
||||
// post (the residual rows), B's mixer needs A's mixer of the same layer (K/V append, GDN history), and
|
||||
// the doorbell the host serves next is always the one the stream reaches next.
|
||||
for layers in 1..=WINDOW_LAYERS {
|
||||
let s = schedule(2, layers);
|
||||
let at = |phase, layer, group| s.iter().position(|x| *x == Step { phase, layer, group }).unwrap();
|
||||
for l in 0..layers {
|
||||
assert!(at(Phase::Pre, l, 0) < at(Phase::Pre, l, 1));
|
||||
for g in 0..2 {
|
||||
assert!(at(Phase::Pre, l, g) < at(Phase::Post, l, g));
|
||||
if l + 1 < layers {
|
||||
assert!(at(Phase::Post, l, g) < at(Phase::Pre, l + 1, g));
|
||||
// layer l+1 of A may overlap B's experts of layer l, never B's mixer of layer l+1 before A's
|
||||
assert!(at(Phase::Pre, l + 1, 0) < at(Phase::Pre, l + 1, 1));
|
||||
}
|
||||
}
|
||||
// the CPU serves A of layer l while the GPU computes B's mixer of layer l (the point of the split)
|
||||
assert!(at(Phase::Pre, l, 1) < at(Phase::Post, l, 0));
|
||||
}
|
||||
// each pre rings once, in the order the host serves
|
||||
let rings: Vec<u32> = s.iter().filter(|x| x.phase == Phase::Pre).map(|x| ring(x.layer, 2, x.group)).collect();
|
||||
assert_eq!(rings, (1..=2 * layers as u32).collect::<Vec<_>>());
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn staging_is_split_between_the_two_groups() {
|
||||
assert_eq!(staging_blobs_per_group(1), 16);
|
||||
|
||||
@@ -705,6 +705,38 @@ mod tests {
|
||||
assert!(windows.iter().skip(1).any(|&(t,lookup)|lookup&&t>2),"{windows:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn output_is_the_greedy_text_for_every_window_shape_noise_and_stop_rule() {
|
||||
// Output invariance: whatever the window sizes, the draft noise, the confidence floor, the suffix
|
||||
// lookup, EOS and max_new do, the emitted tokens are the greedy continuation (cut at the first EOS or
|
||||
// max_new) and the session ends up holding exactly the consumed tokens.
|
||||
let p=prompt(40);
|
||||
let full=expected(&p,64);
|
||||
let noisy=[None,Some(0),Some(1),Some(2),Some(5)];
|
||||
let probs:[[f32;8];3]=[[0.9;8],[0.9,0.1,0.9,0.9,0.9,0.9,0.9,0.9],[0.02;8]];
|
||||
for max_t in 1..=8usize { for mtp in [0usize,1,2,max_t,9] { for suffix in [0usize,3] {
|
||||
for bad in noisy { for pr in probs { for min_p in [0.0f32,0.5] { for max_new in [0usize,1,3,17] {
|
||||
for eos_at in [None,Some(2usize),Some(9)] {
|
||||
let eos:Vec<i32>=eos_at.map(|i|full[i]).into_iter().collect();
|
||||
let mut e=Fake::new(&p[..p.len()-1]);e.bad_draft=bad;e.probs=pr.to_vec();
|
||||
let mut c=OriginalSpecController::new(SpecConfig::new(max_t,mtp,4096,VOCAB,suffix,false).unwrap()).unwrap();
|
||||
c.begin_request(&p,max_new,min_p,&eos).unwrap();
|
||||
let out=drive(&mut c,&mut e,&mut||false).unwrap();
|
||||
c.finish_request(&mut e).unwrap();
|
||||
let mut want=full[..max_new].to_vec();
|
||||
if let Some(i)=eos_at {if i<max_new {want.truncate(i+1);}}
|
||||
let ctx=format!("max_t {max_t} mtp {mtp} suffix {suffix} bad {bad:?} probs {:?} min_p {min_p} max_new {max_new} eos {eos_at:?}",&pr[..3]);
|
||||
assert_eq!(out,want,"{ctx}");
|
||||
assert_eq!(c.consumed().unwrap(),e.committed.as_slice(),"{ctx}");
|
||||
assert_eq!(e.count("begin_adaptation"),e.count("join_adaptation"),"{ctx}");
|
||||
assert_eq!(e.count("drain_verified"),e.count("verify"),"{ctx}");
|
||||
assert_eq!(e.count("drain_draft"),e.count("seed"),"{ctx}");
|
||||
assert_eq!(e.count("restore_target")+e.count("restore_draft"),0,"{ctx}");
|
||||
}
|
||||
}}}}}}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn draft_first_entry_is_a_separate_literal_path_and_drains() {
|
||||
struct First{log:Vec<&'static str>,fail:bool}
|
||||
|
||||
Reference in New Issue
Block a user