-
Notifications
You must be signed in to change notification settings - Fork 687
Skip activation kernels when tensor size is zero #2848
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
timmoon10
wants to merge
6
commits into
NVIDIA:main
Choose a base branch
from
timmoon10:tmoon/activations-with-zero-size-tensor
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d0081f0
Skip quantization kernels when tensor size is zero
timmoon10 a61dfe2
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6df9853
Merge branch 'main' into tmoon/activations-with-zero-size-tensor
timmoon10 43e685f
Merge branch 'main' into tmoon/activations-with-zero-size-tensor
timmoon10 ea6f858
Use consistent early-termination logic in dbias kernels
timmoon10 e05f353
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -844,13 +844,7 @@ void group_quantize(const GroupedTensor *input, const GroupedTensor *activations | |
| e8m0_t *const scales_rowwise_ptr = reinterpret_cast<e8m0_t *>(output->scale_inv.dptr); | ||
| e8m0_t *const scales_colwise_ptr = reinterpret_cast<e8m0_t *>(output->columnwise_scale_inv.dptr); | ||
|
|
||
| if (use_rowwise_scaling) { | ||
| NVTE_CHECK(scales_rowwise_ptr != nullptr, "Scaling tensor must be allocated"); | ||
| } | ||
| if (use_colwise_scaling) { | ||
| NVTE_CHECK(scales_colwise_ptr != nullptr, "Columnwise scaling tensor must be allocated"); | ||
| } | ||
|
|
||
| // Workspace for dbias | ||
| if constexpr (IS_DBIAS) { | ||
| NVTE_CHECK(is_single_tensor, | ||
| "DBias is only supported for tensors with the const last dimension."); | ||
|
|
@@ -863,13 +857,34 @@ void group_quantize(const GroupedTensor *input, const GroupedTensor *activations | |
| NVTE_CHECK(workspace != nullptr, "Workspace must be a tensor."); | ||
| const size_t dbias_workspace_rows = DIVUP(first_logical_dim, static_cast<size_t>(CHUNK_DIM_Y)); | ||
| const size_t dbias_workspace_cols = last_logical_dim; | ||
| NVTE_CHECK(dbias_workspace_rows > 0 && dbias_workspace_cols > 0, | ||
| "Invalid workspace shape for DBias computation (input first_logical_dim=", | ||
| first_logical_dim, ", input last_logical_dim=", last_logical_dim, | ||
| ", workspace shape=(", dbias_workspace_rows, ",", dbias_workspace_cols, "))."); | ||
| if (workspace->data.dptr == nullptr) { | ||
| workspace->data.shape = {dbias_workspace_rows, dbias_workspace_cols}; | ||
| workspace->data.dtype = DType::kFloat32; | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| // Skip kernel if tensor size is zero | ||
| if (elts_total == 0) { | ||
| if constexpr (IS_DBIAS) { | ||
| NVTE_ERROR("Invalid grouped tensor shape for DBias computation (first_logical_dim=", | ||
|
Collaborator
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. In this case we can output dbias = zero tensor also right instead of throwing an error? |
||
| first_logical_dim, ", last_logical_dim=", last_logical_dim, ")"); | ||
| } | ||
| return; | ||
| } | ||
|
|
||
| // Check pointers | ||
| if (use_rowwise_scaling) { | ||
| NVTE_CHECK(scales_rowwise_ptr != nullptr, "Scaling tensor must be allocated"); | ||
| } | ||
| if (use_colwise_scaling) { | ||
| NVTE_CHECK(scales_colwise_ptr != nullptr, "Columnwise scaling tensor must be allocated"); | ||
| } | ||
|
|
||
| TRANSFORMER_ENGINE_TYPE_SWITCH_NON_FP8ONLY( | ||
| input->dtype(), IType, | ||
| TRANSFORMER_ENGINE_TYPE_SWITCH_FP8ONLY( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
So this problem shows up not only for activations, but also for a regular cast?
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.
Yep, many of our kernels are not robust to empty tensors. I still expect to see problems in the FP8 block-scale quantization kernels and transpose kernels.