From 875dd12ddf90b14a7f4b598e4baba23ca3de2f8a Mon Sep 17 00:00:00 2001 From: Pavlo Ratushnyi Date: Wed, 14 Oct 2026 16:51:05 +0200 Subject: [PATCH] fix(kar): do not refuse KAR routed experts just because the serving MoE cache exists The serving backend always constructs a MoeWeightCache and step_cached passes Some(cache) to MoeExpertStage::execute on every token. The KAR branch returned IdentityMismatch whenever a cache was present, so with kar_expert_source set every token failed at layer 0 and the feature was unreachable from serve_load. The KAR branch never consults the cache for routed experts; it now ignores it (the shared expert takes the existing uncached projection path). Co-Authored-By: Claude Sonnet 5.5 --- .../src/qwen_forward/moe_expert.rs | 35 +++++++++---------- 1 file changed, 17 insertions(+), 18 deletions(-) diff --git a/crates/leleka-runtime/src/qwen_forward/moe_expert.rs b/crates/leleka-runtime/src/qwen_forward/moe_expert.rs index 7a50c2a3..4189c8da 100644 --- a/crates/leleka-runtime/src/qwen_forward/moe_expert.rs +++ b/crates/leleka-runtime/src/qwen_forward/moe_expert.rs @@ -106,24 +106,23 @@ impl MoeExpertStage { // One immutable, step-local owner only on the explicitly selected // cache path. It never enters the weight cache or recurrence state. let (result, prepared_close) = if let Some(kar) = binding.kar_expert_source() { - // Routed experts come from the KAR archive; the optimized MMQ - // weight cache is a different owner and is refused, not mixed. - if cache.is_some() { - (Err(Error::IdentityMismatch), Ok(())) - } else { - ( - execute_cuda_kar( - context, - binding, - &weights, - &activation, - &route, - input.mixed(), - (layer.get(), kar), - ), - Ok(()), - ) - } + // Routed experts come from the KAR archive and never touch the MMQ + // weight cache. The serving backend always owns a cache and hands + // it to every step, so a present cache cannot be a reason to + // refuse: it is simply not consulted for any expert here (the + // shared expert takes the uncached path inside the KAR branch). + ( + execute_cuda_kar( + context, + binding, + &weights, + &activation, + &route, + input.mixed(), + (layer.get(), kar), + ), + Ok(()), + ) } else if cache.is_some() { match context.prepare_routed_gate_up_q8(&activation) { Ok(prepared) => {