Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add unit tests on CPU for TritonBench features #2323

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions torchbenchmark/operators/test_op/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .operator import Operator
44 changes: 44 additions & 0 deletions torchbenchmark/operators/test_op/operator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from typing import Generator, List, Optional

import torch

from torchbenchmark.util.triton_op import (
BenchmarkOperator,
BenchmarkOperatorMetrics,
register_benchmark,
register_metric,
)


class Operator(BenchmarkOperator):

DEFAULT_METRICS = ["test_metric"]

def __init__(self, mode: str, device: str, extra_args: Optional[List[str]] = None):
super().__init__(mode=mode, device=device, extra_args=extra_args)

@register_benchmark(label="new_op_label")
def test_op(self, x: torch.Tensor):
return lambda: x

def get_x_val(self, example_inputs):
return example_inputs[0].shape

def get_x_vals(self) -> List[int]:
return [2**n for n in [1, 2, 3]]

def get_input_iter(self) -> Generator:
for x in self.get_x_vals():
yield (torch.Tensor(torch.randn(x, device=self.device, dtype=self.dtype)),)

@register_metric(x_only=True)
def test_metric(
self, fn_name: str, example_inputs, metrics: BenchmarkOperatorMetrics
):
return [ex.shape[0] + 2 for ex in example_inputs]

@register_metric()
def test_metric_per_benchmark(
self, fn_name: str, example_inputs, metrics: BenchmarkOperatorMetrics
):
return [ex.shape[0] + 3 for ex in example_inputs]
1 change: 1 addition & 0 deletions torchbenchmark/util/triton_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,7 @@ def __init__(self, mode: str, device: str, extra_args: Optional[List[str]]=None)
self._only = _split_params_by_comma(self.tb_args.only)
self._input_id = self.tb_args.input_id
self._num_inputs = self.tb_args.num_inputs
self.device = device

# Run the post initialization
def __post__init__(self):
Expand Down
Loading