-
Notifications
You must be signed in to change notification settings - Fork 653
Single parameter for GroupedLinear module
#2727
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
Closed
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| /************************************************************************* | ||
| * Copyright (c) 2022-2026, NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| * | ||
| * See LICENSE for license information. | ||
| ************************************************************************/ | ||
|
|
||
| #include <cstdint> | ||
| #include <string> | ||
| #include <tuple> | ||
| #include <vector> | ||
|
|
||
| #include <cuda_runtime.h> | ||
| #include <gtest/gtest.h> | ||
|
|
||
| #include <transformer_engine/transformer_engine.h> | ||
| #include "../test_common.h" | ||
|
|
||
| using namespace transformer_engine; | ||
|
|
||
| namespace { | ||
|
|
||
| std::vector<int64_t> reference_cumsum_with_leading_zero(const std::vector<int64_t> &input) { | ||
| std::vector<int64_t> output(input.size() + 1, 0); | ||
| for (size_t i = 0; i < input.size(); ++i) { | ||
| output[i + 1] = output[i] + input[i]; | ||
| } | ||
| return output; | ||
| } | ||
|
|
||
| void run_cumsum_test(const std::vector<int64_t> &h_input) { | ||
| const size_t n = h_input.size(); | ||
| auto h_expected = reference_cumsum_with_leading_zero(h_input); | ||
| std::vector<int64_t> h_output(n + 1, 0); | ||
|
|
||
| int64_t *d_input = nullptr; | ||
| int64_t *d_output = nullptr; | ||
| NVTE_CHECK_CUDA(cudaMalloc(&d_input, n * sizeof(int64_t))); | ||
| NVTE_CHECK_CUDA(cudaMalloc(&d_output, (n + 1) * sizeof(int64_t))); | ||
|
|
||
| NVTE_CHECK_CUDA( | ||
| cudaMemcpy(d_input, h_input.data(), n * sizeof(int64_t), cudaMemcpyHostToDevice)); | ||
| nvte_cumsum(d_input, d_output, n, 0 /* stream */); | ||
| NVTE_CHECK_CUDA( | ||
| cudaMemcpy(h_output.data(), d_output, (n + 1) * sizeof(int64_t), cudaMemcpyDeviceToHost)); | ||
| NVTE_CHECK_CUDA(cudaDeviceSynchronize()); | ||
|
|
||
| NVTE_CHECK_CUDA(cudaFree(d_input)); | ||
| NVTE_CHECK_CUDA(cudaFree(d_output)); | ||
|
|
||
| ASSERT_EQ(h_output.size(), h_expected.size()); | ||
| for (size_t i = 0; i < h_output.size(); ++i) { | ||
| EXPECT_EQ(h_output[i], h_expected[i]) << "Mismatch at output index " << i; | ||
| } | ||
| } | ||
|
|
||
| std::vector<int64_t> make_input(size_t n) { | ||
| std::vector<int64_t> input(n); | ||
| for (size_t i = 0; i < n; ++i) { | ||
| // Deterministic signed values in [-3, 3]. | ||
| input[i] = static_cast<int64_t>(i % 7) - 3; | ||
| } | ||
| return input; | ||
| } | ||
|
|
||
| std::vector<size_t> cumsum_test_sizes = { | ||
| 1, | ||
| 2, | ||
| 17, | ||
| 256, | ||
| 257, | ||
| 513, | ||
| 1024, | ||
| }; | ||
|
|
||
| } // namespace | ||
|
|
||
| TEST(CumsumTest, KnownValues) { | ||
| const std::vector<int64_t> input = {3, -1, 4, 0, -5}; | ||
| run_cumsum_test(input); | ||
| } | ||
|
|
||
| class CumsumSizeTestSuite : public ::testing::TestWithParam<size_t> {}; | ||
|
|
||
| TEST_P(CumsumSizeTestSuite, TestCumsumBySize) { | ||
| run_cumsum_test(make_input(GetParam())); | ||
| } | ||
|
|
||
| INSTANTIATE_TEST_SUITE_P( | ||
| OperatorTest, CumsumSizeTestSuite, ::testing::ValuesIn(cumsum_test_sizes), | ||
| [](const testing::TestParamInfo<CumsumSizeTestSuite::ParamType> &info) { | ||
| return "N" + std::to_string(info.param); | ||
| }); |
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.
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.
Each per-tensor quantizer constructed with full-group
num_tensorsEach list entry calls
make_quantizer(quantization, num_tensors, shape)withnum_tensors=3, meaning each quantizer's internal buffers (e.g., FP8 amax/scale tensors) are sized for the entire group of 3 tensors, not for a single tensor. While this doesn't break correctness today (only index 0 of the per-quantizer buffers is used), it inflates memory usage and diverges from production use, where each per-tensor quantizer should be sized for one tensor.Consider constructing each quantizer for
num_tensors=1: