|
| 1 | +import pytest |
| 2 | +import torch |
| 3 | + |
| 4 | +import flag_gems |
| 5 | + |
| 6 | +from . import attri_util as attrs |
| 7 | +from . import performance_utils as base |
| 8 | + |
| 9 | + |
| 10 | +class RepetitionPenaltyBenchmark(base.Benchmark): |
| 11 | + def __init__(self, op_name, torch_op, dtypes): |
| 12 | + super().__init__(op_name, torch_op, dtypes) |
| 13 | + self.gems_op = None |
| 14 | + |
| 15 | + def set_shapes(self, shape_file_path=None): |
| 16 | + self.shapes = [ |
| 17 | + (1, 1024), |
| 18 | + (1, 4096), |
| 19 | + (1, 8192), |
| 20 | + (8, 4096), |
| 21 | + (16, 4096), |
| 22 | + (32, 1024), |
| 23 | + (8, 8192), |
| 24 | + (64, 32000), |
| 25 | + ] |
| 26 | + |
| 27 | + def get_input_iter(self, dtype): |
| 28 | + for shape in self.shapes: |
| 29 | + num_seqs, vocab_size = shape |
| 30 | + yield ( |
| 31 | + torch.randn(shape, dtype=dtype, device=self.device), |
| 32 | + torch.randint(0, 2, shape, dtype=torch.bool, device=self.device), |
| 33 | + torch.randint(0, 2, shape, dtype=torch.bool, device=self.device), |
| 34 | + torch.empty(num_seqs, dtype=dtype, device=self.device).uniform_( |
| 35 | + 1.0, 2.0 |
| 36 | + ), |
| 37 | + ) |
| 38 | + |
| 39 | + def set_gems(self, gems_op): |
| 40 | + self.gems_op = gems_op |
| 41 | + |
| 42 | + |
| 43 | +UNSUPPORTED_VENDORS = { |
| 44 | + "metax", |
| 45 | + "kunlunxin", |
| 46 | + "iluvatar", |
| 47 | + "mthreads", |
| 48 | + "hygon", |
| 49 | + "cambricon", |
| 50 | +} |
| 51 | + |
| 52 | + |
| 53 | +@pytest.mark.skipif(base.SkipVersion("vllm", "<0.4"), reason="vLLM <0.4 not supported") |
| 54 | +@pytest.mark.skipif(not torch.cuda.is_available(), reason="CUDA required") |
| 55 | +@pytest.mark.skipif( |
| 56 | + flag_gems.vendor_name in UNSUPPORTED_VENDORS, reason="Vendor not supported" |
| 57 | +) |
| 58 | +@pytest.mark.apply_repetition_penalties |
| 59 | +def test_apply_repetition_penalties(): |
| 60 | + vllm_ops = pytest.importorskip("vllm._custom_ops") |
| 61 | + |
| 62 | + bench = RepetitionPenaltyBenchmark( |
| 63 | + op_name="apply_repetition_penalties", |
| 64 | + torch_op=vllm_ops.apply_repetition_penalties, |
| 65 | + dtypes=attrs.FLOAT_DTYPES, |
| 66 | + ) |
| 67 | + bench.set_gems(flag_gems.apply_repetition_penalties) |
| 68 | + bench.run() |
0 commit comments