main
py 29 lines 1022 Bytes
Raw
1 # SPDX-License-Identifier: Apache-2.0
2 # SPDX-FileCopyrightText: Copyright contributors to the vLLM project
3
4 import torch
5
6 from tests.kernels.utils import opcheck
7 from vllm import _custom_ops as ops # noqa: F401
8
9
10 def test_gptq_shuffle_opcheck():
11 weight = torch.randint(
12 -2000000, 2000000, (1792, 4096), device="cuda", dtype=torch.int32
13 )
14 bit = 4
15 opcheck(torch.ops._C.gptq_shuffle, (weight, bit))
16
17
18 def test_gptq_gemm_opcheck():
19 a = torch.rand((240, 4096), device="cuda", dtype=torch.float16)
20 weight = torch.randint(
21 -2000000, 2000000, (512, 6144), device="cuda", dtype=torch.int32
22 )
23 zeros = torch.zeros((32, 768), device="cuda", dtype=torch.int32)
24 scales = torch.rand((32, 6144), device="cuda", dtype=torch.float16)
25 use_exllama = True
26 bit = 4
27 # Test both GPTQv1 and GPTQv2 format
28 opcheck(torch.ops._C.gptq_gemm, (a, weight, zeros, scales, use_exllama, True, bit))
29 opcheck(torch.ops._C.gptq_gemm, (a, weight, zeros, scales, use_exllama, False, bit))