Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix failing FP6 benchmark #928

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 14 additions & 11 deletions benchmarks/benchmark_fp6.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,26 @@
import torch
import pandas as pd
import torch.nn.functional as F
from torchao.dtypes import to_affine_quantized_floatx
from torchao.dtypes.floatx import FloatxTensorCoreAQTLayout, FloatxTensorCoreLayoutType
import torchao
from torchao.dtypes.floatx import from_scaled_tc_floatx, to_scaled_tc_floatx
from torchao.utils import benchmark_torch_function_in_microseconds
from tqdm import tqdm


def benchmark(m: int, k: int, n: int):
float_data = torch.randn(n, k, dtype=torch.half, device="cuda")
fp6_weight = to_affine_quantized_floatx(float_data, FloatxTensorCoreLayoutType(3, 2))
fp16_weight = fp6_weight.dequantize(torch.half)
ebits = 3
mbits = 2

fp16_act = torch.randn(m, k, dtype=torch.half, device="cuda")
fp6_output = F.linear(fp16_act, fp6_weight)
fp16_output = F.linear(fp16_act, fp16_weight)
fp32_weight = torch.randn(n, k, device="cuda")
fp6_weight, scale = to_scaled_tc_floatx(fp32_weight, ebits, mbits)
fp16_act = torch.randn(m, k, dtype=torch.half, device="cuda") + 0.5

fp6_time = benchmark_torch_function_in_microseconds(F.linear, fp16_act, fp6_weight)
fp16_time = benchmark_torch_function_in_microseconds(F.linear, fp16_act, fp16_weight)
fp6_output = torchao.ops.quant_llm_linear(ebits, mbits, fp16_act, fp6_weight, scale, splitK=1)

fp16_weight = from_scaled_tc_floatx(fp6_weight, ebits, mbits, scale).half()
fp16_output = torch.matmul(fp16_act, fp16_weight.T)

fp6_time = benchmark_torch_function_in_microseconds(torchao.ops.quant_llm_linear, ebits, mbits, fp16_act, fp6_weight, scale, splitK=1)
fp16_time = benchmark_torch_function_in_microseconds(torch.matmul, fp16_act, fp16_weight.T)

# follow https://github.com/usyd-fsalab/fp6_llm/blob/ce76774bcfc26b325c1b558abcf1935026d9abbc/tests/python/kernel_test.py
# doesn't seem to be the right way to check for correctness
Expand Down
Loading