# How to Override Hardware Detection in llmfit Using CLI Flags

> Override llmfit hardware detection with CLI flags like --memory, --ram, and --cpu-cores. Take control of your model-fit analysis settings.

- Repository: [Alex Jones/llmfit](https://github.com/AlexsJones/llmfit)
- Tags: how-to-guide
- Published: 2026-08-20

---

**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`](https://github.com/AlexsJones/llmfit/blob/main/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`](https://github.com/AlexsJones/llmfit/blob/main/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`](https://github.com/AlexsJones/llmfit/blob/main/llmfit-tui/src/main.rs) lines 50-92. The `HardwareOverrides` struct collects CLI values:

```rust
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:

```bash
llmfit fit --memory 24G

```

Test model recommendations against high-RAM target hardware:

```bash
llmfit recommend --ram 128G

```

Simulate multi-core CPU environment:

```bash
llmfit fit --cpu-cores 32

```

Combine multiple overrides for "what-if" scenario planning:

```bash
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`](https://github.com/AlexsJones/llmfit/blob/main/llmfit-tui/src/main.rs).

## Key Source Files for Hardware Overrides

- **[`llmfit-tui/src/main.rs`](https://github.com/AlexsJones/llmfit/blob/main/llmfit-tui/src/main.rs)** — CLI flag definitions, `HardwareOverrides` struct, and `detect_specs` implementation
- **[`llmfit-core/src/hardware.rs`](https://github.com/AlexsJones/llmfit/blob/main/llmfit-core/src/hardware.rs)** — Auto-detection of system specs via `SystemSpecs::detect()`
- **[`llmfit-core/src/analysis.rs`](https://github.com/AlexsJones/llmfit/blob/main/llmfit-core/src/analysis.rs)** — Consumes the final `SystemSpecs` for model-fit scoring
- **[`docs/cli.md`](https://github.com/AlexsJones/llmfit/blob/main/docs/cli.md)** — User-facing documentation of all flags

## 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`](https://github.com/AlexsJones/llmfit/blob/main/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.