STRA-338 params e01: full MTP forward weights take the head sources as one value (vocabulary derived from the native head)
This commit is contained in:
@@ -20,6 +20,13 @@ enum WeightSource {
|
||||
Pinned,
|
||||
RtDirectory,
|
||||
}
|
||||
/// The native MTP head and the optional gathered draft-vocabulary head that the full forward chooses between.
|
||||
#[derive(Clone, Copy)]
|
||||
pub(in crate::qwen_forward) struct MtpHeadSources<'a, 'ctx> {
|
||||
pub(in crate::qwen_forward) native: &'a OriginalMtpNativeHead<'ctx>,
|
||||
pub(in crate::qwen_forward) draft: Option<&'a leleka_cuda_driver::OriginalMtpDraftHead<'ctx>>,
|
||||
}
|
||||
|
||||
/// Clones share the same device allocations (`Rc`); no buffer is duplicated.
|
||||
#[derive(Clone)]
|
||||
pub(in crate::qwen_forward) struct RetainedOriginalMtpWeights<'ctx> {
|
||||
|
||||
+8
-11
@@ -186,20 +186,20 @@ impl<'ctx> RetainedOriginalMtpWeights<'ctx> {
|
||||
/// Exact full MTP forward role order. The caller lends the model-affine
|
||||
/// native-head allocation from `OriginalNativeOutput::mtp_head`; this
|
||||
/// cache never fabricates a replacement head buffer or dispatch profile.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
/// The id vocabulary is the native head's own vocabulary.
|
||||
pub(in crate::qwen_forward) fn full_forward_weights(
|
||||
&self,
|
||||
binding: &ModelBinding,
|
||||
context: &'ctx Context<'ctx>,
|
||||
prefix: Rc<leleka_cuda_driver::OriginalMtpRetainedPrefix<'ctx>>,
|
||||
head: &OriginalMtpNativeHead<'ctx>,
|
||||
id_vocab: usize,
|
||||
draft_head: Option<&leleka_cuda_driver::OriginalMtpDraftHead<'ctx>>,
|
||||
heads: MtpHeadSources<'_, 'ctx>,
|
||||
) -> Result<Rc<leleka_cuda_driver::OriginalMtpRetainedFullWeights<'ctx>>> {
|
||||
let head = heads.native;
|
||||
let id_vocab = head.vocabulary();
|
||||
self.admit_full_forward(binding, context, head, id_vocab)?;
|
||||
let roles = self.acquire_roles(binding, context, FULL_FORWARD_ROLES)?;
|
||||
let experts = self.expert_bank(binding, context)?;
|
||||
let (head_weights, head_rows, subset) = Self::select_head(head, draft_head);
|
||||
let (head_weights, head_rows, subset) = Self::select_head(heads);
|
||||
let weights = FullWeights::retain(
|
||||
context,
|
||||
prefix,
|
||||
@@ -231,13 +231,10 @@ impl<'ctx> RetainedOriginalMtpWeights<'ctx> {
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn select_head(
|
||||
head: &OriginalMtpNativeHead<'ctx>,
|
||||
draft_head: Option<&leleka_cuda_driver::OriginalMtpDraftHead<'ctx>>,
|
||||
) -> HeadBinding<'ctx> {
|
||||
match draft_head {
|
||||
fn select_head(heads: MtpHeadSources<'_, 'ctx>) -> HeadBinding<'ctx> {
|
||||
match heads.draft {
|
||||
Some(draft) => (draft.rows(), draft.count(), Some(draft.subset_pair())),
|
||||
None => (head.weights(), head.vocabulary(), None),
|
||||
None => (heads.native.weights(), heads.native.vocabulary(), None),
|
||||
}
|
||||
}
|
||||
pub(in crate::qwen_forward) fn metadata_bytes(&self) -> Result<usize> {
|
||||
|
||||
@@ -337,7 +337,7 @@ pub(super) struct RoutedSourceHealth<'cache, 'ctx> {
|
||||
#[path = "cache_original_mtp_weights.rs"]
|
||||
mod original_mtp_weights;
|
||||
#[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
|
||||
pub(in crate::qwen_forward) use original_mtp_weights::RetainedOriginalMtpWeights;
|
||||
pub(in crate::qwen_forward) use original_mtp_weights::{MtpHeadSources, RetainedOriginalMtpWeights};
|
||||
|
||||
mod validate_ranked_profile_fn;
|
||||
#[allow(unused_imports)]
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
use super::{
|
||||
contract::{Error, Result, Stage},
|
||||
executor::original_prompt::embedding::OriginalPromptEmbedding,
|
||||
moe_weight_cache::{MoeWeightCache, RetainedOriginalMtpWeights},
|
||||
moe_weight_cache::{MoeWeightCache, MtpHeadSources, RetainedOriginalMtpWeights},
|
||||
output_native::{OriginalMtpNativeHead, OriginalNativeOutput},
|
||||
session::{QwenSession, original_prompt::draft::OriginalDraftSession},
|
||||
};
|
||||
|
||||
+2
-2
@@ -143,8 +143,8 @@ impl<'ctx> OriginalMtpFullOwner<'ctx> {
|
||||
let head = &prepared.head;
|
||||
let scalar = retained.scalar_prefill_weights(binding, context, embedding)?;
|
||||
let prefix = Rc::new(OriginalMtpRetainedPrefix::from_scalar(scalar).map_err(driver_error)?);
|
||||
let draft_head = prepared.draft_head.as_ref();
|
||||
Ok(retained.full_forward_weights(binding, context, prefix, head, head.vocabulary(), draft_head)?)
|
||||
let heads = MtpHeadSources { native: head, draft: prepared.draft_head.as_ref() };
|
||||
Ok(retained.full_forward_weights(binding, context, prefix, heads)?)
|
||||
}
|
||||
pub(super) fn shared_drafter(
|
||||
context: &'ctx Context<'ctx>,
|
||||
|
||||
Reference in New Issue
Block a user