Metadata-Version: 2.4
Name: llmfit-local
Version: 0.2.0
Summary: Zero-dependency CLI that inspects your CPU, RAM, and GPU/VRAM to recommend local open-weight LLMs and quantization levels.
Author: Staggerlee60
License: MIT
Project-URL: Homepage, https://github.com/staggerlee60/llmfit-local
Project-URL: Repository, https://github.com/staggerlee60/llmfit-local
Project-URL: Issues, https://github.com/staggerlee60/llmfit-local/issues
Keywords: llm,ollama,gguf,onnx,quantization,vram,local-ai,cli
Classifier: Development Status :: 4 - Beta
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Programming Language :: Python :: 3.15
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Utilities
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Provides-Extra: dev
Requires-Dist: pytest>=8.0; extra == "dev"
Dynamic: license-file

# llmfit-local

[![CI](https://github.com/staggerlee60/llmfit-local/actions/workflows/ci.yml/badge.svg)](https://github.com/staggerlee60/llmfit-local/actions/workflows/ci.yml)
[![PyPI](https://shields.io/pypi/v/llmfit-local.svg)](https://pypi.org/project/llmfit-local/)
[![Python 3.10+](https://shields.io/badge/python-3.10%2B-blue.svg)](https://python.org)
[![License: MIT](https://shields.io/badge/License-MIT-green.svg)](LICENSE)
[![Platform: Windows | macOS | Linux](https://shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey.svg)](#cross-platform-support)

A zero-dependency CLI tool that inspects your local CPU, RAM, GPU/VRAM, and free disk space to recommend open-weight LLMs and quantization levels (`FP16`, `Q8_0`, `Q5_K_M`, `Q4_K_M`, and `ONNX INT4`) that fit your machine—complete with MoE-aware speed estimates (`tok/s`), binary `.gguf` header inspection, VRAM max-context scaling, Hugging Face repo inspection, local Ollama audits, and `Modelfile` generation.

## Quick Demo

```console
`\$ llmfit --use-case coding --max-context
System:   Windows (AMD64) | 16 CPU cores
Memory:   32.0 GB RAM | Free Disk: 145.2 GB
GPU:      NVIDIA GeForce RTX 4070 (12.0 GB VRAM)
--------------------------------------------------------------------------------------------
Model                   Quant        Est. Mem   Fit        Speed          Run Command
--------------------------------------------------------------------------------------------
Qwen 3 8B               Q8_0          10.1 GB   GPU_FULL   37-63 tok/s    ollama run qwen3:8b [max 16k ctx]
Qwen 2.5 Coder 7B       Q8_0           9.4 GB   GPU_FULL   40-68 tok/s    ollama run qwen2.5-coder:7b [max 32k ctx]
DeepSeek-R1 Distill 8B  Q8_0           9.9 GB   GPU_FULL   38-65 tok/s    ollama run deepseek-r1:8b [max 16k ctx]
Qwen 3 4B               Q8_0           5.3 GB   GPU_FULL   76-130 tok/s   ollama run qwen3:4b [max 128k ctx]
Phi-4 Mini 3.8B         Q8_0           5.0 GB   GPU_FULL   80-137 tok/s   ollama run phi4-mini:3.8b [max 128k ctx]
Qwen 3 32B              Q4_K_M        23.4 GB   HYBRID     10-16 tok/s    ollama run qwen3:32b
Qwen 2.5 Coder 32B      Q4_K_M        23.4 GB   HYBRID     10-16 tok/s    ollama run qwen2.5-coder:32b
Qwen 3 30B-A3B (MoE)    Q4_K_M        21.8 GB   HYBRID     34-63 tok/s    ollama run qwen3:30b-a3b
```

```console
`\$ llmfit --gguf ./models/qwen3-8b-q4_k_m.gguf
Hardware:       32.0 GB RAM | GPU: NVIDIA GeForce RTX 4070 (12.0 GB VRAM)
GGUF Model:     Qwen3-8B (qwen3 | Q4_K_M)
File Size:      4.92 GB | Native Context: 32,768 tokens
Target Context: 8,192 tokens | Est. Total Mem: 6.27 GB
Fit Tier:       GPU_FULL | Est. Speed: 38-65 tok/s
Max GPU Ctx:    32,768 tokens
```

## Features
- **Automatic Hardware Detection:** Probes system RAM, CPU cores, free disk space, NVIDIA GPUs (`nvidia-smi`), AMD ROCm GPUs (`rocm-smi`), Windows discrete GPUs, and Apple Silicon unified memory using only the Python standard library.
- **Binary `.gguf` Header Inspection (`--gguf`):** Reads GGUF v2/v3 metadata headers directly via Python's built-in `struct` module to extract architecture, quantization type, native context length, and memory/speed fit without loading tensor weights.
- **VRAM Max-Context Scaling (`--max-context`):** Calculates the largest context window (`2k` up to `128k` tokens) that still fits 100% inside your GPU VRAM (`GPU_FULL`).
- **26+ Curated Dense & MoE Models:** Includes Qwen 3, Gemma 3, Phi-4, DeepSeek-R1 Distill, Devstral Small 24B, Mistral Small 3.2 24B, Llama 3.1/3.2/3.3, Qwen 3 30B-A3B (MoE), and Mixtral 8x7B (MoE).
- **MoE-Aware Speed & Fit Tiers:** Categorizes models into `GPU_FULL`, `HYBRID` (GPU + RAM offload), or `CPU_ONLY` while scaling `tok/s` estimates from active parameters (`active_params_b`) for Mixture-of-Experts architectures.
- **Hugging Face Repo Lookup (`--hf`):** Fetches parameter metadata directly from Hugging Face (`llmfit --hf Qwen/Qwen3-32B`) and evaluates `FP16`, `Q8_0`, `Q5_K_M`, and `Q4_K_M` against your hardware.
- **Custom Model Sizing (`--params`, `--active-params`, `--context`):** Evaluate any arbitrary dense or MoE model size and context length before downloading.
- **Local Ollama Audit (`--check-ollama`) & `Modelfile` Export (`--modelfile`):** Audits installed `ollama list` models against detected VRAM/RAM or prints a ready-to-save `Modelfile` configuring `PARAMETER num_ctx`.
- **GGUF / Ollama & ONNX Modes:** Outputs `ollama run` commands by default, or `olive run --model` ONNX INT4 recommendations with `--onnx`.

## Cross-Platform Support

`llmfit-local` runs natively on **Windows, macOS, and Linux** with zero third-party dependencies:
- **Windows:** Uses `GlobalMemoryStatusEx` via `ctypes` for physical RAM detection, plus `nvidia-smi` and Windows video controller queries for GPU VRAM.
- **macOS:** Detects Apple Silicon (`arm64`) unified memory and budgets GPU allocation automatically.
- **Linux:** Reads POSIX `sysconf` memory pages alongside `nvidia-smi` and `rocm-smi` GPU telemetry.

## Installation

```bash
# Run directly without installing
uvx llmfit-local

# Or install via pip
pip install llmfit-local
```

## Usage

```bash
# Detect local hardware and recommend top models (with max GPU VRAM context annotations)
llmfit --max-context

# Inspect a local .gguf file header and evaluate hardware fit
llmfit --gguf path/to/model.gguf

# Filter for coding models that fit 100% in GPU VRAM
llmfit --use-case coding --fit gpu

# Inspect any Hugging Face model repo directly
llmfit --hf Qwen/Qwen3-32B

# Evaluate a custom MoE model (30.5B total, 3.3B active parameters) at 16k context
llmfit --params 30.5 --active-params 3.3 --context 16384

# Audit your locally installed Ollama models against detected VRAM/RAM
llmfit --check-ollama

# Generate an Ollama Modelfile with a 32k context window for your top fitting model
llmfit --modelfile --context 32768

# Recommend ONNX INT4 models instead of GGUF / Ollama
llmfit --onnx

# Simulate a 24 GB VRAM workstation
llmfit --ram 64 --vram 24

# Output structured JSON for scripts
llmfit --format json
```

## Running Tests

```bash
pytest -v
```

## License

MIT
