Merge main (engine stage 10) into claude/debt-rename; rename script rerun, old-names marker for the rename table, baseline regenerated

This commit is contained in:
Pavlo Ratushnyi
2026-11-14 22:17:24 +01:00
280 changed files with 571 additions and 437 deletions
+1 -6
View File
@@ -4,21 +4,16 @@
"oversize": {},
"source": {
"dyn-trait:leleka-cuda-driver": 45,
"dyn-trait:leleka-engine-core": 18,
"dyn-trait:leleka-engine-fake": 1,
"dyn-trait:leleka-engine-qwen35-cuda": 53,
"dyn-trait:leleka-engine-qwen35-cuda": 9,
"env-read:leleka-control-plane": 3,
"env-read:leleka-engine-qwen35-cuda": 1,
"glob-super-import:leleka-cuda-driver": 2,
"instant-now:leleka-control-plane": 15,
"instant-now:leleka-cuda-driver": 25,
"instant-now:leleka-engine-host": 4,
"instant-now:leleka-engine-qwen35-cuda": 16,
"instant-now:leleka-native-cpu-expert": 27,
"path-include:leleka-cuda-driver": 1,
"process-global:leleka-control-plane": 2,
"process-global:leleka-cuda-driver": 96,
"process-global:leleka-engine-qwen35-cuda": 59,
"process-global:leleka-native-cpu-expert": 27
},
"mechanical_names": []
+58 -1
View File
@@ -158,7 +158,64 @@
{"crate": "leleka-gateway-text", "file": "src/prompt/renderer.rs", "ratchet": "process-global", "reason": "the compiled pinned chat template: immutable, built on first use, read by every request"},
{"crate": "leleka-control-plane", "file": "src/request_log.rs", "ratchet": "process-global", "reason": "the process-wide request counters and histograms that /metrics renders; written by every request"},
{"crate": "leleka-control-plane", "file": "src/responses/harmony_prompt.rs", "ratchet": "process-global", "reason": "the gpt-oss prompt date: configuration set once by serve before the first request"},
{"crate": "leleka-control-plane", "file": "src/stage_trace.rs", "ratchet": "process-global", "reason": "diagnostic stage table of the replay harness and STRATA_STAGE_TRACE: one table per process by design"}
{"crate": "leleka-control-plane", "file": "src/stage_trace.rs", "ratchet": "process-global", "reason": "diagnostic stage table of the replay harness and STRATA_STAGE_TRACE: one table per process by design"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/settings/source.rs", "ratchet": "env-read", "reason": "the one reader of the process environment of the engine: ProcessEnv is the adapter of the EnvSource port, and Settings parses every variable into typed fields there (S13)"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_engine/round_tally/serve_rounds.rs", "ratchet": "instant-now", "reason": "measurement timer in a hot loop (one reading per traced port call, only when the bring-up trace is on); a Clock parameter would add a generic to every owner on the path, which is the S14 follow-up; the reading is a Duration that only feeds a log line or a counter"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_lookahead.rs", "ratchet": "instant-now", "reason": "measurement timer in a hot loop (one reading per routing prediction on the lookahead thread); a Clock parameter would add a generic to every owner on the path, which is the S14 follow-up; the reading is a Duration that only feeds a log line or a counter"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_pool/direct_group_steps.rs", "ratchet": "instant-now", "reason": "measurement timer in a hot loop (one reading per CPU expert group of a decode round); a Clock parameter would add a generic to every owner on the path, which is the S14 follow-up; the reading is a Duration that only feeds a log line or a counter"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_pool/direct_tier.rs", "ratchet": "instant-now", "reason": "measurement timer in a hot loop (one reading per eager admission, once at start-up); a Clock parameter would add a generic to every owner on the path, which is the S14 follow-up; the reading is a Duration that only feeds a log line or a counter"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_pool.rs", "ratchet": "instant-now", "reason": "measurement timer in a hot loop (one reading per pool phase lap of a decode round); a Clock parameter would add a generic to every owner on the path, which is the S14 follow-up; the reading is a Duration that only feeds a log line or a counter"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_residency/pcie_share_controllers.rs", "ratchet": "instant-now", "reason": "measurement timer in a hot loop (one reading per PCIe lag probe and adaptation round); a Clock parameter would add a generic to every owner on the path, which is the S14 follow-up; the reading is a Duration that only feeds a log line or a counter"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/prefill_profile.rs", "ratchet": "instant-now", "reason": "measurement timer in a hot loop (one reading per prefill stage span, only when the profile switch is on); a Clock parameter would add a generic to every owner on the path, which is the S14 follow-up; the reading is a Duration that only feeds a log line or a counter"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/prompt_device_rows/prompt_device_read/produce_original_gdn.rs", "ratchet": "instant-now", "reason": "measurement timer in a hot loop (one reading per GDN layer producer lap, only when the command profile is on); a Clock parameter would add a generic to every owner on the path, which is the S14 follow-up; the reading is a Duration that only feeds a log line or a counter"},
{"crate": "leleka-engine-core", "file": "src/family.rs", "ratchet": "dyn-trait", "reason": "EngineFamily::spawn returns Box<dyn Backend>: the family seam is the process boundary of the engine, called once at start-up"},
{"crate": "leleka-engine-fake", "file": "src/lib.rs", "ratchet": "dyn-trait", "reason": "Box<dyn Backend> is the process boundary: the factory hands the composed engine to the host, which holds one Backend per process (startup composition only, never per round)"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/backend/family.rs", "ratchet": "dyn-trait", "reason": "Box<dyn Backend> is the process boundary: the factory hands the composed engine to the host, which holds one Backend per process (startup composition only, never per round)"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/backend/spawn.rs", "ratchet": "dyn-trait", "reason": "Box<dyn Backend> is the process boundary: the factory hands the composed engine to the host, which holds one Backend per process (startup composition only, never per round)"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/backend/spawn_optimized.rs", "ratchet": "dyn-trait", "reason": "Box<dyn Backend> is the process boundary: the factory hands the composed engine to the host, which holds one Backend per process (startup composition only, never per round)"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/backend/spawn_original.rs", "ratchet": "dyn-trait", "reason": "Box<dyn Backend> is the process boundary: the factory hands the composed engine to the host, which holds one Backend per process (startup composition only, never per round)"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/backend/spawn_preview.rs", "ratchet": "dyn-trait", "reason": "Box<dyn Backend> is the process boundary: the factory hands the composed engine to the host, which holds one Backend per process (startup composition only, never per round)"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/backend/measurement.rs", "ratchet": "dyn-trait", "reason": "the evaluation measurement sink is a stored callback handed in by the host (observer port, called once per request)"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/backend/original_serve/runner.rs", "ratchet": "dyn-trait", "reason": "the GPU telemetry probe is a stored callback handed in by the host at load (port, sampled by the telemetry tick, not per token)"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/backend/original_serve/runner/owner_run_steps.rs", "ratchet": "process-global", "reason": "reaches the process-wide memory governor through Governor::global(); the governor is one per process by design (host RAM is process-wide) and the handle is threaded through StackConfig and the request environment in the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/backend/original_serve/runner/reconfigure_command.rs", "ratchet": "process-global", "reason": "reaches the process-wide memory governor through Governor::global(); the governor is one per process by design (host RAM is process-wide) and the handle is threaded through StackConfig and the request environment in the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/backend/session.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/conversation/memory.rs", "ratchet": "process-global", "reason": "reaches the process-wide memory governor through Governor::global(); the governor is one per process by design (host RAM is process-wide) and the handle is threaded through StackConfig and the request environment in the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/memory_governor.rs", "ratchet": "process-global", "reason": "reaches the process-wide memory governor through Governor::global(); the governor is one per process by design (host RAM is process-wide) and the handle is threaded through StackConfig and the request environment in the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/memory_governor/page_cache.rs", "ratchet": "process-global", "reason": "reaches the process-wide memory governor through Governor::global(); the governor is one per process by design (host RAM is process-wide) and the handle is threaded through StackConfig and the request environment in the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/model_binding/weight_binding.rs", "ratchet": "process-global", "reason": "instance-local lazy cell (std::cell::OnceCell), not a process global: the gate pattern matches the type name"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/model_binding/weight_binding/binding_identity.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/model_binding/weight_binding/model_binding.rs", "ratchet": "process-global", "reason": "instance-local lazy cell (std::cell::OnceCell), not a process global: the gate pattern matches the type name"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/contract.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/mtp/mtp_frame.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/mtp/state/chunk/checked_chunk_end.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/mtp/state/dense_kv.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/mtp/state/prefix_draft_snapshot.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/mtp/state/warming.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/mtp_attention/dense_geometry.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/mtp_decode/first_seed_reuse_enabled.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/mtp_decode/mtp_decoder/decoder_entry.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/mtp_decode/mtp_window_spec.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_residency/split_group_pcie.rs", "ratchet": "process-global", "reason": "the adaptive-tier tuning constants, derived once from the settings capture (immutable after the first read)"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_stack.rs", "ratchet": "process-global", "reason": "the epoch of the bring-up trace timestamps (DBG_T0), set once; diagnostics only"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_stack/stack_phases/open_cache_steps.rs", "ratchet": "process-global", "reason": "reaches the process-wide memory governor through Governor::global(); the governor is one per process by design (host RAM is process-wide) and the handle is threaded through StackConfig and the request environment in the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_stack/stack_phases/original_serve_stack_memory_classes.rs", "ratchet": "process-global", "reason": "reaches the process-wide memory governor through Governor::global(); the governor is one per process by design (host RAM is process-wide) and the handle is threaded through StackConfig and the request environment in the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_stack/stack_phases/original_serve_stack_open/assemble.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_stack/stack_phases/original_serve_stack_prefill_phase.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_stack/prefix/prefix_config.rs", "ratchet": "process-global", "reason": "reaches the process-wide memory governor through Governor::global(); the governor is one per process by design (host RAM is process-wide) and the handle is threaded through StackConfig and the request environment in the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_stack/prefix/prefix_serve/prefix_serve_after_phase_parking.rs", "ratchet": "process-global", "reason": "reaches the process-wide memory governor through Governor::global(); the governor is one per process by design (host RAM is process-wide) and the handle is threaded through StackConfig and the request environment in the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_serve_stack/stack_config.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_spec_controller/trace_enabled.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_spec_draft.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/original_spec_draft/prefill_records.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/qsa_index/context.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/qsa_native_resources.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/session.rs", "ratchet": "process-global", "reason": "instance-local lazy cell (std::cell::OnceCell), not a process global: the gate pattern matches the type name"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/session/chunk/host_charge_bounded.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/session/chunk/qwen_chunk_txn/qwen_chunk_txn_begin.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/session/chunk/verify/qwen_chunk_txn/qwen_chunk_txn_begin_verification.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/session/chunk/verify/verified_target_prefix.rs", "ratchet": "process-global", "reason": "reads the serving context (cells) that the engine configures once at start-up (leleka-cuda-model::serving_context, an immutable bound afterwards); threading it through every position check is the S13/S14 injection"},
{"crate": "leleka-engine-qwen35-cuda", "file": "src/qwen_forward/session/qwen_session.rs", "ratchet": "process-global", "reason": "instance-local lazy cell (std::cell::OnceCell), not a process global: the gate pattern matches the type name"}
],
"source_patterns": [
{"id": "env-read", "regex": "\\benv::var(_os)?\\(", "why": "configuration must be parsed once into a Settings struct (S13), not read all over the code"},
+2 -2
View File
@@ -37,8 +37,8 @@ pub struct KvTarget<'a> {
pub has_index_rows: bool,
}
struct Verifier<'a> {
mem: &'a mut dyn StateMemory,
struct Verifier<'a, M: StateMemory + ?Sized> {
mem: &'a mut M,
buffer: Vec<u8>,
hash: u64,
error: Option<ConvError>,
@@ -7,8 +7,8 @@ use super::{
/// Compare the pages of the drafter ring (the last `st.n_slots` pages of the saved pool) with the device's resident
/// copy of them; false once a page differs or cannot be read (the verifier holds the failure).
fn verify_ring(
v: &mut Verifier<'_>,
fn verify_ring<M: StateMemory + ?Sized>(
v: &mut Verifier<'_, M>,
saved: &crate::conversation::buffer::ConversationBuffer,
(begin, end): (i64, i64),
(layer, pool, st): (KvLayer, KvPool, &QsaDesc),
@@ -30,7 +30,11 @@ fn verify_ring(
/// Diagnostic read-back after a synchronised restore: compares the
/// authoritative bytes (and the resident draft-ring pages), fingerprinting the
/// authoritative payload only (FNV-1a 64). Never changes model state.
pub fn kv_verify(image: &ConversationKv, target: KvTarget<'_>, mem: &mut dyn StateMemory) -> ConvResult<u64> {
pub fn kv_verify<M: StateMemory + ?Sized>(
image: &ConversationKv,
target: KvTarget<'_>,
mem: &mut M,
) -> ConvResult<u64> {
let KvTarget { layer, st, g, upto, has_index_rows: index } = target;
kv_validate(image, st, g, upto, index)?;
let mut v = Verifier { mem, buffer: vec![0; 65536], hash: 1469598103934665603, error: None };
@@ -91,11 +91,11 @@ fn capture_layer(
/// only for storage retained from an image actually restored into this
/// session, bounded by every subsequent rewrite: equal token IDs alone do not
/// establish that its K/V bytes are unchanged.
pub fn kv_save(
pub fn kv_save<M: StateMemory + ?Sized>(
image: &mut ConversationKv,
target: KvTarget<'_>,
unchanged_tokens: i64,
mem: &mut dyn StateMemory,
mem: &mut M,
reused_bytes: Option<&mut usize>,
) -> ConvResult<()> {
let KvTarget { layer, st, g, upto, has_index_rows: index } = target;
@@ -159,7 +159,11 @@ fn restore_buffer(
/// Write the image into the layer; refills streamed residency afterwards.
/// The caller synchronises the device before and after the whole session.
pub fn kv_restore(image: &ConversationKv, target: KvTarget<'_>, mem: &mut dyn StateMemory) -> ConvResult<()> {
pub fn kv_restore<M: StateMemory + ?Sized>(
image: &ConversationKv,
target: KvTarget<'_>,
mem: &mut M,
) -> ConvResult<()> {
let KvTarget { layer, st, g, upto, has_index_rows: index } = target;
kv_validate(image, st, g, upto, index)?;
for (buffer, pool) in image.buffers().into_iter().zip(KvPool::ALL) {
@@ -180,7 +184,7 @@ pub fn kv_restore(image: &ConversationKv, target: KvTarget<'_>, mem: &mut dyn St
Ok(())
}
impl Verifier<'_> {
impl<M: StateMemory + ?Sized> Verifier<'_, M> {
/// Compare device bytes at `base + ..` with `expected`, chunked through a
/// 64 KiB workspace; optionally fold them into the fingerprint.
pub(super) fn compare(&mut self, loc: StateRegion, base: usize, expected: &[u8], include_hash: bool) -> bool {
@@ -167,9 +167,9 @@ impl ConversationManager {
/// continue the live session, restore a checkpoint, restore a parked
/// conversation (parking the outgoing one first), or start empty. Any
/// error is fatal for the request and the device state is then undefined.
pub fn begin_request(
pub fn begin_request<E: SessionEngine + ?Sized>(
&mut self,
engine: &mut dyn SessionEngine,
engine: &mut E,
ids: &[i32],
req_imgs: &[ConversationImageKey],
want_cvec: bool,
@@ -215,9 +215,9 @@ impl ConversationManager {
/// A checkpoint of the state after `ids[..position]`. `Ok` also when
/// checkpoints are off. An existing checkpoint at the position just
/// becomes the most recently used.
pub fn checkpoint_at(
pub fn checkpoint_at<E: SessionEngine + ?Sized>(
&mut self,
engine: &mut dyn SessionEngine,
engine: &mut E,
ids: &[i32],
req_imgs: &[ConversationImageKey],
position: usize,
@@ -247,9 +247,9 @@ impl ConversationManager {
/// A batched prompt chunk finished and the prompt is read up to `done`:
/// take the periodic checkpoint when it is due.
pub fn chunk_done(
pub fn chunk_done<E: SessionEngine + ?Sized>(
&mut self,
engine: &mut dyn SessionEngine,
engine: &mut E,
ids: &[i32],
req_imgs: &[ConversationImageKey],
done: usize,
@@ -267,9 +267,9 @@ impl ConversationManager {
/// and the turn/root checkpoint when the action ends its segment.
// Used by the Original-path prompt driver (the plan type is crate-private).
#[allow(dead_code)]
pub fn after_prompt_action(
pub fn after_prompt_action<E: SessionEngine + ?Sized>(
&mut self,
engine: &mut dyn SessionEngine,
engine: &mut E,
ids: &[i32],
req_imgs: &[ConversationImageKey],
action: &PromptAction,
@@ -170,7 +170,11 @@ impl ConversationManager {
/// an incoming image that is still alive during the exchange. Anything
/// recoverable (nothing to park, no room, no RAM, allocation failure)
/// skips parking and returns `Ok`; a device failure is fatal.
pub(in super::super) fn park_current(&mut self, engine: &mut dyn SessionEngine, held: usize) -> ConvResult<()> {
pub(in super::super) fn park_current<E: SessionEngine + ?Sized>(
&mut self,
engine: &mut E,
held: usize,
) -> ConvResult<()> {
if !self.cache.enabled() || !self.live_ok || self.live.is_empty() {
return Ok(());
}
@@ -53,8 +53,8 @@ struct Run {
/// Deterministic xorshift for the property test.
struct Rng(u64);
#[path = "manager_tests/byte_budget_and_slot.rs"]
mod byte_budget_and_slot;
#[path = "manager_tests/budget_and_failure_rules.rs"]
mod budget_and_failure_rules;
#[path = "manager_tests/continuing_chat_reuses.rs"]
mod continuing_chat_reuses;
#[path = "manager_tests/random_traffic_resumes_into_exact_prefix_state.rs"]
@@ -241,11 +241,11 @@ fn begin_capture(
}
/// Capture the K/V of every layer, then the draft's; returns the bytes the retained storage let it skip.
fn capture_kv(
fn capture_kv<M: StateMemory + ?Sized>(
captured: &mut SavedConversation,
view: &ConversationView<'_>,
session: SnapshotSession<'_>,
mem: &mut dyn StateMemory,
mem: &mut M,
unchanged: i64,
) -> ConvResult<usize> {
let SnapshotSession { ss, g, draft } = session;
@@ -270,10 +270,10 @@ fn capture_kv(
/// Builds into a new object so a failure cannot publish a partial snapshot.
/// `reuse` is consumed, including on failure. The caller admits the estimate
/// first; the active session is never modified by capture.
pub fn snapshot_save(
pub fn snapshot_save<M: StateMemory + ?Sized>(
view: &ConversationView<'_>,
session: SnapshotSession<'_>,
mem: &mut dyn StateMemory,
mem: &mut M,
reuse: ConversationKvReuse,
reused_bytes: Option<&mut usize>,
) -> ConvResult<SavedConversation> {
@@ -335,12 +335,12 @@ pub fn snapshot_validate(
// Restore a whole image. Invalid images are rejected before any device
/// write; a transfer failure may leave partial state.
pub fn snapshot_restore(
pub fn snapshot_restore<M: StateMemory + ?Sized>(
image: &SavedConversation,
ss: &SessionSpec,
g: &ModelGeometry,
draft: &QsaDesc,
mem: &mut dyn StateMemory,
mem: &mut M,
) -> RestoreOutcome {
if let Err(e) = snapshot_validate(image, ss, g, draft) {
return RestoreOutcome::Invalid(e.0);
@@ -349,7 +349,7 @@ pub fn snapshot_restore(
return RestoreOutcome::TransferFailed(e.0);
}
let upto = image.live.ids.len() as i64;
let restore = |mem: &mut dyn StateMemory| -> ConvResult<()> {
let restore = |mem: &mut M| -> ConvResult<()> {
for j in 0..ss.owned_qsa() {
let st = ss.owned(j).ok_or_else(|| ConvError("conversation snapshot: missing QSA state".into()))?;
kv_restore(&image.kv[j], KvTarget { layer: KvLayer::Main(j), st, g, upto, has_index_rows: true }, mem)?;
+6 -6
View File
@@ -188,11 +188,11 @@ fn alloc_payloads(c: &mut ConversationCheckpoint, ss: &SessionSpec, z: &StateSiz
/// Capture the running state at `c.ids.len()` tokens into `c`'s payloads.
/// The caller synchronises the device first.
pub fn checkpoint_save(
pub fn checkpoint_save<M: StateMemory + ?Sized>(
c: &mut ConversationCheckpoint,
ss: &SessionSpec,
g: &ModelGeometry,
mem: &mut dyn StateMemory,
mem: &mut M,
) -> ConvResult<()> {
let z = checkpoint_targets(ss, g, c.ids.len())?;
alloc_payloads(c, ss, &z)?;
@@ -208,11 +208,11 @@ pub fn checkpoint_save(
}
/// Restore the indexer state of QSA layer `j`; the spare (moving) pooled row is reconstructed from the dead key.
fn restore_indexer(
fn restore_indexer<M: StateMemory + ?Sized>(
c: &ConversationCheckpoint,
j: usize,
(z, g): (&StateSizes, &ModelGeometry),
mem: &mut dyn StateMemory,
mem: &mut M,
) -> ConvResult<()> {
let idx = |kind| StateRegion::Idx { layer: j, kind };
let dead = &c.dead[j * z.dead..(j + 1) * z.dead];
@@ -228,11 +228,11 @@ fn restore_indexer(
}
/// Restore a validated checkpoint; invalid input writes nothing.
pub fn checkpoint_restore(
pub fn checkpoint_restore<M: StateMemory + ?Sized>(
c: &ConversationCheckpoint,
ss: &SessionSpec,
g: &ModelGeometry,
mem: &mut dyn StateMemory,
mem: &mut M,
) -> ConvResult<()> {
checkpoint_validate(c, ss, g)?;
let z = session_sizes(g, ss)?;
@@ -7,7 +7,7 @@ use super::{
};
mod admit;
mod eviction;
mod lookup_clock;
mod prefix_store_consider_commit;
mod prefix_store_evict_and_budget;
mod prefix_store_stats_and_clock;
mod scoring;
+7 -7
View File
@@ -5,17 +5,17 @@ mod original_serve;
use crate::experimental::{self as experimental_modes, ExperimentalConfig};
use crate::model_binding::kar_expert_source::KarExpertSource;
pub use crate::model_binding::kar_expert_source::{KarArchiveRef, KarExpertLevels, KarExpertSourceConfig};
pub use crate::model_binding::qwen4exp_kar_ple::InheritedKarArchive;
pub use crate::model_binding::kar_ple_source::InheritedKarArchive;
pub use original_serve::{
ExpertSource, OriginalServeChoice, OriginalServeMode, OriginalServeOptions, PrefixCacheOptions, PrefixTail,
};
mod measurement;
use crate::model_binding::qwen4exp_input::{InputBindingError, ModelBinding};
use crate::model_binding::weight_binding::{InputBindingError, ModelBinding};
// What only the preview serve path (generation loop, weight caches, resident conversations) works with.
#[cfg(feature = "preview-path")]
use crate::{
conversation::resident::{ResidentConversations, ResidentPolicy},
model_binding::qwen4exp_input::InputConstants,
model_binding::weight_binding::InputConstants,
qwen_forward::{
contract::{Dimension, Position, TokenId},
dense_weight_cache::DenseWeightCache,
@@ -153,14 +153,11 @@ mod lifecycle_tests;
mod tests;
#[cfg(test)]
mod backend_measurement_sdet;
mod measurement_bookkeeping_proof;
#[cfg(feature = "preview-path")]
#[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
mod combined_prefix_numeric;
#[cfg(feature = "preview-path")]
#[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
mod combined_prefix_numeric_sdet;
#[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
mod original_serve_arms;
#[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
@@ -177,6 +174,9 @@ mod original_serve_smoke;
mod original_serve_ttft;
#[cfg(feature = "preview-path")]
#[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
mod prefix_equivalence_gate;
#[cfg(feature = "preview-path")]
#[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
mod singleload_proof;
#[cfg(feature = "preview-path")]
@@ -8,8 +8,8 @@ use super::{
Dimension, Instant, MtpDecoder, MtpWindowError, MtpWindowSpec, TargetStepProduct, TokenId, native_position,
};
use crate::qwen_forward::mtp::KnownNext;
mod prefill_tiles_and_windows;
use prefill_tiles_and_windows::{begin_decoder, commit_window, emit_token_text, prefill_tiles, verified_window};
mod mtp_loop_steps;
use mtp_loop_steps::{begin_decoder, commit_window, emit_token_text, prefill_tiles, verified_window};
pub(super) fn generate_mtp<C: Clock>(
run: Generation<'_, '_, '_, C>,
@@ -1,5 +1,5 @@
//! Defines `GpuProbe`, `Run`.
//! Split out of `original_serve` to keep its files under the line limit.
//! The state of the Original owner loop: `Run` (everything `serve_load` hands the loop once the context exists) and the
//! GPU telemetry probe port the host injects. The loop's steps live in the `runner/` files.
use super::super::{
ActiveGuard, BackendError, Command, DeferredTail, ErrorCode, FinishReason, GENERATION_TIMEOUT, GenerationEvent,
@@ -93,17 +93,17 @@ mod capture_tests {
}
}
mod stack_config_and_reports;
use stack_config_and_reports::CapturedIds;
use stack_config_and_reports::PhaseDurations;
use stack_config_and_reports::admission_error;
use stack_config_and_reports::capture_request;
use stack_config_and_reports::gpu_probe;
use stack_config_and_reports::log_request_end;
use stack_config_and_reports::meta_facts;
use stack_config_and_reports::open_error;
use stack_config_and_reports::publish_prefix_summary;
use stack_config_and_reports::stack_config;
mod stack_reports;
use stack_reports::CapturedIds;
use stack_reports::PhaseDurations;
use stack_reports::admission_error;
use stack_reports::capture_request;
use stack_reports::gpu_probe;
use stack_reports::log_request_end;
use stack_reports::meta_facts;
use stack_reports::open_error;
use stack_reports::publish_prefix_summary;
use stack_reports::stack_config;
mod request_generation;
pub(in super::super) use request_generation::generate;
pub(in super::super) use request_generation::{ClientLink, RequestToServe, TokenVocabulary};
@@ -244,6 +244,11 @@ fn capture_json(
)
}
/// Token ids as the comma-separated line of the capture file.
fn join_ids<T: std::fmt::Display>(ids: &[T]) -> String {
ids.iter().map(ToString::to_string).collect::<Vec<_>>().join(",")
}
/// The prompt ids and the generated ids of one request, as the capture records them.
#[derive(Clone, Copy)]
pub(super) struct CapturedIds<'a> {
@@ -265,9 +270,8 @@ pub(super) fn capture_request(
let CapturedIds { prompt, generated } = ids;
static NEXT: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(1);
let index = NEXT.fetch_add(1, Ordering::Relaxed);
let join = |ids: &mut dyn Iterator<Item = i64>| ids.map(|t| t.to_string()).collect::<Vec<_>>().join(",");
let prompt_line = join(&mut prompt.iter().map(|&t| i64::from(t)));
let generated_line = join(&mut generated.iter().map(|&t| i64::from(t)));
let prompt_line = join_ids(prompt);
let generated_line = join_ids(generated);
let lines = (prompt_line.as_str(), generated_line.as_str());
let json = capture_json(index, request, lines, (rounds, reused, prompt.len(), generated.len()));
if std::fs::create_dir_all(dir).is_err() {
@@ -26,7 +26,7 @@ pub(super) struct ArmShape {
pub(super) flags: ArmFlags,
}
/// 1 when `on` is set, 0 when `off` is, else -1.
fn tri(has: &dyn Fn(&str) -> bool, on: &str, off: &str) -> i8 {
fn tri(has: &impl Fn(&str) -> bool, on: &str, off: &str) -> i8 {
if has(on) {
1
} else if has(off) {
@@ -43,7 +43,7 @@ fn tail_flag(flags: &str) -> Option<u32> {
/// docs/upstream-port-plan.md rows 2.4 / 2.5: `kh` / `rec` / `orig` (the prompt GDN recurrence: the
/// three-value-heads kernel, the two-barrier kernel, the sealed Original one); `wide` / `fast` (the prompt top-k) and
/// `cluster` / `nocluster` (the decode window's top-k on a thread-block cluster) are plain on/off flags.
fn gdn_flag(has: &dyn Fn(&str) -> bool) -> i8 {
fn gdn_flag(has: &impl Fn(&str) -> bool) -> i8 {
if has("kh") {
1
} else if has("rec") {
@@ -113,7 +113,7 @@ impl ArmFlags {
}
/// `mode@CAP[/BLOCK][!flag...]`: the mode may carry the arm's own prefill chunk and grid: `reply@8192` (chunk 8192,
/// grid = chunk) or `reply@8192/2048`. A bare mode takes `default_capacity()`.
pub(super) fn parse(arm: &str, default_capacity: &dyn Fn() -> usize) -> ArmShape {
pub(super) fn parse(arm: &str, default_capacity: &impl Fn() -> usize) -> ArmShape {
let Some((mode, shape)) = arm.split_once('@') else {
let flags = ArmFlags::environment();
return ArmShape { mode: arm.to_owned(), capacity: default_capacity(), block: 0, tiers: None, flags };
@@ -26,7 +26,7 @@ fn verify_shard1(config: &NativeBackendConfig, clock: &impl Clock) -> Result<Ver
fn verify_kar_archive(archive: &InheritedKarArchive, clock: &impl Clock) -> InputResultKar {
let started = clock.now();
let result = crate::model_binding::qwen4exp_kar_ple::load_pinned_inherited_archive(archive);
let result = crate::model_binding::kar_ple_source::load_pinned_inherited_archive(archive);
crate::load_clock::span("kar_inspect_verify", started);
result
}
@@ -67,7 +67,7 @@ pub(super) fn emit_terminal(
/// says so or the reader is gone.
pub(super) fn emit_event(
sink: &GenerationSink,
cancelled: &dyn Fn() -> bool,
cancelled: &impl Fn() -> bool,
clock: &impl Clock,
event: GenerationEvent,
) -> Result<(), GenerationFailure> {
+4 -3
View File
@@ -4,6 +4,7 @@
//!
//! `lap` times a phase of the loading thread since the previous lap; `span` times a phase that ran on
//! another thread (the parallel verifications), so overlapping phases can be told apart in the log.
use leleka_obs::time::{Clock as _, SystemClock};
use std::{
io::Write,
sync::Mutex,
@@ -28,7 +29,7 @@ fn emit(phase: &str, seconds: Duration, total: Duration) {
/// Start the clock of one load.
pub(crate) fn begin() {
let now = Instant::now();
let now = SystemClock.now();
if let Ok(mut clock) = CLOCK.lock() {
*clock = Some(Clock { start: now, last: now });
}
@@ -36,7 +37,7 @@ pub(crate) fn begin() {
/// The phase of the calling thread that ended now, started at the previous lap.
pub(crate) fn lap(phase: &str) {
let now = Instant::now();
let now = SystemClock.now();
if let Ok(mut guard) = CLOCK.lock()
&& let Some(clock) = guard.as_mut()
{
@@ -49,7 +50,7 @@ pub(crate) fn lap(phase: &str) {
/// A phase that started at `started` (possibly on another thread) and ended now. Does not move the lap mark.
pub(crate) fn span(phase: &str, started: Instant) {
let now = Instant::now();
let now = SystemClock.now();
if let Ok(guard) = CLOCK.lock()
&& let Some(clock) = guard.as_ref()
{
@@ -140,9 +140,9 @@ fn fixed_items(g: &Governor, args: &StartArgs, settings: &Settings) -> Vec<Fixed
fn kar_form(args: &StartArgs) -> KarForm {
match args.kar_file_backed {
Some(true) => KarForm::File { bytes: crate::model_binding::qwen4exp_kar_ple::PINNED_ARCHIVE_BYTES },
Some(true) => KarForm::File { bytes: crate::model_binding::kar_ple_source::PINNED_ARCHIVE_BYTES },
_ => KarForm::MemfdInherited {
bytes: args.kar_sparse_bytes.unwrap_or(crate::model_binding::qwen4exp_kar_ple::PINNED_ARCHIVE_BYTES),
bytes: args.kar_sparse_bytes.unwrap_or(crate::model_binding::kar_ple_source::PINNED_ARCHIVE_BYTES),
},
}
}
@@ -190,7 +190,7 @@ pub(crate) fn startup(args: &StartArgs, settings: &Settings) -> Result<&'static
#[cfg(all(target_os = "linux", target_arch = "x86_64"))]
pub(crate) fn guard_archive(
g: &Governor,
archive: &crate::model_binding::qwen4exp_kar_ple::InheritedKarArchive,
archive: &crate::model_binding::kar_ple_source::InheritedKarArchive,
) -> Result<(), BackendError> {
use std::os::fd::AsFd;
if archive.file_backed() {
@@ -201,7 +201,7 @@ pub(crate) fn guard_archive(
let extents = archive.sparse_extents();
g.guard_archive_extents(
archive.archive_handle().as_fd(),
crate::model_binding::qwen4exp_kar_ple::PINNED_ARCHIVE_BYTES,
crate::model_binding::kar_ple_source::PINNED_ARCHIVE_BYTES,
extents.as_deref(),
)
.map(|_| ())
@@ -225,7 +225,7 @@ fn archive_inventory(extents: Option<&[(u64, u64)]>) -> (u64, &'static str) {
(PLE rows, header, directory); the rest is a hole",
),
None => (
crate::model_binding::qwen4exp_kar_ple::PINNED_ARCHIVE_BYTES,
crate::model_binding::kar_ple_source::PINNED_ARCHIVE_BYTES,
"the pinned level-2 archive, sealed memfd (55,295,529,472 B), shared with the holder",
),
}
@@ -389,7 +389,7 @@ pub(crate) fn complement_room(available: u64) -> u64 {
#[cfg(target_os = "windows")]
pub(crate) fn guard_archive(
_g: &Governor,
_archive: &crate::model_binding::qwen4exp_kar_ple::InheritedKarArchive,
_archive: &crate::model_binding::kar_ple_source::InheritedKarArchive,
) -> Result<(), BackendError> {
Ok(())
}
@@ -1,4 +1,5 @@
//! Page-cache release after the load (`drop_file_cache`), moved out of `memory_governor` by STRA-338 (size).
//! Page-cache release after the load (`drop_file_cache`): the kernel gets the pages of the shard files back once the
//! weights are on the device.
use super::{Governor, HostFacts, HostProc};
@@ -1,6 +1,6 @@
//! Explicit, immutable experimental PLE source. This module never owns CUDA or sessions.
#![allow(dead_code)]
use super::qwen4exp_input::{BindingIdentity, InputBindingError, InputResult, PLE_ROWS};
use super::weight_binding::{BindingIdentity, InputBindingError, InputResult, PLE_ROWS};
use leleka_model_format::kar::{
KarError, KarPlePartProvenance, KarPleProfile, KarPleProfileSpec, VerifiedKarPleArtifact,
};
@@ -1,5 +1,5 @@
//! Methods of `InheritedKarArchive`: `open`, `open_sparse`, `open_sparse`, `sparse_extents` and 7 more.
//! Functions: `open_sealed_archive_fd`, `open_read_only_archive`, `check_read_only_archive`, `reopen_read_only_archi...
//! The KAR PLE archive handed down by the parent process: a sealed memfd, a sparse extent map or an ordinary read-only
//! file. Opening it checks the kind, length, links, owner and permission bits; readers are independent reopens of it.
use super::{
ARCHIVE_DIGEST, File, InheritedKarArchive, InputBindingError, InputResult, PINNED_ARCHIVE_BYTES, PROVENANCE_DIGEST,
@@ -1,5 +1,5 @@
//! Methods of `KarRowPacket`: `payload`, `partition`. Methods of `KarRowReader`: `read_rows`.
//! Functions: `open_archive_reader`, `load_pinned_inherited_archive`, `log_startup_read`, `load_pinned_inherited_arc...
//! Loads the verified PLE artifact from the inherited archive: the read handle, the startup log line of what was read,
//! and the row packets and readers the PLE cache takes its rows from. Windows keeps only the file-backed form.
use super::{
BindingIdentity, File, InheritedKarArchive, InputBindingError, InputResult, KarError, KarPleBinding, KarRowPacket,
@@ -1,5 +1,5 @@
//! Methods of `InheritedKarArchive`: `expert_capture_observation`.
//! Functions: `pinned_profile`, `pinned_parts`, `pinned_profile_spec`, `load_pinned_archive` and 3 more.
//! The pinned KAR PLE profile: the conversion receipts it expects, the partition of the rows, and the verification of
//! the archive against them. Linux freezes a private inode before inspection; other platforms refuse the path form.
use super::{
ARCHIVE_DIGEST, File, InheritedKarArchive, InputBindingError, InputResult, KarPlePartProvenance, KarPleProfile,
@@ -1,5 +1,5 @@
//! Implements `Write for BrokenSink`.
//! Functions: `diagnostic_cases`, `assert_kar_diagnostic_redacts`, `assert_input_diagnostic_survives_broken_sink`, `...
//! Pins the PLE profile: its numbers match the independent conversion receipts, the partitions cover the rows exactly,
//! and load diagnostics redact their causes yet keep the typed failure even when the diagnostic sink is broken.
use super::{
InputBindingError, KarError, LoadPhase, NATIVE_DIGESTS, PLE_ROWS, error, input_diagnostic, kar_diagnostic,
@@ -1,5 +1,5 @@
//! Defines `Inode`, `IoPhase`, `OwnedCopy`.
//! Split out of `qwen4exp_kar_ple` to keep its files under the line limit.
//! Types of the private copy: the inode identity, the I/O phase a failure is reported against, and `OwnedCopy`, the
//! handle that removes its file when dropped. The operations are in `inode` and `checked_reader`.
use super::{InputBindingError, InputResult, LoadPhase, input_failure};
#[cfg(target_os = "linux")]
@@ -1,5 +1,5 @@
//! Functions: `checked_reader`, `copy_exact`, `copy_exact_reporting`, `copy_buffer` and 1 more.
//! Split out of `private_copy` to keep its files under the line limit.
//! Reading side of the private copy: a checked reader over the frozen inode and `copy_exact`, which copies exactly the
//! pinned byte count and refuses a source that holds more.
use super::{COPY_BUFFER, InputBindingError, InputResult, IoPhase, LoadPhase, Read, Write, input_failure, report_io};
#[cfg(not(target_os = "linux"))]
@@ -1,5 +1,5 @@
//! Methods of `OwnedCopy`: `create`, `created`, `writer`, `detach` and 2 more. Implements `Drop for OwnedCopy`.
//! Functions: `inode`, `diagnostic`, `report_io`, `phase_error` and 8 more.
//! The private copy of a source file as an owned inode: create, write, seal, reopen read-only and detach, with the
//! checks that the sealed inode is the one this owner created and that no name refers to it any more.
use super::{
File, Inode, InputBindingError, InputResult, IoPhase, LoadPhase, Metadata, MetadataExt, OpenOptions,
@@ -1,5 +1,5 @@
//! Functions: `io_error`, `open_regular`, `open_read_only_archive`, `check_len` and 3 more.
//! Split out of `qwen4exp_kar_ple` to keep its files under the line limit.
//! Windows form of the inherited archive: a regular file opened with a sharing mode that keeps writers out, a length
//! check, independent positional reopens and the provenance digest check.
use super::{InputBindingError, InputResult};
use std::{
@@ -3,8 +3,8 @@
pub(crate) mod kar_expert_source;
pub(crate) mod kar_levels;
pub(crate) mod qwen4exp_input;
pub(crate) mod qwen4exp_kar_ple;
pub(crate) mod kar_ple_source;
pub(crate) mod weight_binding;
#[cfg(test)]
#[path = "../../tests/stra161_reference.rs"]
@@ -103,7 +103,7 @@ pub(crate) struct ModelBinding {
layers: Box<[BoundLayer]>,
expert_count: u32,
expert_used_count: u32,
kar_ple: Option<super::qwen4exp_kar_ple::KarPleBinding>,
kar_ple: Option<super::kar_ple_source::KarPleBinding>,
kar_experts: Option<super::kar_expert_source::KarExpertSource>,
mtp: Option<MtpWeights>,
/// Lazily opened batched PLE reader; `None` inside means synchronous reads.
@@ -145,7 +145,7 @@ mod native_output;
#[cfg(all(any(target_os = "linux", target_os = "windows"), target_pointer_width = "64"))]
pub(crate) use native_output::NativeOutputRole;
mod binding_identity_and_input_binding_error;
mod binding_identity;
mod model_binding;
mod validate_ple_descriptor;
use validate_ple_descriptor::bind_layers;
@@ -45,7 +45,7 @@ impl ModelBinding {
kar: leleka_model_format::kar::VerifiedKarPleArtifact,
) -> InputResult<Self> {
let mut binding = Self::from_artifact(artifact)?;
binding.kar_ple = Some(super::super::qwen4exp_kar_ple::KarPleBinding::new(&binding.identity, kar)?);
binding.kar_ple = Some(super::super::kar_ple_source::KarPleBinding::new(&binding.identity, kar)?);
Ok(binding)
}
/// Select the KAR routed-expert weight source before publishing the
@@ -68,7 +68,7 @@ impl ModelBinding {
pub(crate) fn kar_expert_source(&self) -> Option<&super::super::kar_expert_source::KarExpertSource> {
self.kar_experts.as_ref()
}
pub(crate) fn kar_ple_binding(&self) -> Option<&super::super::qwen4exp_kar_ple::KarPleBinding> {
pub(crate) fn kar_ple_binding(&self) -> Option<&super::super::kar_ple_source::KarPleBinding> {
self.kar_ple.as_ref()
}
/// Operator paths are consumed inside model binding, never from a request.
@@ -78,7 +78,7 @@ impl ModelBinding {
source: &std::path::Path,
owner_root: &std::path::Path,
) -> InputResult<Self> {
let kar = super::super::qwen4exp_kar_ple::load_pinned_archive(source, owner_root)?;
let kar = super::super::kar_ple_source::load_pinned_archive(source, owner_root)?;
Self::from_artifact_with_kar_ple(artifact, kar)
}
pub(crate) fn expert_count(&self) -> u32 {
@@ -87,9 +87,9 @@ impl ModelBinding {
pub(crate) fn from_artifact_with_inherited_kar_ple(
artifact: Qwen4ExpArtifact,
source: &super::super::qwen4exp_kar_ple::InheritedKarArchive,
source: &super::super::kar_ple_source::InheritedKarArchive,
) -> InputResult<Self> {
let kar = super::super::qwen4exp_kar_ple::load_pinned_inherited_archive(source)?;
let kar = super::super::kar_ple_source::load_pinned_inherited_archive(source)?;
Self::from_artifact_with_kar_ple(artifact, kar)
}
@@ -140,7 +140,7 @@ impl ModelBinding {
/// Both providers are fully admitted before publishing this fresh binding.
pub(crate) fn from_artifact_with_inherited_kar_mtp(
artifact: Qwen4ExpArtifact,
source: &super::super::qwen4exp_kar_ple::InheritedKarArchive,
source: &super::super::kar_ple_source::InheritedKarArchive,
mtp_source: &std::path::Path,
mtp_root: &std::path::Path,
) -> InputResult<Self> {
@@ -37,24 +37,24 @@ use read_expert_rows::read_expert_rows;
use read_expert_rows::row_range;
use read_expert_rows::validate_numeric;
mod mtp_kind_types;
use mtp_kind_types::Dense;
use mtp_kind_types::Descriptor;
pub(crate) use mtp_kind_types::MtpExpertMatrix;
pub(crate) use mtp_kind_types::MtpExpertRef;
pub(crate) use mtp_kind_types::MtpKind;
pub(crate) use mtp_kind_types::MtpRole;
mod descriptors_types;
use descriptors_types::DESCRIPTORS;
mod dense_bytes_types;
use dense_bytes_types::DENSE_BYTES;
use dense_bytes_types::EXPERT_BLOB;
use dense_bytes_types::EXPERT_BYTES;
use dense_bytes_types::FILE_PINS;
use dense_bytes_types::INDEX_BYTES;
use dense_bytes_types::INDEX_LIMIT;
use dense_bytes_types::MAX_READ;
use dense_bytes_types::MAX_ROWS;
use dense_bytes_types::MtpIndex;
pub(crate) use dense_bytes_types::MtpRows;
pub(crate) use dense_bytes_types::MtpWeights;
mod pack_vocabulary;
use pack_vocabulary::Dense;
use pack_vocabulary::Descriptor;
pub(crate) use pack_vocabulary::MtpExpertMatrix;
pub(crate) use pack_vocabulary::MtpExpertRef;
pub(crate) use pack_vocabulary::MtpKind;
pub(crate) use pack_vocabulary::MtpRole;
mod tensor_table;
use tensor_table::DESCRIPTORS;
mod pack_pins;
use pack_pins::DENSE_BYTES;
use pack_pins::EXPERT_BLOB;
use pack_pins::EXPERT_BYTES;
use pack_pins::FILE_PINS;
use pack_pins::INDEX_BYTES;
use pack_pins::INDEX_LIMIT;
use pack_pins::MAX_READ;
use pack_pins::MAX_ROWS;
use pack_pins::MtpIndex;
pub(crate) use pack_pins::MtpRows;
pub(crate) use pack_pins::MtpWeights;
@@ -1,5 +1,5 @@
//! Methods of `OwnedCopy`: `create`, `writer`, `owns_directory`, `owns_file` and 1 more.
//! Implements `Drop for OwnedCopy`. Functions: `inode`, `regular`, `root`, `copy_exact` and 8 more.
//! Linux and macOS test-build backing of the MTP pack: the pinned file is copied into a private, sealed, unlinked inode
//! (`OwnedCopy`) that the verifier reads, so a writer of the source can no longer change what was verified.
#[cfg(test)]
use super::{EXPERT_BLOB, MtpExpertMatrix, MtpKind, read_exact_range, read_expert_rows};
@@ -1,5 +1,5 @@
//! Functions: `read_expert_rows`, `read_expert_row`, `row_range`, `allocate` and 3 more.
//! Split out of `mtp` to keep its files under the line limit.
//! Reads the rows of one MTP expert matrix from the pinned pack: range arithmetic, positional reads on the frozen copy,
//! the interleave of the Q2 codes and scales, and the finiteness check of what was read.
#[cfg(not(target_os = "linux"))]
use super::backing;
@@ -1,5 +1,5 @@
//! The expert a projection, a cache fill or a loan refers to.
use crate::model_binding::qwen4exp_input::{ModelBinding, MoeExpertSelection, MoeExpertWeights};
use crate::model_binding::weight_binding::{ModelBinding, MoeExpertSelection, MoeExpertWeights};
/// One expert (a routed slot or the shared expert) of validated expert weights, under the binding that admitted
/// them. The three always travel together: weights are only meaningful for their binding, and the selection says
@@ -2,7 +2,7 @@
// These declarations intentionally have no production caller until leaf handoff.
#![allow(dead_code)]
use crate::model_binding::qwen4exp_input::BindingError;
use crate::model_binding::weight_binding::BindingError;
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum Stage {
@@ -238,7 +238,7 @@ impl TokenLayer {
#[cfg(test)]
mod tests {
use super::*;
use crate::model_binding::qwen4exp_input::ModelBinding;
use crate::model_binding::weight_binding::ModelBinding;
#[test]
fn positive_dimensions_have_checked_driver_representations() {
@@ -1,6 +1,6 @@
//! Safe actor-side source association; native ownership lives in the leaf crate.
//! Returned bytes are NOT source/current-row/Context/publication certificates.
use crate::model_binding::qwen4exp_input::{
use crate::model_binding::weight_binding::{
BindingIdentity, InputBindingError, ModelBinding, MoeMatrixRole, MoeRoutedSourceScope, MoeWeightDescriptor,
};
use leleka_native_cpu_expert::{
@@ -8,7 +8,7 @@ use super::qsa_index::{QsaIndexKeyCache, QsaPrior, QsaSelectedCache};
use super::qsa_index::{QsaInputLease, QsaInputScratch};
use super::qsa_index::{binding_error, driver_error};
use super::router_scratch::{RouterLease, RouterScratch};
use crate::model_binding::qwen4exp_input::{
use crate::model_binding::weight_binding::{
BindingIdentity, BoundLayerKind, GdnMatrixKind, GdnMatrixRole, GdnWeights, GrRole, GrWeights, ModelBinding,
PleMatrixRole, PleWeights, QsaMatrixKind, QsaMatrixRole, QsaWeights,
};
@@ -96,7 +96,7 @@ pub(crate) struct DenseWeightCache<'ctx> {
mod dense_slab_policy;
mod workspaces;
use workspaces::Workspaces;
mod dense_weight_cache_methods;
mod dense_cache_ops;
use dense_slab_policy::dense_slab_policy;
#[cfg(all(any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
use dense_slab_policy::startup_step;
@@ -12,10 +12,10 @@ use super::{
SlabAllocator, SlabPolicy, Workspaces, binding_error, dense_slab_policy, driver_error, startup_step,
};
mod dense_cache_buffers_and_close;
mod dense_cache_eager_layer_load;
mod dense_cache_gdn_qsa_workspaces;
mod dense_cache_matrix_registration;
mod dense_cache_ple_and_verify_weights;
mod dense_cache_prompt_and_gdn_scratch;
mod dense_cache_prompt_capacity;
mod dense_cache_teardown;
mod dense_cache_weight_views;
mod dense_weight_cache_constructors;
@@ -16,7 +16,7 @@ use super::{
qsa_index::{QsaIndexStage, QsaPrepareRequest},
session::{QwenSession, QwenStepTxn, TargetStepOrigin},
};
use crate::model_binding::qwen4exp_input::{BindingIdentity, BoundLayerKind, ModelBinding};
use crate::model_binding::weight_binding::{BindingIdentity, BoundLayerKind, ModelBinding};
type StepCoreResult = (Option<TokenId>, Option<Box<[f32]>>);
@@ -51,7 +51,7 @@ pub(crate) struct PrefillStepProduct {
/// All helpers disappear from serving builds. No tensor words enter logs or
/// assertion formatting; only equality and bounded counts are reported.
#[cfg(all(test, any(target_os = "linux", target_os = "windows"), target_arch = "x86_64"))]
mod reset_replay_sdet;
mod reset_replay_proof;
/// Fixed operator labels only; diagnostics never contain request/model data.
#[derive(Debug)]
@@ -126,7 +126,13 @@ pub(in crate::qwen_forward) struct NoPromptHooks;
/// [`PromptPlan`](crate::backend::original_prompt::PromptPlan) is walked by `drive`; every `Batched` action is one
/// real `OriginalPromptExecutor::forward` + `publish` transaction on the shared arena/session/draft, so the chunk loop
/// of `Prefill::run` is the action sequence. This is an unselected source owner: nothing in `backend` constructs it.
pub(in crate::qwen_forward) struct OriginalPromptComposer<'a, 'arena, 'ctx> {
pub(in crate::qwen_forward) struct OriginalPromptComposer<
'a,
'arena,
'ctx,
C: FnMut() -> bool,
H: OriginalPromptHooks + ?Sized,
> {
pub executor: &'a mut OriginalPromptExecutor<'ctx>,
pub binding: &'a ModelBinding,
pub dense: &'a DenseWeightCache<'ctx>,
@@ -139,8 +145,8 @@ pub(in crate::qwen_forward) struct OriginalPromptComposer<'a, 'arena, 'ctx> {
pub embedding: &'a OriginalPromptEmbedding<'ctx>,
pub policy: &'a OriginalMtpScalarPolicy,
/// `should_stop` of the Original; also forwarded into every chunk's draft-KV recording.
pub cancel: &'a mut dyn FnMut() -> bool,
pub hooks: &'a mut dyn OriginalPromptHooks,
pub cancel: &'a mut C,
pub hooks: &'a mut H,
/// The last chunk's publication (new origin and the known-next sample), for the caller's first decode window.
pub last_published: Option<(TargetStepOrigin, Option<TokenId>)>,
}
@@ -16,6 +16,6 @@ use super::{
SpanExport, Stage, StagedInput, TokenId, driver_error, prof, staged_input_enabled,
};
mod construction_and_parking;
mod prompt_executor_forward_and_close;
mod chunk_run;
mod executor_lifecycle;
mod prompt_executor_retire_owners;
@@ -5,7 +5,7 @@ use super::{
OriginalPromptExecutor, OriginalPromptTxn, PStage, PromptDeviceNormedRows, PromptDeviceRows, PromptWeights,
QsaLayerDevices, Result, prof,
};
use crate::model_binding::qwen4exp_input::BoundLayer;
use crate::model_binding::weight_binding::BoundLayer;
use crate::qwen_forward::gr::GrRole;
use crate::qwen_forward::prompt_device_rows::PromptDeviceRead;
@@ -41,7 +41,9 @@ impl Drop for OriginalPromptPending<'_, '_, '_> {
}
}
impl OriginalPromptHooks for NoPromptHooks {}
impl crate::backend::original_prompt::PromptRunner for OriginalPromptComposer<'_, '_, '_> {
impl<C: FnMut() -> bool, H: OriginalPromptHooks + ?Sized> crate::backend::original_prompt::PromptRunner
for OriginalPromptComposer<'_, '_, '_, C, H>
{
type Error = Error;
fn cancelled(&mut self) -> bool {
(self.cancel)()
@@ -75,10 +77,10 @@ impl crate::backend::original_prompt::PromptRunner for OriginalPromptComposer<'_
}
/// Runs `plan` to its final seed through `composer`. `admitted_capacity` is the capacity the executor, arena and cache
/// were built for. Cancellation maps to the same refusal `forward` returns when its draft recording is cancelled.
pub(in crate::qwen_forward) fn run_original_prompt(
pub(in crate::qwen_forward) fn run_original_prompt<C: FnMut() -> bool, H: OriginalPromptHooks + ?Sized>(
plan: crate::backend::original_prompt::PromptPlan<'_>,
admitted_capacity: usize,
composer: &mut OriginalPromptComposer<'_, '_, '_>,
composer: &mut OriginalPromptComposer<'_, '_, '_, C, H>,
) -> Result<crate::backend::original_prompt::DriveSummary> {
use crate::backend::original_prompt::{DriveError, drive};
drive(plan, admitted_capacity, composer).map_err(|e| match e {
@@ -2,7 +2,7 @@
//! Q6K matrices (GDN or QSA roles), giving the projected columns per row for the retained GR bank.
use super::{BoundLayerKind, DenseWeightCache, Error, LayerId, ModelBinding, QwenChunkTxn, Result};
use crate::model_binding::qwen4exp_input::{GdnMatrixKind, GdnMatrixRole, QsaMatrixKind, QsaMatrixRole};
use crate::model_binding::weight_binding::{GdnMatrixKind, GdnMatrixRole, QsaMatrixKind, QsaMatrixRole};
use crate::qwen_forward::gr::ResidualReady;
use crate::qwen_forward::prompt_device_rows::PromptWeights;
use crate::qwen_forward::q6_attention_columns::{self, ColumnKey, ColumnTarget, ProjectionRow, Role};

Some files were not shown because too many files have changed in this diff Show More