|
25 | 25 | BenchMode, |
26 | 26 | OperationAttribute, |
27 | 27 | check_metric_dependencies, |
| 28 | + model_shapes, |
28 | 29 | ) |
29 | 30 | from .conftest import Config, emit_record_logger |
30 | 31 |
|
@@ -492,9 +493,9 @@ def set_more_shapes(self): |
492 | 493 | more_shapes_3d = [(100, 2**i, 100) for i in (0, 8, 16)] |
493 | 494 | return more_shapes_1d + more_shapes_2d + more_shapes_3d |
494 | 495 |
|
495 | | - def get_input_iter(self, cur_dtype) -> Generator: |
| 496 | + def get_input_iter(self, dtype) -> Generator: |
496 | 497 | for shape in self.shapes: |
497 | | - yield from self.input_fn(shape, cur_dtype, self.device) |
| 498 | + yield from self.input_fn(shape, dtype, self.device) |
498 | 499 |
|
499 | 500 |
|
500 | 501 | class GenericBenchmarkFilterShapes(GenericBenchmark): |
@@ -641,6 +642,61 @@ def get_tflops(self, op, *args, **kwargs): |
641 | 642 | return torch.tensor(inp_shape).prod().item() * 2 |
642 | 643 |
|
643 | 644 |
|
| 645 | +class BlasBenchmark(Benchmark): |
| 646 | + """ |
| 647 | + benchmark for blas |
| 648 | + """ |
| 649 | + |
| 650 | + DEFAULT_METRICS = DEFAULT_METRICS[:] + ["tflops"] |
| 651 | + |
| 652 | + def __init__(self, *args, input_fn, **kwargs): |
| 653 | + super().__init__(*args, **kwargs) |
| 654 | + self.input_fn = input_fn |
| 655 | + |
| 656 | + def get_input_iter(self, dtype) -> Generator: |
| 657 | + for b, m, n, k in self.shapes: |
| 658 | + yield from self.input_fn(b, m, n, k, dtype, self.device, False) |
| 659 | + |
| 660 | + if Config.bench_level == BenchLevel.COMPREHENSIVE: |
| 661 | + for b, m, n, k in self.shapes: |
| 662 | + yield from self.input_fn(b, m, n, k, dtype, self.device, True) |
| 663 | + |
| 664 | + def set_more_shapes(self): |
| 665 | + large_k_shapes = [ |
| 666 | + [8, 1848, 1536, 151936], |
| 667 | + [8, 1848, 1536, 128256], |
| 668 | + [8, 1848, 1536, 152064], |
| 669 | + [8, 4096, 1, 152064], |
| 670 | + ] |
| 671 | + |
| 672 | + model_shaps = model_shapes() |
| 673 | + return large_k_shapes + model_shaps |
| 674 | + |
| 675 | + def get_tflops(self, op, *args, **kwargs): |
| 676 | + total_flops = 0 |
| 677 | + # shape(m,k)(k,n) |
| 678 | + # total_flops mxnx2k |
| 679 | + if self.op_name == "mm": |
| 680 | + total_flops = args[0].shape[0] * args[0].shape[1] * args[1].shape[1] * 2 |
| 681 | + |
| 682 | + # shape(m,n)(n,p) |
| 683 | + # total_flops mxpx(2n+1) |
| 684 | + elif self.op_name == "addmm": |
| 685 | + total_flops = ( |
| 686 | + args[0].shape[0] * args[1].shape[1] * (args[1].shape[0] * 2 + 1) |
| 687 | + ) |
| 688 | + # total_flops bxnxpx2m |
| 689 | + elif self.op_name == "bmm": |
| 690 | + total_flops = ( |
| 691 | + args[0].shape[0] |
| 692 | + * args[0].shape[1] |
| 693 | + * args[1].shape[2] |
| 694 | + * 2 |
| 695 | + * args[0].shape[2] |
| 696 | + ) |
| 697 | + return total_flops |
| 698 | + |
| 699 | + |
644 | 700 | def generate_tensor_input(shape, dtype, device): |
645 | 701 | if dtype in FLOAT_DTYPES: |
646 | 702 | return torch.randn(shape, dtype=dtype, device=device) |
|
0 commit comments