STRA-338 params e02: MMQ model gate takes LoadedTargetOwners, compare_chunk takes ScalarBaseline
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
//! Private sole new changed-path model gate; actual source identity/load preserved.
|
||||
use super::combined_changed_boundary_proof::rig::{DEVICE_BUDGET, MOE_REFUSAL, Owners, bind_pinned, require_opt_in};
|
||||
use super::*;
|
||||
use crate::qwen_forward::loaded_target_owners::LoadedTargetOwners;
|
||||
use std::{env, panic::resume_unwind};
|
||||
|
||||
fn required_path(name: &str) -> PathBuf {
|
||||
@@ -17,7 +18,9 @@ fn pinned_single_load_resident_mmq_model_numeric() {
|
||||
let device = driver.device(0).expect("prefix CUDA device0 unavailable");
|
||||
let context = Rc::new(device.create_context(DEVICE_BUDGET).expect("bounded prefix Context unavailable"));
|
||||
let mut owners = Owners::load(&binding, context.as_ref(), (MoeWeightCache::new_mmq, MOE_REFUSAL));
|
||||
let numerical = owners.run(&binding, &context, QwenForward::test_mmq_on_loaded);
|
||||
let numerical = owners.run(&binding, &context, |binding, session, output, kar, moe, dense| {
|
||||
QwenForward::test_mmq_on_loaded(LoadedTargetOwners { binding, session, output, kar, moe, dense })
|
||||
});
|
||||
let mut teardown = owners.close(true);
|
||||
teardown.close_context(context);
|
||||
drop((binding, inherited));
|
||||
|
||||
@@ -1,30 +1,17 @@
|
||||
//! Only the explicitly selected new full-model MMQ gate. Old observers unchanged.
|
||||
use super::*;
|
||||
use crate::qwen_forward::loaded_target_owners::LoadedTargetOwners;
|
||||
use crate::qwen_forward::mtp::MtpChunkNumericSnapshot;
|
||||
use crate::qwen_forward::mtp_decode::MtpDecoder;
|
||||
use crate::qwen_forward::session::ResetReplaySnapshot;
|
||||
impl QwenForward {
|
||||
pub(crate) fn test_mmq_on_loaded<'driver>(
|
||||
binding: &ModelBinding,
|
||||
session: &mut QwenSession<'driver>,
|
||||
output: &OutputStage<'_, '_>,
|
||||
kar: &mut KarPleCache<'_>,
|
||||
moe: &mut MoeWeightCache<'driver>,
|
||||
dense: &DenseWeightCache<'_>,
|
||||
) {
|
||||
check_mmq_on_loaded(binding, session, output, kar, moe, dense);
|
||||
pub(crate) fn test_mmq_on_loaded(owners: LoadedTargetOwners<'_, '_, '_, '_, '_, '_>) {
|
||||
check_mmq_on_loaded(owners);
|
||||
}
|
||||
}
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(in crate::qwen_forward) fn check_mmq_on_loaded<'driver>(
|
||||
binding: &ModelBinding,
|
||||
session: &mut QwenSession<'driver>,
|
||||
output: &OutputStage<'_, '_>,
|
||||
kar: &mut KarPleCache<'_>,
|
||||
moe: &mut MoeWeightCache<'driver>,
|
||||
dense: &DenseWeightCache<'_>,
|
||||
) {
|
||||
let mut run = MmqRun::new(binding, session, output, kar, moe, dense);
|
||||
pub(in crate::qwen_forward) fn check_mmq_on_loaded(owners: LoadedTargetOwners<'_, '_, '_, '_, '_, '_>) {
|
||||
let binding = owners.binding;
|
||||
let mut run = MmqRun::new(owners);
|
||||
let fresh = run.session.test_reset_replay_snapshot(binding).expect("fresh snapshot refused");
|
||||
assert!(fresh.has_prefix(0, [-1, -1]), "fresh target required");
|
||||
let mut scalar_draft = MtpDecoder::new(binding).expect("baseline draft refused");
|
||||
@@ -38,7 +25,8 @@ pub(in crate::qwen_forward) fn check_mmq_on_loaded<'driver>(
|
||||
run.mtp_row_cancel(&mut candidate_draft, &fresh, &fresh_draft);
|
||||
let chunk = run.candidate_chunk(&mut candidate_draft);
|
||||
let head_exact = run.compare_head(&baseline, &chunk);
|
||||
let exact = run.compare_chunk(&baseline, &baseline_streams, &chunk, &candidate_draft, head_exact);
|
||||
let scalar_baseline = ScalarBaseline { observation: &baseline, streams: &baseline_streams };
|
||||
let exact = run.compare_chunk(scalar_baseline, &chunk, &candidate_draft, head_exact);
|
||||
let continued_exact = run.candidate_continuation(&mut candidate_draft, &chunk, &continued, &exact);
|
||||
let continued_draft_exact = candidate_draft.test_chunk_eq(&continued.draft);
|
||||
run.output.test_reset_replay_record(false).expect("head observer did not drain");
|
||||
@@ -87,6 +75,13 @@ pub(super) struct ChunkExact {
|
||||
pub(super) draft: bool,
|
||||
}
|
||||
|
||||
/// The scalar target step the candidate chunk is compared with: its observation and residual stream words.
|
||||
#[derive(Clone, Copy)]
|
||||
struct ScalarBaseline<'a> {
|
||||
observation: &'a Observation,
|
||||
streams: &'a [u32],
|
||||
}
|
||||
|
||||
/// Exactness flags of the continuation step.
|
||||
struct ContinuedExact {
|
||||
head: bool,
|
||||
@@ -94,14 +89,8 @@ struct ContinuedExact {
|
||||
}
|
||||
|
||||
impl<'a, 'driver, 'o, 'p, 'k, 'd> MmqRun<'a, 'driver, 'o, 'p, 'k, 'd> {
|
||||
pub(super) fn new(
|
||||
binding: &'a ModelBinding,
|
||||
session: &'a mut QwenSession<'driver>,
|
||||
output: &'a OutputStage<'o, 'p>,
|
||||
kar: &'a mut KarPleCache<'k>,
|
||||
moe: &'a mut MoeWeightCache<'driver>,
|
||||
dense: &'a DenseWeightCache<'d>,
|
||||
) -> Self {
|
||||
pub(super) fn new(owners: LoadedTargetOwners<'a, 'driver, 'o, 'p, 'k, 'd>) -> Self {
|
||||
let LoadedTargetOwners { binding, session, output, kar, moe, dense } = owners;
|
||||
let vocab = Dimension::new(248320).expect("vocabulary refused");
|
||||
let ids: Vec<_> =
|
||||
[0, 1, 0, 1].into_iter().map(|n| TokenId::new(n, vocab).expect("fixed token refused")).collect();
|
||||
@@ -307,12 +296,12 @@ impl MmqRun<'_, '_, '_, '_, '_, '_> {
|
||||
}
|
||||
fn compare_chunk(
|
||||
&mut self,
|
||||
baseline: &Observation,
|
||||
baseline_streams: &[u32],
|
||||
scalar_baseline: ScalarBaseline<'_>,
|
||||
chunk: &ChunkRun,
|
||||
candidate_draft: &MtpDecoder,
|
||||
head: bool,
|
||||
) -> ChunkExact {
|
||||
let ScalarBaseline { observation: baseline, streams: baseline_streams } = scalar_baseline;
|
||||
let predicted = chunk.product.predicted(self.session).expect("chunk current origin invalid");
|
||||
assert_eq!(baseline.greedy, predicted, "greedy mismatch");
|
||||
let actual_streams =
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
//! Separate native-certified activation model observer. Original failed observer unchanged.
|
||||
use super::mmq_evaluation::{ChunkExact, ChunkRun, MmqRun, Observation, pos};
|
||||
use super::*;
|
||||
use crate::qwen_forward::loaded_target_owners::LoadedTargetOwners;
|
||||
use crate::qwen_forward::mtp_decode::MtpDecoder;
|
||||
|
||||
#[derive(Debug)]
|
||||
@@ -64,7 +65,7 @@ pub(in crate::qwen_forward) fn check_native_mmq_on_loaded<'driver>(
|
||||
moe: &mut MoeWeightCache<'driver>,
|
||||
dense: &DenseWeightCache<'_>,
|
||||
) -> NativeMmqReport {
|
||||
let mut run = MmqRun::new(binding, session, output, kar, moe, dense);
|
||||
let mut run = MmqRun::new(LoadedTargetOwners { binding, session, output, kar, moe, dense });
|
||||
let fresh = run.session.test_reset_replay_snapshot(binding).expect("fresh snapshot refused");
|
||||
assert!(fresh.has_prefix(0, [-1, -1]), "fresh target required");
|
||||
let mut scalar_draft = MtpDecoder::new(binding).expect("baseline draft refused");
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
//! The freshly loaded target model and its device caches, as one value a `test_*_on_loaded` GPU phase receives.
|
||||
use super::{
|
||||
dense_weight_cache::DenseWeightCache, kar_ple_cache::KarPleCache, moe_weight_cache::MoeWeightCache,
|
||||
output::OutputStage, session::QwenSession,
|
||||
};
|
||||
use crate::model_binding::qwen4exp_input::ModelBinding;
|
||||
|
||||
/// The loaded target model and every cache one on-loaded observation borrows; it exists so a phase takes one
|
||||
/// argument instead of six owners that always travel together.
|
||||
pub(crate) struct LoadedTargetOwners<'a, 'driver, 'o, 'p, 'k, 'd> {
|
||||
pub(crate) binding: &'a ModelBinding,
|
||||
pub(crate) session: &'a mut QwenSession<'driver>,
|
||||
pub(crate) output: &'a OutputStage<'o, 'p>,
|
||||
pub(crate) kar: &'a mut KarPleCache<'k>,
|
||||
pub(crate) moe: &'a mut MoeWeightCache<'driver>,
|
||||
pub(crate) dense: &'a DenseWeightCache<'d>,
|
||||
}
|
||||
@@ -11,6 +11,8 @@ pub(crate) mod kar_ple_cache;
|
||||
pub(crate) mod moe_expert;
|
||||
pub(crate) mod moe_route;
|
||||
// Original Strata prefill MoE router + shared expert over a whole micro-window of genuine FFN reads.
|
||||
#[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
|
||||
pub(crate) mod loaded_target_owners;
|
||||
#[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
|
||||
mod moe_prefill_batch;
|
||||
pub(crate) mod moe_weight_cache;
|
||||
|
||||
Reference in New Issue
Block a user