diff --git a/crates/engine-qwen35-cuda/src/qwen_forward/cache_original_prompt/impl_moeweightcache.rs b/crates/engine-qwen35-cuda/src/qwen_forward/cache_original_prompt/impl_moeweightcache.rs index 24a2945a..77b14e07 100644 --- a/crates/engine-qwen35-cuda/src/qwen_forward/cache_original_prompt/impl_moeweightcache.rs +++ b/crates/engine-qwen35-cuda/src/qwen_forward/cache_original_prompt/impl_moeweightcache.rs @@ -3,6 +3,18 @@ #[allow(unused_imports)] use super::*; +/// The prefill layout options of the arena and the validated u32 capacity carved from them. +struct ArenaPlan { + options: leleka_cuda_driver::PrefillLayoutOptions, + capacity: u32, +} + +/// The resident expert bank lease and the members mapped from it into the registered bank. +struct ExpertBankMapping { + lease: leleka_model_format::qwen4exp::ResidentExpertBankLease, + members: Vec, +} + impl<'ctx> MoeWeightCache<'ctx> { /// Explicit selected factory: real arena-backed MMQ, with no second /// X/weight/GU/H/Q8/Down payload bank or old host-window prefill owner. @@ -20,11 +32,7 @@ impl<'ctx> MoeWeightCache<'ctx> { return Err(Error::InvalidDimension); } crate::bringup_trace!("DBG arena: start capacity={capacity}"); - let (lease, members) = binding.retained_expert_bank_members().map_err(|e| { - crate::bringup_trace!("DBG arena members err: {e:?}"); - binding_error(e) - })?; - crate::bringup_trace!("DBG arena: members ok ({})", members.len()); + let mapping = Self::retained_bank_mapping(binding)?; let workspace = Self::arena_workspace(context, capacity)?; let mut cache = Self::assemble_mmq_with_mtp_experts(binding, context, workspace, mtp_pack_experts) .inspect_err(|e| { @@ -33,13 +41,23 @@ impl<'ctx> MoeWeightCache<'ctx> { crate::bringup_trace!("DBG arena: assemble_mmq ok"); cache.original_prompt_mmq = true; cache.mmq_policy = MmqRoutingPolicy::NativeIntegerIq3; - if let Err(primary) = cache.attach_arena_owners(binding, context, options, capacity, lease, members) { + if let Err(primary) = cache.attach_arena_owners(binding, context, ArenaPlan { options, capacity }, mapping) { let _ = cache.close(); return Err(primary); } Ok(cache) } + /// The retained model bank's lease and members, traced as the arena bring-up steps. + fn retained_bank_mapping(binding: &ModelBinding) -> Result { + let (lease, members) = binding.retained_expert_bank_members().map_err(|e| { + crate::bringup_trace!("DBG arena members err: {e:?}"); + binding_error(e) + })?; + crate::bringup_trace!("DBG arena: members ok ({})", members.len()); + Ok(ExpertBankMapping { lease, members }) + } + /// The original-formats integer MMQ workspace with its expert group arena enabled. fn arena_workspace(context: &'ctx Context<'ctx>, capacity: u32) -> Result> { let mut workspace = context.native_integer_iq3_mmq_original_formats_workspace().map_err(|e| { @@ -59,11 +77,11 @@ impl<'ctx> MoeWeightCache<'ctx> { &mut self, binding: &ModelBinding, context: &'ctx Context<'ctx>, - options: leleka_cuda_driver::PrefillLayoutOptions, - capacity: u32, - lease: leleka_model_format::qwen4exp::ResidentExpertBankLease, - members: Vec, + plan: ArenaPlan, + mapping: ExpertBankMapping, ) -> Result<()> { + let ArenaPlan { options, capacity } = plan; + let ExpertBankMapping { lease, members } = mapping; // Create persistent actual streams/events before model cache fills. // Slot count comes from the same options used to carve the arena. let slots = options.original_ring_slots().map_err(|e| arena_driver_error(2, e))?;