How to Display Detected Hardware Using WhichLLM

To display detected hardware using WhichLLM, import detect_hardware from whichllm.hardware.detector and display_hardware from whichllm.output.display, then call display_hardware(detect_hardware()) to print a Rich-formatted panel showing GPUs, CPU, RAM, and OS information.

WhichLLM is an open-source Python tool that analyzes your system capabilities to recommend compatible LLM models. When you need to display detected hardware using WhichLLM, the library provides a clean two-step API that separates hardware probing from formatted output rendering.

Overview of the Hardware Detection Pipeline

The hardware display functionality spans three core modules in the repository. The detection logic lives in src/whichllm/hardware/detector.py, where the detect_hardware() function orchestrates platform-specific probes for CPUs, GPUs, memory, and storage. This function returns a HardwareInfo dataclass defined in src/whichllm/hardware/types.py, which structures the detected specifications into typed fields.

The visual presentation layer resides in src/whichllm/output/display.py. The display_hardware(hw: HardwareInfo) function accepts the dataclass instance and renders a color-coded Rich panel containing GPU details, CPU specifications, available RAM, disk space, and operating system.

Step-by-Step Implementation

Import the Detection and Display Functions

Begin by importing the detection orchestrator and display renderer from their respective modules:

from whichllm.hardware.detector import detect_hardware
from whichllm.output.display import display_hardware

Capture Hardware Information

Call detect_hardware() to execute the platform-specific probes. This function aggregates results from NVIDIA, AMD, Intel, Apple, and Windows GPU detectors alongside CPU and RAM helpers:

hardware = detect_hardware()  # Returns HardwareInfo dataclass

The returned HardwareInfo object contains:

  • gpus: List of GPUInfo objects with vendor, VRAM, compute capability, and memory bandwidth
  • cpu_name, cpu_cores: Processor identification and core count
  • has_avx2, has_avx512: Boolean flags for instruction set support
  • ram_bytes, disk_free_bytes: Memory and storage metrics
  • os: Operating system identifier

Render the Hardware Panel

Pass the hardware object to the display function to print the formatted summary:

display_hardware(hardware)

This builds a Rich Panel containing styled sections for GPUs (or "No GPU detected"), CPU details with AVX flags, and system memory statistics.

Complete Code Examples

Basic Script Usage

For quick inspection in a Python script or REPL:

from whichllm.hardware.detector import detect_hardware
from whichllm.output.display import display_hardware

# Detect and display in one flow

hardware = detect_hardware()
display_hardware(hardware)

Capturing Output as a String

When you need the hardware report as text for logging or API responses, redirect the Rich console output:

from whichllm.hardware.detector import detect_hardware
from whichllm.output.display import display_hardware
from io import StringIO
from rich.console import Console
import whichllm.output.display as disp_mod

def show_my_hardware():
    """Returns formatted hardware summary as a string."""
    buf = StringIO()
    console = Console(file=buf, force_terminal=False, width=80)
    
    # Temporarily replace module console

    old_console = disp_mod.console
    disp_mod.console = console
    
    try:
        hardware = detect_hardware()
        disp_mod.display_hardware(hardware)
    finally:
        disp_mod.console = old_console  # Restore original console

    
    return buf.getvalue()

print(show_my_hardware())

Command-Line Interface

WhichLLM exposes this functionality directly through the CLI:

$ whichllm hardware

This executes the detection and display pipeline automatically, producing output similar to:


GPU 0: NVIDIA GeForce RTX 4090 — 24.0 GB — BW: 1000 GB/s
CPU: Intel(R) Core i9-13900K — 24 cores (AVX2, AVX-512)
RAM: 64.0 GB
Disk free: 200.0 GB
OS: linux

Understanding the Data Structure

The HardwareInfo dataclass in src/whichllm/hardware/types.py serves as the contract between detection and display layers. Each GPUInfo entry within the gpus list contains vendor-specific metadata including VRAM capacity, compute capability version, and memory bandwidth measurements.

According to the WhichLLM source code, the detector in src/whichllm/hardware/detector.py (lines 20-55) imports platform-specific implementations and aggregates their results into this unified structure. The display module in src/whichllm/output/display.py (lines 71-126) then formats these raw values into human-readable strings with appropriate units and labels.

Summary

  • Import detect_hardware from whichllm.hardware.detector and display_hardware from whichllm.output.display
  • Call detect_hardware() to probe system capabilities and receive a HardwareInfo dataclass
  • Pass the hardware object to display_hardware() to render a Rich terminal panel showing GPUs, CPU specs, memory, and OS
  • Access the underlying data structure in src/whichllm/hardware/types.py for custom processing or programmatic access to detected hardware using WhichLLM

Frequently Asked Questions

How do I check if AVX-512 is supported on my CPU using WhichLLM?

The detect_hardware() function automatically checks for AVX-512 support during the CPU detection phase. The result is stored in the has_avx512 boolean attribute of the returned HardwareInfo object. When you call display_hardware(), this information appears in the CPU line alongside the processor name and core count.

Can I display detected hardware using WhichLLM without printing to the console?

Yes, you can capture the formatted output as a string by temporarily redirecting the Rich console instance used by display_hardware. Create a StringIO buffer, initialize a Rich Console with that buffer as the file argument, replace whichllm.output.display.console with your instance, call display_hardware(), then restore the original console and retrieve the string value.

What GPU information does WhichLLM detect and display?

WhichLLM detects GPU vendor, model name, VRAM capacity, compute capability (for CUDA devices), and memory bandwidth. The GPUInfo dataclass in src/whichllm/hardware/types.py models these attributes, and display_hardware() renders them as "GPU 0: — () — BW: " or indicates "No GPU detected" if none are found.

Where is the hardware detection logic implemented in the WhichLLM repository?

The detection orchestrator lives in src/whichllm/hardware/detector.py, which coordinates platform-specific GPU detectors (NVIDIA, AMD, Intel, Apple, Windows) and CPU/RAM helpers. The data structures are defined in src/whichllm/hardware/types.py, while the display formatting resides in src/whichllm/output/display.py.

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 →