STRA-338 params r02: MTP draft round passes DraftTarget, AcceptedWindow, RepeatRowWindow, DraftSampling, DraftOutput
OriginalMtpActor::draft_from_verifier/launch_draft_from_verifier/draft_first_from_verifier/draft/draft_first and OriginalMtpDrafter::draft_public/draft_first_public take the new draft-round DTOs (original_mtp_draft_round.rs) instead of eight to twelve positional arguments; the engine adapter and the preflight probe build them at the call. Files: crates/engine-qwen35-cuda/src/qwen_forward/original_mtp_verified_adapter.rs crates/engine-qwen35-cuda/src/qwen_forward/original_mtp_verified_adapter/impl_originalpromptexecutor.rs
This commit is contained in:
@@ -71,6 +71,8 @@ mod original_mtp_bank;
|
||||
mod original_mtp_coupled;
|
||||
#[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))]
|
||||
mod original_mtp_draft_head;
|
||||
#[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))]
|
||||
mod original_mtp_draft_round;
|
||||
mod original_mtp_draft_vocab;
|
||||
mod original_mtp_rt;
|
||||
mod original_session_state;
|
||||
|
||||
@@ -20,9 +20,9 @@ use crate::original_mtp_coupled::{
|
||||
use crate::original_mtp_draft_head::OriginalMtpDraftHead;
|
||||
use crate::original_mtp_loader::{CoupledPlan, KvPlan, OriginalMtpLoadPlan};
|
||||
use crate::{
|
||||
CompletedOriginalMtpDraft, Context, Error, MtpInt8Snapshot, MtpOriginalInt8, NativeHeadSelection,
|
||||
OriginalMtpDrafter, OriginalMtpFullPolicy, OriginalMtpRetainedFullWeights, OriginalVerifyWindow, Result,
|
||||
SamplerParams,
|
||||
AcceptedWindow, CompletedOriginalMtpDraft, Context, DraftOutput, DraftSampling, DraftTarget, Error,
|
||||
MtpInt8Snapshot, MtpOriginalInt8, OriginalMtpDrafter, OriginalMtpFullPolicy, OriginalMtpRetainedFullWeights,
|
||||
RepeatRowWindow, Result, SamplerParams,
|
||||
};
|
||||
use std::rc::Rc;
|
||||
|
||||
|
||||
+24
-67
@@ -10,20 +10,17 @@ impl<'ctx> OriginalMtpActor<'ctx> {
|
||||
|
||||
/// `draft(T, tokens, p, a, drafts, ...)` over a completed verifier window.
|
||||
/// `max_drafts` and the coupled request come from this actor's settings.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn draft_from_verifier(
|
||||
&mut self,
|
||||
ring: &mut MtpOriginalInt8<'ctx>,
|
||||
prior: &MtpInt8Snapshot,
|
||||
window: OriginalVerifyWindow<'ctx>,
|
||||
selection: NativeHeadSelection,
|
||||
accepted_row: usize,
|
||||
target: DraftTarget<'_, 'ctx>,
|
||||
window: AcceptedWindow<'ctx>,
|
||||
min_probability: f32,
|
||||
policy: &OriginalMtpFullPolicy,
|
||||
) -> Result<CompletedOriginalMtpDraft<'ctx>> {
|
||||
let staged = self.staged_coupled();
|
||||
let coupled = staged.as_ref().map(|(p, h)| (*p, &**h));
|
||||
let max_drafts = self.settings.max_drafts();
|
||||
let DraftTarget { ring, prior, policy } = target;
|
||||
let AcceptedWindow { window, selection, accepted_row } = window;
|
||||
self.drafter.as_mut().ok_or(Error::ContextPoisoned)?.draft_from_verifier(
|
||||
ring,
|
||||
prior,
|
||||
@@ -39,21 +36,18 @@ impl<'ctx> OriginalMtpActor<'ctx> {
|
||||
|
||||
/// `draft_from_verifier` split around the host's work (`OriginalMtpDrafter::launch_from_verifier`); `after` is the
|
||||
/// verifier's pending commit event.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn launch_draft_from_verifier(
|
||||
&mut self,
|
||||
ring: &mut MtpOriginalInt8<'ctx>,
|
||||
prior: &MtpInt8Snapshot,
|
||||
window: OriginalVerifyWindow<'ctx>,
|
||||
selection: NativeHeadSelection,
|
||||
accepted_row: usize,
|
||||
target: DraftTarget<'_, 'ctx>,
|
||||
window: AcceptedWindow<'ctx>,
|
||||
min_probability: f32,
|
||||
policy: &OriginalMtpFullPolicy,
|
||||
after: Option<&mut crate::OriginalGpuEvent<'ctx>>,
|
||||
) -> Result<()> {
|
||||
let staged = self.staged_coupled();
|
||||
let coupled = staged.as_ref().map(|(p, h)| (*p, &**h));
|
||||
let max_drafts = self.settings.max_drafts();
|
||||
let DraftTarget { ring, prior, policy } = target;
|
||||
let AcceptedWindow { window, selection, accepted_row } = window;
|
||||
self.drafter.as_mut().ok_or(Error::ContextPoisoned)?.launch_from_verifier(
|
||||
ring,
|
||||
prior,
|
||||
@@ -78,20 +72,17 @@ impl<'ctx> OriginalMtpActor<'ctx> {
|
||||
}
|
||||
|
||||
/// `draft_first(T, R_row, token, cell, ...)`: the Original repeat-row path.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn draft_first_from_verifier(
|
||||
&mut self,
|
||||
ring: &mut MtpOriginalInt8<'ctx>,
|
||||
prior: &MtpInt8Snapshot,
|
||||
window: OriginalVerifyWindow<'ctx>,
|
||||
selection: NativeHeadSelection,
|
||||
rows: usize,
|
||||
target: DraftTarget<'_, 'ctx>,
|
||||
window: RepeatRowWindow<'ctx>,
|
||||
min_probability: f32,
|
||||
policy: &OriginalMtpFullPolicy,
|
||||
) -> Result<CompletedOriginalMtpDraft<'ctx>> {
|
||||
let staged = self.staged_coupled();
|
||||
let coupled = staged.as_ref().map(|(p, h)| (*p, &**h));
|
||||
let max_drafts = self.settings.max_drafts();
|
||||
let DraftTarget { ring, prior, policy } = target;
|
||||
let RepeatRowWindow { window, selection, rows } = window;
|
||||
self.drafter.as_mut().ok_or(Error::ContextPoisoned)?.draft_first_from_verifier(
|
||||
ring,
|
||||
prior,
|
||||
@@ -106,67 +97,33 @@ impl<'ctx> OriginalMtpActor<'ctx> {
|
||||
}
|
||||
|
||||
/// Public array form of `draft` (`drafts`/`probs` out-arguments).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn draft(
|
||||
&mut self,
|
||||
ring: &mut MtpOriginalInt8<'ctx>,
|
||||
prior: &MtpInt8Snapshot,
|
||||
window: OriginalVerifyWindow<'ctx>,
|
||||
selection: NativeHeadSelection,
|
||||
accepted_row: usize,
|
||||
target: DraftTarget<'_, 'ctx>,
|
||||
window: AcceptedWindow<'ctx>,
|
||||
min_probability: f32,
|
||||
policy: &OriginalMtpFullPolicy,
|
||||
drafts: &mut [i32],
|
||||
probabilities: Option<&mut [f32]>,
|
||||
output: DraftOutput<'_>,
|
||||
) -> Result<CompletedOriginalMtpDraft<'ctx>> {
|
||||
let staged = self.staged_coupled();
|
||||
let coupled = staged.as_ref().map(|(p, h)| (*p, &**h));
|
||||
let settings = self.settings;
|
||||
self.drafter.as_mut().ok_or(Error::ContextPoisoned)?.draft_public(
|
||||
ring,
|
||||
prior,
|
||||
window,
|
||||
selection,
|
||||
accepted_row,
|
||||
&settings,
|
||||
min_probability,
|
||||
policy,
|
||||
coupled,
|
||||
drafts,
|
||||
probabilities,
|
||||
)
|
||||
let max_drafts = self.settings.max_drafts();
|
||||
let sampling = DraftSampling { min_probability, max_drafts, coupled };
|
||||
self.drafter.as_mut().ok_or(Error::ContextPoisoned)?.draft_public(target, window, sampling, output)
|
||||
}
|
||||
|
||||
/// Public array form of `draft_first`.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn draft_first(
|
||||
&mut self,
|
||||
ring: &mut MtpOriginalInt8<'ctx>,
|
||||
prior: &MtpInt8Snapshot,
|
||||
window: OriginalVerifyWindow<'ctx>,
|
||||
selection: NativeHeadSelection,
|
||||
rows: usize,
|
||||
target: DraftTarget<'_, 'ctx>,
|
||||
window: RepeatRowWindow<'ctx>,
|
||||
min_probability: f32,
|
||||
policy: &OriginalMtpFullPolicy,
|
||||
drafts: &mut [i32],
|
||||
probabilities: Option<&mut [f32]>,
|
||||
output: DraftOutput<'_>,
|
||||
) -> Result<CompletedOriginalMtpDraft<'ctx>> {
|
||||
let staged = self.staged_coupled();
|
||||
let coupled = staged.as_ref().map(|(p, h)| (*p, &**h));
|
||||
let settings = self.settings;
|
||||
self.drafter.as_mut().ok_or(Error::ContextPoisoned)?.draft_first_public(
|
||||
ring,
|
||||
prior,
|
||||
window,
|
||||
selection,
|
||||
rows,
|
||||
&settings,
|
||||
min_probability,
|
||||
policy,
|
||||
coupled,
|
||||
drafts,
|
||||
probabilities,
|
||||
)
|
||||
let max_drafts = self.settings.max_drafts();
|
||||
let sampling = DraftSampling { min_probability, max_drafts, coupled };
|
||||
self.drafter.as_mut().ok_or(Error::ContextPoisoned)?.draft_first_public(target, window, sampling, output)
|
||||
}
|
||||
|
||||
/// `~MtpDrafter()`: stream drain, graphs and owners via the drafter's
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
//! The inputs of one MTP draft round (STRA-338): the ring it writes into, the verifier window it continues from, how
|
||||
//! its tokens are chosen and where the public array form puts them. The actor, the drafter and the engine adapters
|
||||
//! pass these instead of a long positional argument list.
|
||||
|
||||
use crate::{
|
||||
MtpInt8Snapshot, MtpOriginalInt8, NativeHeadSelection, OriginalMtpFullPolicy, OriginalVerifyWindow, SamplerParams,
|
||||
};
|
||||
|
||||
/// The draft ring a round writes into, the snapshot of its prior state and the full-forward policy of the round.
|
||||
pub struct DraftTarget<'a, 'ctx> {
|
||||
pub ring: &'a mut MtpOriginalInt8<'ctx>,
|
||||
pub prior: &'a MtpInt8Snapshot,
|
||||
pub policy: &'a OriginalMtpFullPolicy,
|
||||
}
|
||||
|
||||
/// A completed verifier window with the head selection of the same transaction and the last accepted row of the
|
||||
/// window: what a regular round continues from.
|
||||
pub struct AcceptedWindow<'ctx> {
|
||||
pub window: OriginalVerifyWindow<'ctx>,
|
||||
pub selection: NativeHeadSelection,
|
||||
pub accepted_row: usize,
|
||||
}
|
||||
|
||||
/// The single-row verifier window of the final prompt seed and the number of rows `T` the first round repeats it
|
||||
/// for (the Original repeat-row path).
|
||||
pub struct RepeatRowWindow<'ctx> {
|
||||
pub window: OriginalVerifyWindow<'ctx>,
|
||||
pub selection: NativeHeadSelection,
|
||||
pub rows: usize,
|
||||
}
|
||||
|
||||
/// How a round chooses its tokens: the probability floor, the draft cap and the coupled sampling request of the
|
||||
/// actor's settings.
|
||||
pub struct DraftSampling<'a> {
|
||||
pub min_probability: f32,
|
||||
pub max_drafts: i32,
|
||||
pub coupled: Option<(SamplerParams, &'a [i32; 4096])>,
|
||||
}
|
||||
|
||||
/// The caller's output arrays of the public array form: the draft tokens and, when wanted, their probabilities.
|
||||
pub struct DraftOutput<'a> {
|
||||
pub drafts: &'a mut [i32],
|
||||
pub probabilities: Option<&'a mut [f32]>,
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
use crate::{AcceptedWindow, DraftOutput, DraftSampling, DraftTarget, RepeatRowWindow};
|
||||
|
||||
impl<'ctx> OriginalMtpDrafter<'ctx> {
|
||||
pub(crate) fn loaded_max_t(&self) -> Result<usize> {
|
||||
@@ -179,29 +180,25 @@ impl<'ctx> OriginalMtpDrafter<'ctx> {
|
||||
/// Public-array adapter over the genuine existing graph executor. It NEVER
|
||||
/// reads token/probability output before actual graph drain, and retains the
|
||||
/// completed ring/window product in its return value for subsequent replay.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn draft_public(
|
||||
&mut self,
|
||||
ring: &mut MtpOriginalInt8<'ctx>,
|
||||
prior: &MtpInt8Snapshot,
|
||||
window: OriginalVerifyWindow<'ctx>,
|
||||
selection: NativeHeadSelection,
|
||||
accepted_row: usize,
|
||||
settings: &DraftSettings,
|
||||
min_probability: f32,
|
||||
policy: &OriginalMtpFullPolicy,
|
||||
coupled: Option<(SamplerParams, &[i32; 4096])>,
|
||||
drafts: &mut [i32],
|
||||
probabilities: Option<&mut [f32]>,
|
||||
target: DraftTarget<'_, 'ctx>,
|
||||
window: AcceptedWindow<'ctx>,
|
||||
sampling: DraftSampling<'_>,
|
||||
output: DraftOutput<'_>,
|
||||
) -> Result<CompletedOriginalMtpDraft<'ctx>> {
|
||||
let DraftOutput { drafts, probabilities } = output;
|
||||
self.validate_public_output_extent(drafts, probabilities.as_deref())?;
|
||||
let DraftTarget { ring, prior, policy } = target;
|
||||
let AcceptedWindow { window, selection, accepted_row } = window;
|
||||
let DraftSampling { min_probability, max_drafts, coupled } = sampling;
|
||||
let completion = self.draft_from_verifier(
|
||||
ring,
|
||||
prior,
|
||||
window,
|
||||
selection,
|
||||
accepted_row,
|
||||
settings.max_drafts(),
|
||||
max_drafts,
|
||||
min_probability,
|
||||
policy,
|
||||
coupled,
|
||||
@@ -212,29 +209,25 @@ impl<'ctx> OriginalMtpDrafter<'ctx> {
|
||||
/// Existing direct first-round executor makes T real synchronous D2D copies
|
||||
/// of the authentic single-row verifier R, then stages T copies of its real
|
||||
/// matching head token. Caller shape errors are refused BEFORE those copies.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn draft_first_public(
|
||||
&mut self,
|
||||
ring: &mut MtpOriginalInt8<'ctx>,
|
||||
prior: &MtpInt8Snapshot,
|
||||
window: OriginalVerifyWindow<'ctx>,
|
||||
selection: NativeHeadSelection,
|
||||
rows: usize,
|
||||
settings: &DraftSettings,
|
||||
min_probability: f32,
|
||||
policy: &OriginalMtpFullPolicy,
|
||||
coupled: Option<(SamplerParams, &[i32; 4096])>,
|
||||
drafts: &mut [i32],
|
||||
probabilities: Option<&mut [f32]>,
|
||||
target: DraftTarget<'_, 'ctx>,
|
||||
window: RepeatRowWindow<'ctx>,
|
||||
sampling: DraftSampling<'_>,
|
||||
output: DraftOutput<'_>,
|
||||
) -> Result<CompletedOriginalMtpDraft<'ctx>> {
|
||||
self.validate_first_public(drafts, probabilities.as_deref(), rows)?;
|
||||
let DraftOutput { drafts, probabilities } = output;
|
||||
self.validate_first_public(drafts, probabilities.as_deref(), window.rows)?;
|
||||
let DraftTarget { ring, prior, policy } = target;
|
||||
let RepeatRowWindow { window, selection, rows } = window;
|
||||
let DraftSampling { min_probability, max_drafts, coupled } = sampling;
|
||||
let completion = self.draft_first_from_verifier(
|
||||
ring,
|
||||
prior,
|
||||
window,
|
||||
selection,
|
||||
rows,
|
||||
settings.max_drafts(),
|
||||
max_drafts,
|
||||
min_probability,
|
||||
policy,
|
||||
coupled,
|
||||
|
||||
@@ -217,6 +217,8 @@ pub use original_file_expert_source::{
|
||||
pub use original_gpu_schedule::OriginalStreamDrained;
|
||||
pub use original_gpu_schedule::capture_timing as original_capture_timing;
|
||||
#[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))]
|
||||
pub use original_mtp_draft_round::{AcceptedWindow, DraftOutput, DraftSampling, DraftTarget, RepeatRowWindow};
|
||||
#[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))]
|
||||
pub use original_verify::chain::set_down_override as set_chain_down_override;
|
||||
pub use original_verify::sm120::set_overrides as set_sm120_overrides;
|
||||
#[cfg(all(feature = "cuda-driver", any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))]
|
||||
|
||||
+4
-3
@@ -139,10 +139,9 @@ impl<'ctx> Replay<'ctx> {
|
||||
&mut self,
|
||||
mtp: &mut Option<Mtp<'ctx>>,
|
||||
reset_snapshot: &mut Option<MtpInt8Snapshot>,
|
||||
window: (NativeHeadSelection, Option<OriginalVerifyWindow<'ctx>>),
|
||||
(selection, completed): (NativeHeadSelection, Option<OriginalVerifyWindow<'ctx>>),
|
||||
(t, keep): (usize, usize),
|
||||
) {
|
||||
let (selection, completed) = window;
|
||||
let (Some((ring, actor)), Some(done)) = (mtp.as_mut(), completed) else { return };
|
||||
actor.set_prompt_len(1);
|
||||
actor.set_max_drafts(3);
|
||||
@@ -154,7 +153,9 @@ impl<'ctx> Replay<'ctx> {
|
||||
keep - 1,
|
||||
prior.next_position()
|
||||
);
|
||||
let drafted = actor.draft_from_verifier(ring, &prior, done, selection, keep - 1, 0.0, &full_policy());
|
||||
let window = leleka_cuda_driver::AcceptedWindow { window: done, selection, accepted_row: keep - 1 };
|
||||
let target = leleka_cuda_driver::DraftTarget { ring, prior: &prior, policy: &full_policy() };
|
||||
let drafted = actor.draft_from_verifier(target, window, 0.0);
|
||||
if let Some(d) =
|
||||
step!(format!("actor.draft_from_verifier(t={t}, a={}) in {:?}", keep - 1, started.elapsed()), drafted)
|
||||
{
|
||||
|
||||
@@ -10,8 +10,8 @@ use super::{
|
||||
};
|
||||
use crate::model_binding::qwen4exp_input::{BindingIdentity, ModelBinding};
|
||||
use leleka_cuda_driver::{
|
||||
CompletedOriginalMtpDraft, Context, NativeHeadSelection, OriginalGpuEvent, OriginalMtpFullPolicy,
|
||||
OriginalVerifyWindow, SamplerParams,
|
||||
AcceptedWindow, CompletedOriginalMtpDraft, Context, DraftTarget, NativeHeadSelection, OriginalGpuEvent,
|
||||
OriginalMtpFullPolicy, OriginalVerifyWindow, RepeatRowWindow, SamplerParams,
|
||||
};
|
||||
|
||||
/// One completed `Verifier::run` receipt, before the target commit. It owns
|
||||
|
||||
+8
-13
@@ -28,8 +28,9 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
before.validate(session)?;
|
||||
let actor = self.checked_mtp_actor(binding)?;
|
||||
draft.with_mtp_launch_ring(binding, session, &before, &prospective, |ring, prior| {
|
||||
let target = DraftTarget { ring, prior, policy };
|
||||
actor
|
||||
.launch_draft_from_verifier(ring, prior, window, selection, accepted_row, min_p, policy, after)
|
||||
.launch_draft_from_verifier(target, AcceptedWindow { window, selection, accepted_row }, min_p, after)
|
||||
.map_err(driver_error)
|
||||
})?;
|
||||
Ok(OriginalLaunchedMtpDraft { binding: binding.identity(), before, prospective })
|
||||
@@ -111,16 +112,10 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
let actor = self.checked_mtp_actor(binding)?;
|
||||
let completed =
|
||||
draft.with_mtp_transition_ring(binding, session, &receipt.before, &receipt.committed, |ring, prior| {
|
||||
let target = DraftTarget { ring, prior, policy };
|
||||
let (window, selection, accepted_row) = (receipt.window, receipt.selection, receipt.accepted_row);
|
||||
actor
|
||||
.draft_from_verifier(
|
||||
ring,
|
||||
prior,
|
||||
receipt.window,
|
||||
receipt.selection,
|
||||
receipt.accepted_row,
|
||||
min_p,
|
||||
policy,
|
||||
)
|
||||
.draft_from_verifier(target, AcceptedWindow { window, selection, accepted_row }, min_p)
|
||||
.map_err(driver_error)
|
||||
})?;
|
||||
self.publish_draft_receipt(binding, session, draft, (&receipt.before, receipt.committed), completed)
|
||||
@@ -147,9 +142,9 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
let actor = self.checked_mtp_actor(binding)?;
|
||||
let completed =
|
||||
draft.with_mtp_transition_ring(binding, session, &receipt.before, &receipt.committed, |ring, prior| {
|
||||
actor
|
||||
.draft_first_from_verifier(ring, prior, receipt.window, receipt.selection, rows, min_p, policy)
|
||||
.map_err(driver_error)
|
||||
let target = DraftTarget { ring, prior, policy };
|
||||
let window = RepeatRowWindow { window: receipt.window, selection: receipt.selection, rows };
|
||||
actor.draft_first_from_verifier(target, window, min_p).map_err(driver_error)
|
||||
})?;
|
||||
self.publish_draft_receipt(binding, session, draft, (&receipt.before, receipt.committed), completed)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user