Skip to content

Commit 24bea42

Browse files
committed
Updates
1 parent a56f3ab commit 24bea42

File tree

29 files changed

+74
-293
lines changed

29 files changed

+74
-293
lines changed

benchmarks/microbenchmarks/benchmark_config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ model_params:
1414
[4096, 4096, 1024]
1515
]
1616
precision: "torch.bfloat16"
17-
compile: false
17+
compile: "max-autotune"
1818
device: "cuda" # Change this to "cuda", "mps", "xpu", or "cpu" as needed
1919
model_type: "linear"

benchmarks/microbenchmarks/benchmark_inference.py

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,27 +4,28 @@
44
This script runs inference benchmarks and generates a micro-benchmarking report for it.
55
- run() function is the main entry point for running inference benchmarks.
66
"""
7+
78
from copy import deepcopy
8-
import json
99
from pathlib import Path
1010
from typing import Dict
1111

1212
import torch
1313
from utils import (
14+
BenchmarkConfig,
1415
benchmark_model_inference_in_microseconds,
1516
clean_caches,
1617
create_model_and_input,
1718
quantize_model,
18-
BenchmarkConfig,
1919
)
2020

21+
2122
def run(config: BenchmarkConfig) -> Dict[str, float]:
2223
"""Run inference benchmarks"""
2324
clean_caches() # Clean caches
24-
25+
2526
# Create output directory if it doesn't exist
2627
Path(config.output_dir).mkdir(parents=True, exist_ok=True)
27-
28+
2829
base_model, input_data = create_model_and_input(
2930
config.model_type,
3031
config.m,
@@ -33,10 +34,7 @@ def run(config: BenchmarkConfig) -> Dict[str, float]:
3334
dtype=config.precision,
3435
device=config.device,
3536
)
36-
print(
37-
f"Starting benchmarking for model: {base_model.__class__.__name__} for quantization: {config.quantization}"
38-
)
39-
37+
4038
# Use quantize_ to apply each quantization function to the model
4139
m_copy = deepcopy(base_model).eval().to(config.device)
4240
m_copy = quantize_model(m_copy, config.quantization)
@@ -46,16 +44,13 @@ def run(config: BenchmarkConfig) -> Dict[str, float]:
4644
m_copy = torch.compile(m_copy, mode=config.compile, fullgraph=True)
4745

4846
# Run benchmarks
49-
results = {}
50-
47+
result = {**config.__dict__}
48+
5149
# Benchmark time to run an inference call for quantized model
5250
model_time = benchmark_model_inference_in_microseconds(
5351
model=m_copy, input_data=input_data
5452
)
55-
results[f"benchmark_model_inference_in_microseconds"] = model_time
56-
print(
57-
f"Time to run a {base_model.__class__.__name__}: {model_time:.2f} microseconds quantized with {config.quantization}"
58-
)
53+
result["benchmark_model_inference_in_microseconds"] = model_time
5954

6055
# TODO: Benchmark time using profiler
6156
# Profile dtype model evaluation
@@ -68,4 +63,4 @@ def run(config: BenchmarkConfig) -> Dict[str, float]:
6863
# TODO: Benchmark op with cuda graph
6964
# time = benchmark_op_with_cuda_graph(op, args)
7065

71-
return results
66+
return result

benchmarks/microbenchmarks/benchmark_runner.py

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@
1313
1414
The YAML file should contain all necessary configuration parameters for the benchmarks.
1515
"""
16+
1617
from itertools import product
1718
from typing import Any, Dict, List, Tuple
1819

19-
import torch
2020
import yaml
21+
from utils import BenchmarkConfig, generate_results_csv
2122

22-
from utils import BenchmarkConfig
2323

2424
def get_shapes_for_config(shape_config: Dict[str, Any]) -> List[Tuple[str, List[int]]]:
2525
"""Get shapes for a given configuration"""
@@ -43,13 +43,16 @@ def load_benchmark_configs(config_path: str) -> List[BenchmarkConfig]:
4343
shapes = get_shapes_for_config(shape_config)
4444
# Generate combinations for each shape
4545
for quant, (shape_name, shape) in product(quantizations, shapes):
46-
configs.append(BenchmarkConfig(
47-
quantization=quant,
48-
params=params,
49-
shape_name=shape_name,
50-
shape=shape,
51-
output_dir=output_dir,
52-
))
46+
configs.append(
47+
BenchmarkConfig(
48+
quantization=quant,
49+
params=params,
50+
shape_name=shape_name,
51+
shape=shape,
52+
output_dir=output_dir,
53+
)
54+
)
55+
print("Configs: ", configs[0].__dict__)
5356

5457
return configs
5558

@@ -60,22 +63,21 @@ def run_benchmarks_from_config(config_path: str) -> None:
6063

6164
configs = load_benchmark_configs(config_path)
6265
results = []
63-
print(f"Benchmarking Inference ......")
66+
print("Benchmarking Inference ......")
6467
for config in configs:
6568
print(f"Running: {config.name}")
6669
result = run_inference(config) # Pass the config object directly
6770
results.append(result)
6871

69-
# TODO: Convert results to csv
70-
# Speedups:
72+
# Add results to csv
73+
generate_results_csv(results, configs[0].output_dir)
74+
75+
# TODO: Process results: Speedups:
7176
# 1. For different shapes for same model and quantization
7277
# 2. For different quantizations for same model and shape
7378
# 3. For different models for same quantization
7479

7580

76-
77-
78-
7981
if __name__ == "__main__":
8082
import argparse
8183

benchmarks/microbenchmarks/benchmark_training.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,6 @@
1010

1111
def run(config: BenchmarkConfig) -> None:
1212
"""Run training benchmarks"""
13-
raise NotImplementedError("Training benchmarks are not implemented yet. This is a placeholder function.")
13+
raise NotImplementedError(
14+
"Training benchmarks are not implemented yet. This is a placeholder function."
15+
)

benchmarks/microbenchmarks/results/benchmark_baseline_custom_m1024_k1024_n1024_results.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

benchmarks/microbenchmarks/results/benchmark_baseline_custom_m2048_k4096_n1024_results.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

benchmarks/microbenchmarks/results/benchmark_baseline_custom_m4096_k4096_n1024_results.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

benchmarks/microbenchmarks/results/benchmark_baseline_linear_m1024_k1024_n1024_results.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

benchmarks/microbenchmarks/results/benchmark_baseline_linear_m2048_k4096_n1024_results.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

benchmarks/microbenchmarks/results/benchmark_baseline_linear_m4096_k4096_n1024_results.json

Lines changed: 0 additions & 3 deletions
This file was deleted.

0 commit comments

Comments
 (0)