STRA-338 params r04: original prompt chain (forward, forward_operation, run_layers .. GdnLayer::compute) takes PromptResources, PromptAdmission, DraftRecording, PromptLayerEnv, PromptSource
Files:
This commit is contained in:
@@ -72,6 +72,35 @@ pub(in crate::qwen_forward) struct OriginalPromptPending<'session, 'program, 'ct
|
||||
draft: &'program mut OriginalDraftSession<'ctx>,
|
||||
draft_checkpoint: OriginalDraftCheckpoint,
|
||||
}
|
||||
/// What one prompt chunk reads and fills outside its transaction: the model binding and dense weights, the KAR PLE
|
||||
/// cache, the MoE weight cache and the prefill arena.
|
||||
pub(in crate::qwen_forward) struct PromptResources<'program, 'stores, 'loan, 'ctx> {
|
||||
pub(in crate::qwen_forward) binding: &'program ModelBinding,
|
||||
pub(in crate::qwen_forward) dense: &'program DenseWeightCache<'ctx>,
|
||||
pub(in crate::qwen_forward) kar: Option<&'stores mut KarPleCache<'ctx>>,
|
||||
pub(in crate::qwen_forward) moe: &'stores mut MoeWeightCache<'ctx>,
|
||||
pub(in crate::qwen_forward) arena: &'stores mut OriginalPrefillArena<'loan, 'ctx>,
|
||||
}
|
||||
/// The session a prompt chunk is admitted into and the rows it takes: the prompt input and how many rows of it.
|
||||
pub(in crate::qwen_forward) struct PromptAdmission<'session, 'source, 'ctx> {
|
||||
pub(in crate::qwen_forward) session: &'session mut QwenSession<'ctx>,
|
||||
pub(in crate::qwen_forward) source: &'source std::rc::Rc<OriginalPromptInput>,
|
||||
pub(in crate::qwen_forward) count: usize,
|
||||
}
|
||||
/// How the draft KV of a chunk is recorded: the draft session, the embedding and scalar policy it uses, and the probe
|
||||
/// that cancels the recording.
|
||||
pub(in crate::qwen_forward) struct DraftRecording<'program, 'inputs, 'ctx, Cancel: FnMut() -> bool> {
|
||||
pub(in crate::qwen_forward) session: &'program mut OriginalDraftSession<'ctx>,
|
||||
pub(in crate::qwen_forward) embedding: &'inputs OriginalPromptEmbedding<'ctx>,
|
||||
pub(in crate::qwen_forward) policy: &'inputs OriginalMtpScalarPolicy,
|
||||
pub(in crate::qwen_forward) cancelled: Cancel,
|
||||
}
|
||||
/// The prompt rows one chunk covers: their tokens, the position of the first and the input they come from.
|
||||
struct PromptWindow<'a> {
|
||||
tokens: &'a [TokenId],
|
||||
first_position: u64,
|
||||
source: &'a std::rc::Rc<OriginalPromptInput>,
|
||||
}
|
||||
/// The three prompt actions the batched path does not own (verifier windows, the final seed, session checkpoints).
|
||||
/// Defaults refuse: those belong to the Original Verifier / serving owner, which hands its own implementation in.
|
||||
pub(in crate::qwen_forward) trait OriginalPromptHooks {
|
||||
|
||||
+15
-14
@@ -60,20 +60,21 @@ impl crate::backend::original_prompt::PromptRunner for OriginalPromptComposer<'_
|
||||
if self.session.target_origin()?.next_position() != action.first as u64 {
|
||||
return Err(Error::IdentityMismatch);
|
||||
}
|
||||
let pending = self.executor.forward(
|
||||
self.binding,
|
||||
self.dense,
|
||||
&mut *self.session,
|
||||
self.source,
|
||||
action.count,
|
||||
self.kar.as_deref_mut(),
|
||||
&mut *self.moe,
|
||||
&mut *self.arena,
|
||||
&mut *self.draft,
|
||||
self.embedding,
|
||||
self.policy,
|
||||
&mut *self.cancel,
|
||||
)?;
|
||||
let resources = PromptResources {
|
||||
binding: self.binding,
|
||||
dense: self.dense,
|
||||
kar: self.kar.as_deref_mut(),
|
||||
moe: &mut *self.moe,
|
||||
arena: &mut *self.arena,
|
||||
};
|
||||
let admission = PromptAdmission { session: &mut *self.session, source: self.source, count: action.count };
|
||||
let recording = DraftRecording {
|
||||
session: &mut *self.draft,
|
||||
embedding: self.embedding,
|
||||
policy: self.policy,
|
||||
cancelled: &mut *self.cancel,
|
||||
};
|
||||
let pending = self.executor.forward(resources, admission, recording)?;
|
||||
self.last_published = Some(pending.publish()?);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
+27
-32
@@ -2,6 +2,7 @@
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
use crate::qwen_forward::prompt_device_rows::PromptLayerEnv;
|
||||
|
||||
#[path = "impl_originalpromptexecutor/forward_draft.rs"]
|
||||
mod forward_draft;
|
||||
@@ -41,35 +42,28 @@ fn trace_error(step: &str, error: Error) -> Error {
|
||||
impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
/// No target position is advanced here. Every read is actual GR arithmetic;
|
||||
/// recurrent/KV/PLE seals belong to the same still-private source transaction.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(in crate::qwen_forward) fn forward<'session, 'program, 'loan>(
|
||||
&'program mut self,
|
||||
binding: &'program ModelBinding,
|
||||
dense: &'program DenseWeightCache<'ctx>,
|
||||
session: &'session mut QwenSession<'ctx>,
|
||||
source: &std::rc::Rc<OriginalPromptInput>,
|
||||
count: usize,
|
||||
kar: Option<&mut KarPleCache<'ctx>>,
|
||||
moe: &mut MoeWeightCache<'ctx>,
|
||||
arena: &mut OriginalPrefillArena<'loan, 'ctx>,
|
||||
draft: &'program mut OriginalDraftSession<'ctx>,
|
||||
embedding: &OriginalPromptEmbedding<'ctx>,
|
||||
policy: &OriginalMtpScalarPolicy,
|
||||
mut cancelled: impl FnMut() -> bool,
|
||||
mut resources: PromptResources<'program, '_, 'loan, 'ctx>,
|
||||
admission: PromptAdmission<'session, '_, 'ctx>,
|
||||
recording: DraftRecording<'program, '_, 'ctx, impl FnMut() -> bool>,
|
||||
) -> Result<OriginalPromptPending<'session, 'program, 'ctx>> {
|
||||
let (tokens, first_position) = self.admit_window(binding, dense, session, source, count, arena.capacity())?;
|
||||
let (binding, dense) = (resources.binding, resources.dense);
|
||||
let PromptAdmission { session, source, count } = admission;
|
||||
let DraftRecording { session: draft, embedding, policy, cancelled } = recording;
|
||||
let arena_capacity = resources.arena.capacity();
|
||||
let (tokens, first_position) = self.admit_window(binding, dense, session, source, count, arena_capacity)?;
|
||||
let _launch_sync = leleka_cuda_driver::PromptSyncTrace::enter();
|
||||
if tokens.is_empty() || tokens.len() > self.capacity || arena.capacity() != self.capacity {
|
||||
if tokens.is_empty() || tokens.len() > self.capacity || arena_capacity != self.capacity {
|
||||
return Err(Error::InvalidDimension);
|
||||
}
|
||||
let checkpoint = session.original_checkpoint(binding)?;
|
||||
let draft_checkpoint = draft.checkpoint(binding, session)?;
|
||||
let mut txn = OriginalPromptTxn::begin(session, binding, source, count)?;
|
||||
let (window, draft_args) = ((tokens, first_position), (&mut *draft, embedding, policy));
|
||||
let owners = (kar, (&mut *moe, arena));
|
||||
let operation =
|
||||
self.forward_operation((binding, dense), &mut txn, (window, source), owners, draft_args, &mut cancelled);
|
||||
self.finish_forward(operation, (binding, dense), (txn, moe), (draft, checkpoint, draft_checkpoint))
|
||||
let window = PromptWindow { tokens, first_position, source };
|
||||
let recording = DraftRecording { session: &mut *draft, embedding, policy, cancelled };
|
||||
let operation = self.forward_operation(&mut resources, &mut txn, window, recording);
|
||||
self.finish_forward(operation, (binding, dense), (txn, resources.moe), (draft, checkpoint, draft_checkpoint))
|
||||
}
|
||||
|
||||
/// The prompt window of the chunk and its first position, after the executor accepted the session.
|
||||
@@ -127,24 +121,25 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
/// the draft KV. Its error is rolled back by `forward`.
|
||||
fn forward_operation<'loan>(
|
||||
&mut self,
|
||||
(binding, dense): (&ModelBinding, &DenseWeightCache<'ctx>),
|
||||
resources: &mut PromptResources<'_, '_, 'loan, 'ctx>,
|
||||
txn: &mut OriginalPromptTxn<'_, 'ctx>,
|
||||
(window, source): ((&[TokenId], u64), &std::rc::Rc<OriginalPromptInput>),
|
||||
(mut kar, (moe, arena)): (
|
||||
Option<&mut KarPleCache<'ctx>>,
|
||||
(&mut MoeWeightCache<'ctx>, &mut OriginalPrefillArena<'loan, 'ctx>),
|
||||
),
|
||||
draft_args: DraftArgs<'_, 'ctx>,
|
||||
cancelled: &mut impl FnMut() -> bool,
|
||||
window: PromptWindow<'_>,
|
||||
recording: DraftRecording<'_, '_, 'ctx, impl FnMut() -> bool>,
|
||||
) -> Result<ForwardDone> {
|
||||
let (binding, dense) = (resources.binding, resources.dense);
|
||||
let (moe, arena) = (&mut *resources.moe, &mut *resources.arena);
|
||||
let DraftRecording { session, embedding, policy, mut cancelled } = recording;
|
||||
// The last prompt seed belongs to Original Verifier. Every row
|
||||
// admitted here must have its authentic next token in the source.
|
||||
txn.known_prompt_next()?.ok_or(Error::IdentityMismatch)?;
|
||||
let (rows, first_predecessors, _staged) =
|
||||
self.stage_prompt_rows((binding, dense), txn, window.0, (&mut kar, arena))?;
|
||||
self.read_ahead_next_chunk(binding, source, window, &mut kar, first_predecessors);
|
||||
let carrier = self.run_layers(binding, dense, moe, txn, Carrier::Plain(rows))?;
|
||||
self.finish_chunk_rows((binding, dense), (moe, txn), carrier, (draft_args, cancelled))
|
||||
self.stage_prompt_rows((binding, dense), txn, window.tokens, (&mut resources.kar, arena))?;
|
||||
let read_ahead = (window.tokens, window.first_position);
|
||||
self.read_ahead_next_chunk(binding, window.source, read_ahead, &mut resources.kar, first_predecessors);
|
||||
let layer_env = PromptLayerEnv { binding, dense, txn: &*txn };
|
||||
let carrier = self.run_layers(layer_env, moe, Carrier::Plain(rows))?;
|
||||
let draft_args = (session, embedding, policy);
|
||||
self.finish_chunk_rows((binding, dense), (moe, txn), carrier, (draft_args, &mut cancelled))
|
||||
}
|
||||
|
||||
/// Stages the inputs of the chunk and initializes its rows on the device; the staged host input is returned
|
||||
|
||||
+20
-35
@@ -4,7 +4,7 @@
|
||||
use super::*;
|
||||
use crate::model_binding::qwen4exp_input::BoundLayer;
|
||||
use crate::qwen_forward::gr::GrRole;
|
||||
use crate::qwen_forward::prompt_device_rows::PromptDeviceRead;
|
||||
use crate::qwen_forward::prompt_device_rows::{PromptDeviceRead, PromptLayerEnv};
|
||||
|
||||
/// One validation of the current row state, timed on its own.
|
||||
fn validated<R>(check: impl FnOnce() -> Result<R>) -> Result<R> {
|
||||
@@ -16,14 +16,12 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
/// Layer-major order: every layer completes all rows of the chunk before the next starts.
|
||||
pub(super) fn run_layers<'w, 'arena, 'loan>(
|
||||
&mut self,
|
||||
binding: &ModelBinding,
|
||||
dense: &'w DenseWeightCache<'ctx>,
|
||||
env: PromptLayerEnv<'_, 'w, '_, 'ctx>,
|
||||
moe: &mut MoeWeightCache<'ctx>,
|
||||
txn: &OriginalPromptTxn<'_, 'ctx>,
|
||||
mut carrier: Carrier<'w, 'arena, 'loan, 'ctx>,
|
||||
) -> Result<Carrier<'w, 'arena, 'loan, 'ctx>> {
|
||||
for layer in binding.ordered_layers() {
|
||||
carrier = self.run_layer(layer, binding, dense, moe, txn, carrier)?;
|
||||
for layer in env.binding.ordered_layers() {
|
||||
carrier = self.run_layer(layer, env, moe, carrier)?;
|
||||
}
|
||||
Ok(carrier)
|
||||
}
|
||||
@@ -31,12 +29,11 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
fn run_layer<'w, 'arena, 'loan>(
|
||||
&mut self,
|
||||
layer: &BoundLayer,
|
||||
binding: &ModelBinding,
|
||||
dense: &'w DenseWeightCache<'ctx>,
|
||||
env: PromptLayerEnv<'_, 'w, '_, 'ctx>,
|
||||
moe: &mut MoeWeightCache<'ctx>,
|
||||
txn: &OriginalPromptTxn<'_, 'ctx>,
|
||||
carrier: Carrier<'w, 'arena, 'loan, 'ctx>,
|
||||
) -> Result<Carrier<'w, 'arena, 'loan, 'ctx>> {
|
||||
let PromptLayerEnv { binding, dense, txn } = env;
|
||||
let index = layer.index();
|
||||
crate::bringup_trace!(
|
||||
"DBG[{:.0}s] forward layer {index} {:?} begin",
|
||||
@@ -47,7 +44,7 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
let mut read = self.read_attention(binding, dense, carrier, index)?;
|
||||
crate::bringup_trace!("DBG[{:.0}s] L{index} attn-read ok", crate::qwen_forward::original_serve_stack::dbg_el());
|
||||
validated(|| read.validate_original_rows(binding, dense))?;
|
||||
let ffn = self.complete_mixer(binding, dense, txn, read, layer)?;
|
||||
let ffn = self.complete_mixer(env, read, layer)?;
|
||||
crate::bringup_trace!("DBG[{:.0}s] L{index} mixer ok", crate::qwen_forward::original_serve_stack::dbg_el());
|
||||
let read = self.read_ffn(binding, dense, ffn, index)?;
|
||||
let carrier = self.complete_moe(binding, dense, moe, read, index)?;
|
||||
@@ -105,9 +102,7 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
/// The token mixer (GDN or QSA) of the layer, fused with the next norm when `fused`.
|
||||
fn complete_mixer<'w, 'arena, 'loan>(
|
||||
&mut self,
|
||||
binding: &ModelBinding,
|
||||
dense: &'w DenseWeightCache<'ctx>,
|
||||
txn: &OriginalPromptTxn<'_, 'ctx>,
|
||||
env: PromptLayerEnv<'_, 'w, '_, 'ctx>,
|
||||
read: PromptDeviceRead<'static, 'arena, 'loan, 'ctx>,
|
||||
layer: &BoundLayer,
|
||||
) -> Result<Carrier<'w, 'arena, 'loan, 'ctx>> {
|
||||
@@ -120,9 +115,9 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
drain,
|
||||
);
|
||||
let ffn = if self.fused {
|
||||
Carrier::Normed(self.mixer_normed(binding, dense, txn, read, layer)?)
|
||||
Carrier::Normed(self.mixer_normed(env, read, layer)?)
|
||||
} else {
|
||||
Carrier::Plain(self.mixer_plain(binding, dense, txn, read, layer)?)
|
||||
Carrier::Plain(self.mixer_plain(env, read, layer)?)
|
||||
};
|
||||
drop(mixer_span);
|
||||
Ok(ffn)
|
||||
@@ -130,21 +125,16 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
|
||||
fn mixer_normed<'w, 'arena, 'loan>(
|
||||
&mut self,
|
||||
binding: &ModelBinding,
|
||||
dense: &'w DenseWeightCache<'ctx>,
|
||||
txn: &OriginalPromptTxn<'_, 'ctx>,
|
||||
env: PromptLayerEnv<'_, 'w, '_, 'ctx>,
|
||||
read: PromptDeviceRead<'static, 'arena, 'loan, 'ctx>,
|
||||
layer: &BoundLayer,
|
||||
) -> Result<PromptDeviceNormedRows<'w, 'static, 'arena, 'loan, 'ctx>> {
|
||||
let prompt = self.prompt.as_mut().ok_or(Error::IdentityMismatch)?;
|
||||
let PromptLayerEnv { binding, dense, txn } = env;
|
||||
match layer.kind() {
|
||||
BoundLayerKind::Gdn => read.complete_original_gdn_normed(
|
||||
binding,
|
||||
dense,
|
||||
txn,
|
||||
prompt,
|
||||
self.gdn.as_mut().ok_or(Error::IdentityMismatch)?,
|
||||
),
|
||||
BoundLayerKind::Gdn => {
|
||||
read.complete_original_gdn_normed(env, prompt, self.gdn.as_mut().ok_or(Error::IdentityMismatch)?)
|
||||
}
|
||||
BoundLayerKind::Qsa => read.complete_original_qsa_normed(
|
||||
binding,
|
||||
dense,
|
||||
@@ -160,21 +150,16 @@ impl<'ctx> OriginalPromptExecutor<'ctx> {
|
||||
|
||||
fn mixer_plain<'arena, 'loan>(
|
||||
&mut self,
|
||||
binding: &ModelBinding,
|
||||
dense: &DenseWeightCache<'ctx>,
|
||||
txn: &OriginalPromptTxn<'_, 'ctx>,
|
||||
env: PromptLayerEnv<'_, '_, '_, 'ctx>,
|
||||
read: PromptDeviceRead<'static, 'arena, 'loan, 'ctx>,
|
||||
layer: &BoundLayer,
|
||||
) -> Result<PromptDeviceRows<'static, 'arena, 'loan, 'ctx>> {
|
||||
let prompt = self.prompt.as_mut().ok_or(Error::IdentityMismatch)?;
|
||||
let PromptLayerEnv { binding, dense, txn } = env;
|
||||
match layer.kind() {
|
||||
BoundLayerKind::Gdn => read.complete_original_gdn(
|
||||
binding,
|
||||
dense,
|
||||
txn,
|
||||
prompt,
|
||||
self.gdn.as_mut().ok_or(Error::IdentityMismatch)?,
|
||||
),
|
||||
BoundLayerKind::Gdn => {
|
||||
read.complete_original_gdn(env, prompt, self.gdn.as_mut().ok_or(Error::IdentityMismatch)?)
|
||||
}
|
||||
BoundLayerKind::Qsa => read.complete_original_qsa(
|
||||
binding,
|
||||
dense,
|
||||
|
||||
+16
-14
@@ -3,6 +3,7 @@
|
||||
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
use crate::qwen_forward::executor::original_prompt::{DraftRecording, PromptAdmission, PromptResources};
|
||||
|
||||
impl<'ctx> PromptChunk<'_, 'ctx> {
|
||||
pub(super) fn run(
|
||||
@@ -11,20 +12,21 @@ impl<'ctx> PromptChunk<'_, 'ctx> {
|
||||
arena: &mut OriginalPrefillArena<'_, 'ctx>,
|
||||
cancel: &mut dyn FnMut() -> bool,
|
||||
) -> std::result::Result<(), SpecError> {
|
||||
let pending = self.executor.forward(
|
||||
self.binding,
|
||||
self.dense,
|
||||
&mut *self.session,
|
||||
self.source,
|
||||
count,
|
||||
self.kar.as_deref_mut(),
|
||||
&mut *self.moe,
|
||||
&mut *arena,
|
||||
&mut *self.draft,
|
||||
self.embedding,
|
||||
self.scalar_policy,
|
||||
|| cancel(),
|
||||
);
|
||||
let resources = PromptResources {
|
||||
binding: self.binding,
|
||||
dense: self.dense,
|
||||
kar: self.kar.as_deref_mut(),
|
||||
moe: &mut *self.moe,
|
||||
arena: &mut *arena,
|
||||
};
|
||||
let admission = PromptAdmission { session: &mut *self.session, source: self.source, count };
|
||||
let recording = DraftRecording {
|
||||
session: &mut *self.draft,
|
||||
embedding: self.embedding,
|
||||
policy: self.scalar_policy,
|
||||
cancelled: || cancel(),
|
||||
};
|
||||
let pending = self.executor.forward(resources, admission, recording);
|
||||
let pending = forward_outcome(pending, cancel)?;
|
||||
crate::bringup_trace!("DBG[{:.0}s] forward ok, publishing", dbg_el());
|
||||
let _span = super::super::prefill_profile::span(super::super::prefill_profile::Stage::Publish, None);
|
||||
|
||||
@@ -38,6 +38,14 @@ pub(in crate::qwen_forward) struct PromptDeviceRows<'source, 'arena, 'loan, 'ctx
|
||||
sources: Sources<'source, 'ctx>,
|
||||
device: OriginalDeviceResidual<'arena, 'loan, 'ctx>,
|
||||
}
|
||||
/// The model binding, the dense weights and the prompt transaction every layer of one original prompt chunk runs
|
||||
/// against; no layer replaces them.
|
||||
#[derive(Clone, Copy)]
|
||||
pub(in crate::qwen_forward) struct PromptLayerEnv<'a, 'weight, 'txn, 'ctx> {
|
||||
pub(in crate::qwen_forward) binding: &'a ModelBinding,
|
||||
pub(in crate::qwen_forward) dense: &'weight DenseWeightCache<'ctx>,
|
||||
pub(in crate::qwen_forward) txn: &'a OriginalPromptTxn<'txn, 'ctx>,
|
||||
}
|
||||
pub(in crate::qwen_forward) struct PromptDeviceNormedRows<'weight, 'source, 'arena, 'loan, 'ctx> {
|
||||
sources: Sources<'source, 'ctx>,
|
||||
device: OriginalDeviceNormedResidual<'weight, 'arena, 'loan, 'ctx>,
|
||||
|
||||
+8
-10
@@ -1,5 +1,6 @@
|
||||
//! Moved out of the parent module by STRA-338: impl PromptDeviceRead.
|
||||
|
||||
use super::super::super::gdn::PromptSource;
|
||||
use super::produce_original_gdn_fn::{DeviceBlockResult, GdnLayer, Lap, QsaLayerDevices, inject_span, produce_block};
|
||||
#[allow(unused_imports)]
|
||||
use super::*;
|
||||
@@ -53,32 +54,29 @@ impl<'source, 'arena, 'loan, 'ctx> PromptDeviceRead<'source, 'arena, 'loan, 'ctx
|
||||
/// Only its genuine completed end recurrence/history enters the journal.
|
||||
pub(in crate::qwen_forward) fn complete_original_gdn(
|
||||
self,
|
||||
binding: &ModelBinding,
|
||||
dense: &DenseWeightCache<'ctx>,
|
||||
txn: &OriginalPromptTxn<'_, '_>,
|
||||
env: PromptLayerEnv<'_, '_, '_, 'ctx>,
|
||||
producer: &mut OriginalPromptDevice<'ctx>,
|
||||
gdn: &mut leleka_cuda_driver::OriginalGdnPromptDevice<'ctx>,
|
||||
) -> Result<PromptDeviceRows<'source, 'arena, 'loan, 'ctx>> {
|
||||
let PromptLayerEnv { binding, dense, txn } = env;
|
||||
let (layer, context) = self.attention_layer(|phase| phase.same(&txn.phase()))?;
|
||||
self.complete_with(binding, dense, producer, GrRole::Ffn(layer.get()), |read| {
|
||||
let mut lap = Lap::off();
|
||||
let (mut state, rows) = GdnLayer::enter(binding, dense, txn, context, layer, &mut lap)?;
|
||||
let (block, edges) = state.compute(binding, dense, rows, read, gdn)?;
|
||||
let (block, edges) = state.compute(binding, dense, PromptSource { rows, read }, gdn)?;
|
||||
state.leave(binding, dense, txn, edges, &mut lap)?;
|
||||
Ok(block)
|
||||
})
|
||||
}
|
||||
pub(in crate::qwen_forward) fn complete_original_gdn_normed<'weight>(
|
||||
self,
|
||||
binding: &ModelBinding,
|
||||
dense: &'weight DenseWeightCache<'ctx>,
|
||||
txn: &OriginalPromptTxn<'_, '_>,
|
||||
env: PromptLayerEnv<'_, 'weight, '_, 'ctx>,
|
||||
producer: &mut OriginalPromptDevice<'ctx>,
|
||||
gdn: &mut leleka_cuda_driver::OriginalGdnPromptDevice<'ctx>,
|
||||
) -> Result<PromptDeviceNormedRows<'weight, 'source, 'arena, 'loan, 'ctx>> {
|
||||
let (layer, context) = self.attention_layer(|phase| phase.same(&txn.phase()))?;
|
||||
self.complete_with_normed(binding, dense, producer, GrRole::Ffn(layer.get()), |read| {
|
||||
produce_original_gdn(binding, dense, txn, context, layer, read, gdn)
|
||||
let (layer, context) = self.attention_layer(|phase| phase.same(&env.txn.phase()))?;
|
||||
self.complete_with_normed(env.binding, env.dense, producer, GrRole::Ffn(layer.get()), |read| {
|
||||
produce_original_gdn(env, context, layer, read, gdn)
|
||||
})
|
||||
}
|
||||
pub(in crate::qwen_forward) fn complete_original_qsa(
|
||||
|
||||
+5
-12
@@ -64,20 +64,14 @@ impl<'ctx> GdnLayer<'ctx> {
|
||||
&mut self,
|
||||
binding: &ModelBinding,
|
||||
dense: &DenseWeightCache<'ctx>,
|
||||
rows: Vec<GdnChunkRow>,
|
||||
read: OriginalDeviceGrRead<'arena, 'loan, 'ctx>,
|
||||
source: PromptSource<'arena, 'loan, 'ctx>,
|
||||
gdn: &mut leleka_cuda_driver::OriginalGdnPromptDevice<'ctx>,
|
||||
) -> Result<(OriginalDeviceBlock<'arena, 'loan, 'ctx>, Vec<ChunkEdge>)> {
|
||||
let context = self.context;
|
||||
let mut workspace = dense.native_batch_workspace(binding, context)?.ok_or(Error::IdentityMismatch)?;
|
||||
let prompt = PromptLayer { binding, layer: self.layer, cache: dense, current: context };
|
||||
let program = PromptProgram { producer: gdn, workspace: &mut workspace };
|
||||
super::super::super::gdn::GdnStage::produce_prompt_device(
|
||||
prompt,
|
||||
&mut self.owner,
|
||||
PromptSource { rows, read },
|
||||
program,
|
||||
)
|
||||
super::super::super::gdn::GdnStage::produce_prompt_device(prompt, &mut self.owner, source, program)
|
||||
}
|
||||
pub(super) fn leave(
|
||||
self,
|
||||
@@ -99,22 +93,21 @@ impl<'ctx> GdnLayer<'ctx> {
|
||||
|
||||
/// End-state is staged only from the same completed whole-layer producer.
|
||||
pub(in super::super) fn produce_original_gdn<'arena, 'loan, 'ctx>(
|
||||
binding: &ModelBinding,
|
||||
dense: &DenseWeightCache<'ctx>,
|
||||
txn: &OriginalPromptTxn<'_, '_>,
|
||||
env: PromptLayerEnv<'_, '_, '_, 'ctx>,
|
||||
context: &'ctx Context<'ctx>,
|
||||
layer: LayerId,
|
||||
read: OriginalDeviceGrRead<'arena, 'loan, 'ctx>,
|
||||
gdn: &mut leleka_cuda_driver::OriginalGdnPromptDevice<'ctx>,
|
||||
) -> Result<OriginalDeviceBlock<'arena, 'loan, 'ctx>> {
|
||||
use super::super::super::prefill_profile::{Drain, Stage as P, span};
|
||||
let PromptLayerEnv { binding, dense, txn } = env;
|
||||
let drain = Some(context as &dyn Drain);
|
||||
let mut lap = Lap::new("gdn-host");
|
||||
let state_in = span(P::GdnStateIn, drain);
|
||||
let (mut state, rows) = GdnLayer::enter(binding, dense, txn, context, layer, &mut lap)?;
|
||||
drop(state_in);
|
||||
let compute = span(P::GdnCompute, drain);
|
||||
let (block, edges) = state.compute(binding, dense, rows, read, gdn)?;
|
||||
let (block, edges) = state.compute(binding, dense, PromptSource { rows, read }, gdn)?;
|
||||
drop(compute);
|
||||
lap.at(4, "compute: produce_prompt_device");
|
||||
let _state_out = span(P::GdnStateOut, drain);
|
||||
|
||||
Reference in New Issue
Block a user