๐ฌ Local LLM Inference ToolsJuly 28, 2026โ
Tests passing
LLM Hardware Optimizer
A CLI tool to analyze local hardware capabilities and generate an optimized configuration file for running large language models efficiently. It considers GPU/CPU specs, available memory, and other hardware details to recommend optimal batch sizes, precision modes (FP16/FP32), and parallelism settings.
What It Does
- Automatic Hardware Profiling: Detects CPU, GPU, and memory specifications.
- Optimized Configuration Generation: Recommends batch sizes, precision modes, and parallelism settings based on hardware.
- Multi-framework Support: Configurations are suitable for frameworks like PyTorch and TensorFlow.
Installation
1. Clone the repository:
git clone <repository-url>
cd llm_hardware_optimizer2. Install the required dependencies:
pip install -r requirements.txtUsage
batch_size: 32
precision: FP16
parallelism: noneSource Code
import argparse
import os
import psutil
import torch
import yaml
def profile_hardware():
"""Profiles local hardware capabilities."""
hardware_info = {
"cpu_count": psutil.cpu_count(logical=True),
"total_memory_gb": round(psutil.virtual_memory().total / (1024 ** 3), 2),
"gpu_available": torch.cuda.is_available(),
"gpu_count": torch.cuda.device_count(),
"gpu_details": []
}
if hardware_info["gpu_available"]:
for i in range(hardware_info["gpu_count"]):
gpu_properties = torch.cuda.get_device_properties(i)
hardware_info["gpu_details"].append({
"name": gpu_properties.name,
"memory_gb": round(gpu_properties.total_memory / (1024 ** 3), 2),
"compute_capability": f"{gpu_properties.major}.{gpu_properties.minor}"
})
return hardware_info
def generate_configuration(hardware_info):
"""Generates an optimized configuration based on hardware info."""
config = {
"batch_size": 32,
"precision": "FP32",
"parallelism": "none"
}
if hardware_info["gpu_available"]:
config["precision"] = "FP16"
config["parallelism"] = "data_parallel" if hardware_info["gpu_count"] > 1 else "none"
# Adjust batch size based on GPU memory
if hardware_info["gpu_details"]:
min_gpu_memory = min(gpu["memory_gb"] for gpu in hardware_info["gpu_details"])
if min_gpu_memory >= 16:
config["batch_size"] = 64
elif min_gpu_memory >= 8:
config["batch_size"] = 32
else:
config["batch_size"] = 16
else:
# Adjust batch size for CPU-only systems
if hardware_info["total_memory_gb"] >= 16:
config["batch_size"] = 16
elif hardware_info["total_memory_gb"] >= 8:
config["batch_size"] = 8
else:
config["batch_size"] = 4
return config
def save_configuration(config, output_path):
"""Saves the configuration to a file in YAML or JSON format."""
_, ext = os.path.splitext(output_path)
ext = ext.lower()
if ext == ".yaml" or ext == ".yml":
with open(output_path, "w") as file:
yaml.dump(config, file)
elif ext == ".json":
import json
with open(output_path, "w") as file:
json.dump(config, file, indent=4)
else:
raise ValueError("Unsupported file format. Use .yaml or .json.")
def main():
parser = argparse.ArgumentParser(description="LLM Hardware Optimizer")
parser.add_argument("--output", required=True, help="Path to save the configuration file (e.g., config.yaml or config.json)")
args = parser.parse_args()
try:
hardware_info = profile_hardware()
config = generate_configuration(hardware_info)
save_configuration(config, args.output)
print(f"Configuration saved to {args.output}")
except Exception as e:
print(f"Error: {e}")
if __name__ == "__main__":
main()
Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- llm_hardware_optimizer
- Category
- Local LLM Inference Tools
- Generated
- July 28, 2026
- Tests
- Passing โ
Quick Install
Clone just this tool:
git clone --depth 1 --filter=blob:none --sparse \ https://github.com/ptulin/autoaiforge.git cd autoaiforge git sparse-checkout set generated_tools/2026-07-28/llm_hardware_optimizer cd generated_tools/2026-07-28/llm_hardware_optimizer pip install -r requirements.txt 2>/dev/null || true python llm_hardware_optimizer.py