-
Notifications
You must be signed in to change notification settings - Fork 718
[PyTorch] Add workaround for cuteDSL stride requirement for zero-token expert #2947
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -58,19 +58,41 @@ def _cudnn_compute_wgrad( | |
|
|
||
| fp8_dtype = torch.float8_e4m3fn | ||
|
|
||
| # a_tensor = DY^T = (out_features, total_tokens) row-major | ||
| a_tensor = grouped_dy.columnwise_data.view(dtype=fp8_dtype).view(total_tokens, out_features).T | ||
| # b_tensor = X = (total_tokens, in_features) column-major | ||
| b_tensor = grouped_x.columnwise_data.view(dtype=fp8_dtype).view(total_tokens, in_features) | ||
|
|
||
| sfa_leading_dim = ((out_features + 127) // 128) * 128 | ||
| sfb_leading_dim = ((in_features + 127) // 128) * 128 | ||
| sfa_tensor = grouped_dy.columnwise_scale_inv.view(sfa_leading_dim, -1).view( | ||
| dtype=torch.float8_e8m0fnu | ||
| ) | ||
| sfb_tensor = grouped_x.columnwise_scale_inv.view(sfb_leading_dim, -1).view( | ||
| dtype=torch.float8_e8m0fnu | ||
| ) | ||
|
|
||
| if total_tokens == 0: | ||
| # A workaround for the case with zero-token experts. | ||
| # Even for this case, cuteDSL still requires the same | ||
| # stride requirements for the input and scale tensors. | ||
| device = grouped_dy.columnwise_data.device | ||
| a_tensor = torch.empty_strided((out_features, 0), (16, 1), dtype=fp8_dtype, device=device) | ||
| b_tensor = torch.empty_strided( | ||
| (0, in_features), (in_features, 1), dtype=fp8_dtype, device=device | ||
| ) | ||
| sfa_tensor = torch.empty_strided( | ||
| (sfa_leading_dim, 0), | ||
| (16, 1), | ||
| dtype=torch.float8_e8m0fnu, | ||
| device=device, | ||
| ) | ||
| sfb_tensor = torch.empty_strided( | ||
| (sfb_leading_dim, 0), | ||
| (16, 1), | ||
| dtype=torch.float8_e8m0fnu, | ||
| device=device, | ||
| ) | ||
|
Comment on lines
+69
to
+84
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The value |
||
| else: | ||
| a_tensor = ( | ||
| grouped_dy.columnwise_data.view(dtype=fp8_dtype).view(total_tokens, out_features).T | ||
| ) | ||
| b_tensor = grouped_x.columnwise_data.view(dtype=fp8_dtype).view(total_tokens, in_features) | ||
| sfa_tensor = grouped_dy.columnwise_scale_inv.view(sfa_leading_dim, -1).view( | ||
| dtype=torch.float8_e8m0fnu | ||
| ) | ||
| sfb_tensor = grouped_x.columnwise_scale_inv.view(sfb_leading_dim, -1).view( | ||
| dtype=torch.float8_e8m0fnu | ||
| ) | ||
|
|
||
| # Prepare wgrad output | ||
| if single_grouped_weight: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description states this workaround will be removed once the upstream fix lands in
cutedsl, but the in-code comment has no corresponding TODO or issue-tracker reference. Without one, there's no actionable reminder to clean this up once the upstream fix is released.