Skip to content

Commit

Permalink
Fix Inductor bench BC change (pytorch#638)
Browse files Browse the repository at this point in the history
* Fix Inductor bench BC change

* update

* push

* pish
  • Loading branch information
msaroufim authored Aug 8, 2024
1 parent 34b24f7 commit 0a3b328
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions torchao/quantization/autoquant.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
from .quant_primitives import (
safe_int_mm,
)
from torchao.utils import TORCH_VERSION_AFTER_2_3
from torchao.utils import TORCH_VERSION_AFTER_2_3, TORCH_VERSION_AFTER_2_5
from torchao.quantization.utils import quantize_activation_per_token_absmax

import torch.nn.functional as F

try:
from torch._inductor.utils import do_bench
except:
from torch._inductor.runtime.runtime_utils import do_bench
except ImportError:
try:
from torch._inductor.runtime.runtime_utils import do_bench
except ImportError:
from torch._inductor.runtime.benchmarking import benchmarker
do_bench = benchmarker.benchmark

__all__ = [
"AutoQuantizableLinearWeight",
Expand Down Expand Up @@ -227,9 +232,13 @@ def do_autoquant_bench(op, *args, **kwargs):
graph = torch.cuda.CUDAGraph()
with torch.cuda.graph(graph, stream=stream):
op(*args, **kwargs)
if TORCH_VERSION_AFTER_2_3:
if TORCH_VERSION_AFTER_2_3 and not TORCH_VERSION_AFTER_2_5:
from torch._inductor.runtime.runtime_utils import do_bench_gpu
res = do_bench_gpu(lambda: graph.replay(), warmup=warmup, rep=rep, return_mode="median")
elif TORCH_VERSION_AFTER_2_5 and torch.cuda.is_available():
from torch._inductor.runtime.benchmarking import benchmarker
do_bench_gpu = benchmarker.benchmark_gpu
res = do_bench_gpu(lambda: graph.replay(), warmup=warmup, rep=rep, return_mode="median")
else:
res = do_bench(lambda: graph.replay(), warmup=warmup, rep=rep, return_mode="median")
return res
Expand Down

0 comments on commit 0a3b328

Please sign in to comment.