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:

  1. Base detection — SystemSpecs::detect() runs first
  2. RAM override — If --ram provided, parsed and applied via with_ram_override(gb) (lines 63-66)
  3. GPU memory override — If --memory provided, applied via with_gpu_memory_override(gb) (lines 75-78)
  4. CPU core override — If --cpu-cores provided, applied via with_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

Summary

  • --ram, --memory, --cpu-cores override auto-detected hardware values in llmfit
  • Overrides apply before any fit, recommend, or plan calculations
  • Human-readable sizes (24G, 128000M) parse via parse_memory_size
  • Invalid inputs trigger warnings without stopping execution
  • Source implementation spans llmfit-tui/src/main.rs lines 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:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →