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

Add FP8 rowwise and tensorwise unittests with cudagraph #2609

Closed
wants to merge 1 commit into from
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
31 changes: 22 additions & 9 deletions fbgemm_gpu/experimental/gen_ai/test/quantize/quantize_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,23 +126,36 @@ def test_quantize_fp8_matmul(
)

if Mode == "tensorwise":
xq, x_scale = torch.ops.fbgemm.quantize_fp8_per_tensor(x)
wq, w_scale = torch.ops.fbgemm.quantize_fp8_per_tensor(w)
zq = torch.ops.fbgemm.f8f8bf16(xq, wq, x_scale * w_scale)
g = torch.cuda.CUDAGraph()
with torch.cuda.graph(g):
xq, x_scale = torch.ops.fbgemm.quantize_fp8_per_tensor(x)
wq, w_scale = torch.ops.fbgemm.quantize_fp8_per_tensor(w)
zq = torch.ops.fbgemm.f8f8bf16(xq, wq, x_scale * w_scale)
g.replay()
if bias is not None:
zq += bias
elif Mode == "tensorwise_broadcast":
xq, x_scale = torch.ops.fbgemm.quantize_fp8_per_tensor(x)
wq, w_scale = torch.ops.fbgemm.quantize_fp8_per_tensor(w)
zq = torch.ops.fbgemm.f8f8bf16_tensorwise(
xq, wq, (x_scale * w_scale).item()
)
x_scale = x_scale.item()
w_scale = w_scale.item()
g = torch.cuda.CUDAGraph()
with torch.cuda.graph(g):
zq = torch.ops.fbgemm.f8f8bf16_tensorwise(xq, wq, x_scale * w_scale)
g.replay()
if bias is not None:
zq += bias
elif Mode == "rowwise":
xq, x_scale = torch.ops.fbgemm.quantize_fp8_per_row(x, output_dtype=QType)
wq, w_scale = torch.ops.fbgemm.quantize_fp8_per_row(w)
zq = torch.ops.fbgemm.f8f8bf16_rowwise(xq, wq, x_scale, w_scale, bias=bias)
g = torch.cuda.CUDAGraph()
with torch.cuda.graph(g):
xq, x_scale = torch.ops.fbgemm.quantize_fp8_per_row(
x, output_dtype=QType
)
wq, w_scale = torch.ops.fbgemm.quantize_fp8_per_row(w)
zq = torch.ops.fbgemm.f8f8bf16_rowwise(
xq, wq, x_scale, w_scale, bias=bias
)
g.replay()
else:
raise ValueError(f"Invalid mode {Mode}")

Expand Down
Loading