From 7eb69e62512cda954a1ce934abf8690c07af27c7 Mon Sep 17 00:00:00 2001 From: jars Date: Sat, 9 May 2026 12:41:23 +0100 Subject: [PATCH] refactor(core): remove old inference_thread_count facade The MIN_INFERENCE_THREADS, MAX_INFERENCE_THREADS, and inference_thread_count() defined in constants.rs were superseded by the equivalents in tuning.rs (Task 2.1) and are no longer called by any production code. Both call sites (whisper backend Task 4.1, LLM generate Task 5.1) have migrated. Constants.rs now holds only audio/mel/RAM/VAD/download constants; inference-tuning concerns live in tuning.rs. Co-Authored-By: Claude Opus 4.7 (1M context) --- crates/core/src/constants.rs | 51 ------------------------------------ 1 file changed, 51 deletions(-) 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) -}