diff --git a/crates/core/src/constants.rs b/crates/core/src/constants.rs index 0286432..36a0525 100644 --- a/crates/core/src/constants.rs +++ b/crates/core/src/constants.rs @@ -18,22 +18,6 @@ pub const MIN_CHUNK_SAMPLES: usize = 8000; /// Post-processing thresholds. pub const SMART_PARAGRAPH_GAP_SECS: f64 = 2.0; -/// Lower bound for inference threads. Single-threaded inference is -/// measurably worse than two on every multi-core part; we never go below -/// 2. (Whisper Tiny is the exception where the work is so small that -/// thread count barely matters — but the floor still costs nothing.) -pub const MIN_INFERENCE_THREADS: usize = 2; - -/// Upper bound for inference threads. Both whisper.cpp and llama.cpp -/// scaling flattens around physical core count; SMT siblings contend -/// for shared FPU resources during heavy F16/F32 matmul, which means -/// going past physical cores often anti-scales. Empirical evidence: -/// whisper.cpp issue #200 (sweet spot at 7t on 8c/16t Ryzen 3700X), -/// llama.cpp #3167 ("SMT hurts inference"). 8 is a conservative -/// ceiling that leaves <5% on the table for big-iron desktops while -/// keeping consumer 6c/12t laptops out of contention territory. -pub const MAX_INFERENCE_THREADS: usize = 8; - /// History limits. pub const HISTORY_MAX_ENTRIES: usize = 100; @@ -52,38 +36,3 @@ pub const VAD_SPEECH_PAD_MS: u32 = 100; /// Model download chunk size for progress reporting. pub const DOWNLOAD_CHUNK_BYTES: usize = 65_536; - -/// Inference thread count, clamped to physical-core budget. -/// -/// Returns the system's physical-core count, clamped to -/// `[MIN_INFERENCE_THREADS, MAX_INFERENCE_THREADS]`. Uses physical -/// rather than logical cores because SMT/hyperthreaded siblings -/// contend for shared FPU resources during heavy matmul; counting -/// them as additional workers is well-documented to anti-scale on -/// both whisper.cpp and llama.cpp. -/// -/// Falls back to `available_parallelism` only if the physical-core -/// probe is unavailable (some non-Linux/non-Windows platforms or -/// containerised environments). -/// -/// Users can override at runtime by setting -/// `MAGNOTIA_INFERENCE_THREADS=N` — useful for benchmarking and for -/// users on big-iron desktops who want to push past the cap. -pub fn inference_thread_count() -> usize { - if let Ok(s) = std::env::var("MAGNOTIA_INFERENCE_THREADS") { - if let Ok(n) = s.parse::() { - if n > 0 { - return n; - } - } - } - let physical = num_cpus::get_physical(); - let chosen = if physical > 0 { - physical - } else { - std::thread::available_parallelism() - .map(|p| p.get()) - .unwrap_or(MIN_INFERENCE_THREADS) - }; - chosen.clamp(MIN_INFERENCE_THREADS, MAX_INFERENCE_THREADS) -}