How to Override Hardware Detection in llmfit Using CLI Flags
Use --memory, --ram, and --cpu-cores flags to replace llmfit's automatic hardware detection with user-specified values before any model-fit analysis runs.
The llmfit CLI tool automatically discovers your system's RAM, CPU cores, and GPU VRAM through the SystemSpecs::detect() routine in llmfit-core/src/hardware.rs. When this auto-detection fails—common in containerized environments, headless servers with missing drivers, or when evaluating different target hardware—you can override these values directly from the command line.
Available Hardware Override Flags
llmfit exposes four global flags that apply across all subcommands (fit, recommend, plan, etc.). These are defined in the Cli struct in llmfit-tui/src/main.rs and processed by the detect_specs helper function.
| Flag | Overrides | Input Format | Parser Location |
|---|---|---|---|
--ram <SIZE> |
System RAM total | 64G, 128000M, 1T |
llmfit_core::hardware::parse_memory_size |
--memory <SIZE> |
GPU VRAM or unified memory | Same as above | Same parser |
--cpu-cores <N> |
CPU core count | Plain integer | parse_positive_usize |
--max-context <TOKENS> |
Context-length cap for memory estimation | Integer | Direct u32 parsing |
How Overrides Are Applied
The override mechanism lives in llmfit-tui/src/main.rs lines 50-92. The HardwareOverrides struct collects CLI values:
pub(crate) struct HardwareOverrides {
pub memory: Option<String>,
pub ram: Option<String>,
pub cpu_cores: Option<usize>,
}
The detect_specs function applies these in sequence:
- Base detection —
SystemSpecs::detect()runs first - RAM override — If
--ramprovided, parsed and applied viawith_ram_override(gb)(lines 63-66) - GPU memory override — If
--memoryprovided, applied viawith_gpu_memory_override(gb)(lines 75-78) - CPU core override — If
--cpu-coresprovided, applied viawith_cpu_core_override(cores)(lines 87-89)
The context limit is resolved separately through resolve_context_limit (lines 94-102), checking --max-context first, then falling back to OLLAMA_CONTEXT_LENGTH.
Practical CLI Examples
Force GPU VRAM when nvidia-smi is unavailable:
llmfit fit --memory 24G
Test model recommendations against high-RAM target hardware:
llmfit recommend --ram 128G
Simulate multi-core CPU environment:
llmfit fit --cpu-cores 32
Combine multiple overrides for "what-if" scenario planning:
llmfit recommend \
--memory 16G \
--ram 64G \
--cpu-cores 24 \
--max-context 8192
Error Handling and Fallbacks
When a value fails parsing, llmfit prints a warning to stderr and retains the auto-detected value. This prevents hard failures while alerting you to the issue. The warning logic appears in lines 63-71 and 75-81 of llmfit-tui/src/main.rs.
Key Source Files for Hardware Overrides
llmfit-tui/src/main.rs— CLI flag definitions,HardwareOverridesstruct, anddetect_specsimplementationllmfit-core/src/hardware.rs— Auto-detection of system specs viaSystemSpecs::detect()llmfit-core/src/analysis.rs— Consumes the finalSystemSpecsfor model-fit scoringdocs/cli.md— User-facing documentation of all flags
Summary
--ram,--memory,--cpu-coresoverride auto-detected hardware values inllmfit- Overrides apply before any
fit,recommend, orplancalculations - Human-readable sizes (
24G,128000M) parse viaparse_memory_size - Invalid inputs trigger warnings without stopping execution
- Source implementation spans
llmfit-tui/src/main.rslines 50-92
Frequently Asked Questions
What happens if I provide an invalid memory string?
llmfit prints a warning to stderr and continues with the automatically detected value. For example, --ram 64GB (invalid suffix) will warn rather than error.
Can I use these flags with any subcommand?
Yes. The hardware override flags are defined on the global Cli struct and apply universally to fit, recommend, plan, and future subcommands.
Does --memory require a GPU to be present?
No. The --memory flag sets the GPU VRAM or unified memory pool value used for calculations, regardless of whether a physical GPU is detected. This enables modeling headless or containerized environments.
How does --max-context interact with environment variables?
--max-context takes precedence. If omitted, llmfit checks OLLAMA_CONTEXT_LENGTH. If neither is set, internal defaults apply based on the hardware profile.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →