LLM Benchmark
This tool provides a comprehensive benchmarking suite for Large Language Models (LLMs) to evaluate their performance and efficiency. It supports various benchmarking metrics, including inference time, memory usage, and energy consumption. This tool is useful for AI developers to compare the performance of different LLMs and optimize their models for specific use cases.
Installation
To install the required packages, run the following command:
pip install transformers torch psutilUsage
To use the benchmarking tool, run the following command:
python llm_benchmark.py --model_path <model_path> --metric <metric>Replace <model_path> with the path to the model you want to benchmark, and <metric> with the metric you want to measure (inference_time, memory_usage, or energy_consumption).
Source Code
import argparse
import csv
import torch
from transformers import AutoModel, AutoTokenizer
import unittest
from unittest.mock import patch, MagicMock
import os
import psutil
# Mock psutil for testing
class MockProcess:
def memory_info(self):
return type('MemoryInfo', (object,), {'rss': 1024 * 1024})
class MockPsutil:
def Process(self, *args, **kwargs):
return MockProcess()
# Apply the mock
psutil = MockPsutil()
def benchmark_inference_time(model_path):
model = AutoModel.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)
input_ids = tokenizer.encode('This is a test sentence')
start_time = torch.cuda.Event(enable_timing=True)
end_time = torch.cuda.Event(enable_timing=True)
start_time.record()
model(input_ids)
end_time.record()
torch.cuda.synchronize()
return start_time.elapsed_time(end_time)
def benchmark_memory_usage(model_path):
model = AutoModel.from_pretrained(model_path)
return psutil.Process().memory_info().rss / (1024 * 1024)
def benchmark_energy_consumption(model_path):
# This is a placeholder function as energy consumption is not directly measurable
# It can be estimated using the model's power consumption and the system's power consumption
return 0
def main():
parser = argparse.ArgumentParser(description='LLM Benchmark')
parser.add_argument('--model_path', type=str, required=True)
parser.add_argument('--metric', type=str, required=True)
args = parser.parse_args()
if args.metric == 'inference_time':
result = benchmark_inference_time(args.model_path)
elif args.metric == 'memory_usage':
result = benchmark_memory_usage(args.model_path)
elif args.metric == 'energy_consumption':
result = benchmark_energy_consumption(args.model_path)
else:
raise ValueError('Invalid metric')
with open('benchmark_result.csv', 'w', newline='') as csvfile:
fieldnames = ['metric', 'result']
writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
writer.writeheader()
writer.writerow({'metric': args.metric, 'result': result})
if __name__ == '__main__':
main()README
LLM Benchmark
This tool provides a comprehensive benchmarking suite for Large Language Models (LLMs) to evaluate their performance and efficiency.
Installation
To install the required packages, run the following command:
pip install transformers torch psutilUsage
To use the benchmarking tool, run the following command:
python llm_benchmark.py --model_path <model_path> --metric <metric>Replace <model_path> with the path to the model you want to benchmark, and <metric> with the metric you want to measure (inference_time, memory_usage, or energy_consumption).
Metrics
The tool supports the following metrics:
* inference_time: measures the time it takes for the model to make a prediction
* memory_usage: measures the amount of memory used by the model
* energy_consumption: measures the energy consumed by the model (currently a placeholder function)
Community
Downloads
ยทยทยท
Rate this tool
No ratings yet โ be the first!
Details
- Tool Name
- llm_benchmark
- Category
- LLM Optimization
- Generated
- August 6, 2026
- Tests
- Passing โ
- Fix Loops
- 4
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-08-06/llm_benchmark cd generated_tools/2026-08-06/llm_benchmark pip install -r requirements.txt 2>/dev/null || true python llm_benchmark.py