monsterdog-bot / monsterdog_benchmark.py
MonsterDo000's picture
Upload 17 files
00329f8 verified
import torch
import torchvision.models as models
import time
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
from qiskit import QuantumCircuit
from torch import nn
# === 1. ResNet50 Inference Benchmark ===
def benchmark_resnet50():
model = models.resnet50(pretrained=False).eval()
input_data = torch.randn(64, 3, 224, 224)
start = time.time()
with torch.no_grad():
_ = model(input_data)
end = time.time()
return end - start
# === 2. GAN Benchmark ===
class SimpleGAN(nn.Module):
def __init__(self):
super(SimpleGAN, self).__init__()
self.fc = nn.Sequential(
nn.Linear(100, 256),
nn.ReLU(),
nn.Linear(256, 784),
nn.Tanh()
)
def forward(self, z):
return self.fc(z)
def benchmark_gan():
model = SimpleGAN()
z = torch.randn((1, 100))
start = time.time()
_ = model(z)
end = time.time()
return end - start
# === 3. QAOA Simulation (Mock) ===
def benchmark_qaoa(qubits=1000):
start = time.time()
qc = QuantumCircuit(qubits)
for i in range(qubits):
qc.h(i)
qc.barrier()
end = time.time()
return end - start
# === 4. Save Results ===
def run_benchmarks():
results = {
"ResNet50 (s)": benchmark_resnet50(),
"GAN Gen (s)": benchmark_gan(),
"QAOA 1000q (s)": benchmark_qaoa()
}
df = pd.DataFrame([results])
df.to_csv("benchmark_results.csv", index=False)
# Plot
plt.figure(figsize=(10, 6))
plt.bar(results.keys(), results.values(), color='purple')
plt.ylabel("Temps (s)")
plt.title("Benchmarks MONSTERDOG Multi-Noeuds")
plt.savefig("benchmark_plot.png")
plt.close()
if __name__ == "__main__":
run_benchmarks()