MCPcopy Index your code
hub / github.com/hpcaitech/ColossalAI / test_linear

Function test_linear

tests/test_smoothquant/test_smoothquant_linear.py:20–35  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

18 reason="smoothquant linear not installed properly",
19)
20def test_linear():
21 a = torch.randint(-127, 127, (128, 512), dtype=torch.int8, device="cuda")
22 b = torch.randint(-127, 127, (512, 256), dtype=torch.int8, device="cuda")
23 c = torch.rand(256, dtype=torch.float, device="cuda")
24
25 alpha = 1 / 127
26 beta = 1.0
27 torch_out = torch.mm(a.to(torch.float) * alpha, b.to(torch.float)) + c
28
29 silu = torch.nn.SiLU()
30 torch_out = silu(torch_out)
31
32 b = b.transpose(0, 1).contiguous()
33 cuda_out = smoothquant_cuda.linear_silu_a8_w8_bfp32_ofp32(a, b, c, alpha, beta)
34
35 assert torch.allclose(torch_out, cuda_out, rtol=1e-02, atol=1e-02)
36
37
38if __name__ == "__main__":

Callers 1

Calls 1

toMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…