use model_io::{ArchConfig, ResidentIndex};
use crate::real_forward_layout::RoutedLayerLayout;
pub use crate::real_forward_rollback::RollbackPoint;
use crate::real_forward_types::DecodeScratch;
pub use crate::real_forward_types::{dispatch_profile_report, PhaseCounters, RealForwardError};
pub(crate) const EXPERT_CACHE_SLOTS: usize = 16;
pub(crate) const MAX_PREFILL_CHUNK_TOKENS: usize = 128;
pub(crate) const PACKED_LAYOUT_MAX_BYTES: u64 = 64 * 1024 * 1024;
pub(crate) const DEFAULT_MAX_CONTEXT: usize = 4096;
pub struct RealForwardRunner {
pub(crate) kv_prefix: crate::kv_prefix::KvPrefix,
pub(crate) prefix_reuse_enabled: bool,
pub(crate) session_pool: crate::session_pool::SessionPool,
pub(crate) session_slot_evicted: bool,
pub(crate) context: gpu::MetalContext,
pub(crate) weights: gpu::ResidentGpuWeights,
pub(crate) index: ResidentIndex,
pub(crate) arch: ArchConfig,
pub(crate) kv: gpu::KvCacheManager,
pub(crate) scratch: DecodeScratch,
pub(crate) slot_buffers: Vec<Vec<gpu::MetalBuffer>>,
pub(crate) streamers: Vec<Option<streaming::PreadExpertStreamer>>,
pub(crate) mapped: crate::real_forward_init::MappedResidency,
pub(crate) expert_cache_slots: usize,
pub(crate) resolved_residency: model_io::ResolvedExpertResidency,
pub(crate) moe_offsets: Vec<gpu::MoeExpertOffsets>,
pub(crate) routed_blobs: Option<gpu::RoutedBlobsBuffer>,
pub(crate) routed_blobs_banks: Vec<gpu::RoutedBlobsBuffer>,
pub(crate) real: Option<crate::families::gemma4::RealGemmaState>,
pub(crate) real_qwen: Option<crate::families::qwen::RealQwenState>,
pub(crate) real_mtp: Option<crate::families::qwen::MtpState>,
pub(crate) real_dflash: Option<crate::families::qwen::DflashState>,
pub(crate) batched_tape: Option<crate::real_forward_rollback::VerifyTape>,
pub(crate) batched_tape_row0: Option<Vec<u8>>,
pub(crate) real_llama: Option<crate::families::llama::RealLlamaState>,
pub(crate) real_deepseek2: Option<crate::families::deepseek2::RealDeepseek2State>,
pub(crate) real_gpt_oss: Option<crate::families::gptoss::RealGptOssState>,
pub(crate) real_muse: Option<crate::families::museglimmer::RealMuseState>,
pub(crate) real_spark: Option<crate::families::spark::RealSparkState>,
pub(crate) real_qwen4: Option<crate::families::qwen4::RealQwen4State>,
pub(crate) phases: PhaseCounters,
pub(crate) shared_cb_overlap: bool,
pub(crate) routed_pipeline: bool,
pub(crate) routed_batch_prefill: bool,
pub(crate) batched_gemv_prefill: bool,
pub(crate) routed_layouts: Vec<RoutedLayerLayout>,
pub(crate) router_hist: Option<crate::router_hist::RouterHistogram>,
pub(crate) ffn_hist: Option<crate::ffn_hist::FfnActHist>,
pub(crate) resid_capture: Option<crate::resid_capture::ResidCapture>,
pub(crate) prefill_chunk_is_final: bool,
pub(crate) steering: Option<crate::steering::SteeringState>,
pub(crate) install_dir: std::path::PathBuf,
pub(crate) vision: Option<crate::vision::VisionTower>,
pub(crate) vision_sidecar_dir: Option<std::path::PathBuf>,
pub(crate) prompt_vision: Option<crate::vision::PromptVision>,
pub(crate) skip_head: bool,
}