| 1 | # SPDX-License-Identifier: Apache-2.0 |
| 2 | # SPDX-FileCopyrightText: Copyright contributors to the vLLM project |
| 3 | |
| 4 | import pytest |
| 5 | import torch |
| 6 | |
| 7 | from vllm.scalar_type import scalar_types |
| 8 | |
| 9 | |
| 10 | @pytest.mark.parametrize( |
| 11 | "type_tuple", |
| 12 | ( |
| 13 | (-8, 7, scalar_types.int4), |
| 14 | (0, 15, scalar_types.uint4), |
| 15 | (-8, 7, scalar_types.uint4b8), |
| 16 | (-128, 127, scalar_types.uint8b128), |
| 17 | (-6.0, 6.0, scalar_types.float4_e2m1f), |
| 18 | (-28.0, 28.0, scalar_types.float6_e3m2f), |
| 19 | (torch.int8, scalar_types.int8), |
| 20 | (torch.uint8, scalar_types.uint8), |
| 21 | (torch.float8_e5m2, scalar_types.float8_e5m2), |
| 22 | (torch.float8_e4m3fn, scalar_types.float8_e4m3fn), |
| 23 | (torch.bfloat16, scalar_types.float16_e8m7), |
| 24 | (torch.float16, scalar_types.float16_e5m10), |
| 25 | ), |
| 26 | ids=lambda x: str(x), |
| 27 | ) |
| 28 | def test_scalar_type_min_max(type_tuple): |
| 29 | print(type_tuple) |
| 30 | if len(type_tuple) == 3: |
| 31 | min, max, t = type_tuple |
| 32 | else: |
| 33 | torch_type, t = type_tuple |
| 34 | if torch_type.is_floating_point: |
| 35 | min = torch.finfo(torch_type).min |
| 36 | max = torch.finfo(torch_type).max |
| 37 | else: |
| 38 | min = torch.iinfo(torch_type).min |
| 39 | max = torch.iinfo(torch_type).max |
| 40 | |
| 41 | print(t, min, max, t.min(), t.max()) |
| 42 | assert min == t.min(), f"min: {min} != {t.min()}" |
| 43 | assert max == t.max(), f"max: {max} != {t.max()}" |