Skip to content

Simplify grouped gemm output allocations #4134

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -574,15 +574,14 @@ bf16bf16bf16_grouped_stacked(at::Tensor X, at::Tensor W, at::Tensor M_sizes) {
"M_sizes must be on same device as inputs.");
TORCH_CHECK(
W.dim() == 3 && W.size(0) == G, "Weights should be shape [G, N, K].")
at::Tensor Y = at::empty(total_M * N, X.options().dtype(at::kBFloat16));
at::Tensor Y = at::empty({total_M, N}, X.options().dtype(at::kBFloat16));
// Early exit for empty inputs.
if (total_M == 0) {
return Y.view({total_M, N});
return Y;
}
// Return continuous view of output.
at::Tensor out = dispatch_bf16_grouped_kernel<at::Tensor>(
return dispatch_bf16_grouped_kernel<at::Tensor>(
total_M, X, W, Y, std::nullopt, M_sizes);
return out.view({total_M, N});
}

at::Tensor bf16bf16bf16_grouped_dynamic(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -732,15 +732,14 @@ at::Tensor f8f8bf16_rowwise_grouped_stacked(
"M_sizes must be on same device as inputs.");
TORCH_CHECK(
WQ.dim() == 3 && WQ.size(0) == G, "Weights should be shape [G, N, K].")
at::Tensor Y = at::empty(total_M * N, XQ.options().dtype(at::kBFloat16));
at::Tensor Y = at::empty({total_M, N}, XQ.options().dtype(at::kBFloat16));
// Early exit for empty inputs.
if (total_M == 0) {
return Y.view({total_M, N});
return Y;
}
// Return continuous view of output.
at::Tensor out = dispatch_fp8_grouped_kernel<at::Tensor>(
return dispatch_fp8_grouped_kernel<at::Tensor>(
total_M, XQ, WQ, x_scale, w_scale, Y, std::nullopt, M_sizes);
return out.view({total_M, N});
}

at::Tensor f8f8bf16_rowwise_grouped_dynamic(
Expand Down
Loading