diff --git a/crates/cuda-driver/src/original_verify_window_plan.rs b/crates/cuda-driver/src/original_verify_window_plan.rs index 512d2f5e..7ba91a13 100644 --- a/crates/cuda-driver/src/original_verify_window_plan.rs +++ b/crates/cuda-driver/src/original_verify_window_plan.rs @@ -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 = 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::>()); + } + } + #[test] fn staging_is_split_between_the_two_groups() { assert_eq!(staging_blobs_per_group(1), 16); diff --git a/crates/leleka-runtime/src/qwen_forward/original_spec_controller.rs b/crates/leleka-runtime/src/qwen_forward/original_spec_controller.rs index 19517b26..b719f871 100644 --- a/crates/leleka-runtime/src/qwen_forward/original_spec_controller.rs +++ b/crates/leleka-runtime/src/qwen_forward/original_spec_controller.rs @@ -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=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,fail:bool}