From fdb1071783b17dfbf220143edbe2dcb666f8eb7e Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Fri, 16 Oct 2026 15:52:23 +0200 Subject: [PATCH] perf(prefill): profile spans for input embedding/PLE and row init sources/upload Co-Authored-By: Claude Opus 5.5 --- .../src/qwen_forward/executor_original_prompt.rs | 5 ++++- crates/leleka-runtime/src/qwen_forward/input.rs | 3 +++ .../src/qwen_forward/prefill_profile.rs | 16 ++++++++++++++-- 3 files changed, 21 insertions(+), 3 deletions(-) diff --git a/crates/leleka-runtime/src/qwen_forward/executor_original_prompt.rs b/crates/leleka-runtime/src/qwen_forward/executor_original_prompt.rs index 22c40cb3..02527f3f 100644 --- a/crates/leleka-runtime/src/qwen_forward/executor_original_prompt.rs +++ b/crates/leleka-runtime/src/qwen_forward/executor_original_prompt.rs @@ -274,10 +274,13 @@ impl<'ctx> OriginalPromptExecutor<'ctx>{ drop(input_span); let init_span=prof::span(PStage::Initialize,drain); let mut sources=Vec::new();sources.try_reserve_exact(tokens.len()).map_err(|_|Error::InputAllocation)?; + let sources_span=prof::span(PStage::InitSources,None); for local in 0..tokens.len(){sources.push(PromptDeviceSource::from_original(binding,self.context,&txn,local)?);} + drop(sources_span); + let upload_span=prof::span(PStage::InitUpload,drain); let prompt=self.prompt.as_mut().ok_or(Error::IdentityMismatch)?; let rows=PromptDeviceRows::initialize(binding,dense,self.context,prompt,arena.begin_rows(tokens.len()).map_err(driver_error)?,sources)?; - drop(init_span); + drop(upload_span);drop(init_span); let mut carrier=Carrier::Plain(rows); for layer in binding.ordered_layers(){ let index=layer.index();let role=super::super::gr::GrRole::Attention(index); diff --git a/crates/leleka-runtime/src/qwen_forward/input.rs b/crates/leleka-runtime/src/qwen_forward/input.rs index f172a1ec..03df518b 100644 --- a/crates/leleka-runtime/src/qwen_forward/input.rs +++ b/crates/leleka-runtime/src/qwen_forward/input.rs @@ -115,8 +115,11 @@ impl InputStage { txn.input_predecessors()?, binding.input_constants(), )?; + let embedding_span = super::prefill_profile::span(super::prefill_profile::Stage::InputEmbedding, None); let embedding = binding.embedding_row(token.get()).map_err(binding_error)?; let streams = ResidualStreams::broadcast(&embedding)?; + drop(embedding_span); + let _ple_span = super::prefill_profile::span(super::prefill_profile::Stage::InputPle, None); let ple = cache.gather(kar, &rows)?; Ok(InputReady { binding: binding.identity(), diff --git a/crates/leleka-runtime/src/qwen_forward/prefill_profile.rs b/crates/leleka-runtime/src/qwen_forward/prefill_profile.rs index 720bca0a..a908ac17 100644 --- a/crates/leleka-runtime/src/qwen_forward/prefill_profile.rs +++ b/crates/leleka-runtime/src/qwen_forward/prefill_profile.rs @@ -13,8 +13,16 @@ use std::time::{Duration, Instant}; pub(crate) enum Stage { /// Host input staging of every row (token embedding, KAR/PLE inputs). Input, + /// Token embedding rows of the input staging (KAR path). + InputEmbedding, + /// PLE rows of the input staging (KAR gather, KAR path). + InputPle, /// Row source keys and the initial R/PLE upload. Initialize, + /// Row source keys and their finite checks. + InitSources, + /// Initial R/PLE staging and upload. + InitUpload, /// Layer-one PLE application and its history. Ple, /// Chronological per-row session validation of every phase. @@ -56,8 +64,8 @@ pub(crate) enum Stage { /// Expert-cache slot loan for the chunk's arena (expert tier only). Lend, } -const STAGES: [Stage; 22] = [ - Stage::Input, Stage::Initialize, Stage::Ple, Stage::Validate, Stage::AttnRead, Stage::Gdn, Stage::GdnStateIn, +const STAGES: [Stage; 26] = [ + Stage::Input, Stage::InputEmbedding, Stage::InputPle, Stage::Initialize, Stage::InitSources, Stage::InitUpload, Stage::Ple, Stage::Validate, Stage::AttnRead, Stage::Gdn, Stage::GdnStateIn, Stage::GdnCompute, Stage::GdnStateOut, Stage::Qsa, Stage::FfnRead, Stage::Moe, Stage::MoePrepare, Stage::MoeSpans, Stage::MoeRing, Stage::MoeFinish, Stage::Inject, Stage::Final, Stage::DraftKv, Stage::FinishPreview, Stage::Publish, Stage::Lend, @@ -66,7 +74,11 @@ impl Stage { fn name(self) -> &'static str { match self { Self::Input => "input", + Self::InputEmbedding => "input.embedding", + Self::InputPle => "input.ple", Self::Initialize => "init", + Self::InitSources => "init.sources", + Self::InitUpload => "init.upload", Self::Ple => "ple", Self::Validate => "validate", Self::AttnRead => "attn_read",