File: benchmark_test_generator.py

package info (click to toggle)
pytorch-cuda 2.6.0%2Bdfsg-7
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid, trixie
  • size: 161,620 kB
  • sloc: python: 1,278,832; cpp: 900,322; ansic: 82,710; asm: 7,754; java: 3,363; sh: 2,811; javascript: 2,443; makefile: 597; ruby: 195; xml: 84; objc: 68
file content (42 lines) | stat: -rw-r--r-- 1,627 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from benchmark_core import _register_test
from benchmark_pytorch import create_pytorch_op_test_case


def generate_pt_test(configs, pt_bench_op):
    """This function creates PyTorch op test based on the given operator"""
    _register_test(configs, pt_bench_op, create_pytorch_op_test_case, False)


def generate_pt_gradient_test(configs, pt_bench_op):
    """This function creates PyTorch op test based on the given operator"""
    _register_test(configs, pt_bench_op, create_pytorch_op_test_case, True)


def generate_pt_tests_from_op_list(ops_list, configs, pt_bench_op):
    """This function creates pt op tests one by one from a list of dictionaries.
    ops_list is a list of dictionary. Each dictionary includes
    the name of the operator and the math operation. Here is an example of using this API:
    unary_ops_configs = op_bench.config_list(
        attrs=[...],
        attr_names=["M", "N"],
    )
    unary_ops_list = op_bench.op_list(
        attr_names=["op_name", "op_func"],
        attrs=[
            ["abs", torch.abs],
        ],
    )
    class UnaryOpBenchmark(op_bench.TorchBenchmarkBase):
        def init(self, M, N, op_name, op_func):
            ...
        def forward(self):
            ...
    op_bench.generate_pt_tests_from_op_list(unary_ops_list, unary_ops_configs, UnaryOpBenchmark)
    """
    for op in ops_list:
        _register_test(configs, pt_bench_op, create_pytorch_op_test_case, False, op)


def generate_pt_gradient_tests_from_op_list(ops_list, configs, pt_bench_op):
    for op in ops_list:
        _register_test(configs, pt_bench_op, create_pytorch_op_test_case, True, op)