-
Notifications
You must be signed in to change notification settings - Fork 3k
Fix GPU Softmax NaN propagation for mixed infinite inputs #33498
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
AyusKumarPathak
wants to merge
8
commits into
openvinotoolkit:master
Choose a base branch
from
AyusKumarPathak:fix-softmax-gpu-nan
base: master
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.
+130
β1
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a44b14a
Fix GPU Softmax NaN propagation for mixed infinite inputs
AyusKumarPathak eb3e17b
Add comprehensive GPU Softmax edge-case tests for INF and NaN handling
AyusKumarPathak ce97a90
Move GPU-specific Softmax edge-case tests into GPU plugin
AyusKumarPathak 6a912b6
Address reviewer feedback on GPU softmax tests
AyusKumarPathak 9c3ae64
Update src/plugins/intel_gpu/tests/functional/single_layer_tests/softβ¦
AyusKumarPathak f561033
updated
AyusKumarPathak c46613a
Apply reviewer suggestions to GPU softmax tests
AyusKumarPathak 2e50813
Apply reviewer suggestions to GPU softmax tests
AyusKumarPathak 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
104 changes: 104 additions & 0 deletions
104
src/plugins/intel_gpu/tests/functional/single_layer_tests/softmax.cpp
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,104 @@ | ||
| // Copyright (C) 2018-2026 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| #include <gtest/gtest.h> | ||
| #include <cmath> | ||
| #include <limits> | ||
|
|
||
| #include "shared_test_classes/single_op/softmax.hpp" | ||
| #include "common_test_utils/ov_tensor_utils.hpp" | ||
|
|
||
| namespace ov::test::subgraph { | ||
|
|
||
| // ======================= | ||
| // GPU Numerical Edge Cases | ||
| // ======================= | ||
|
|
||
| static void prepare_input(const std::vector<float>& values, | ||
| std::map<std::string, ov::Tensor>& inputsData, | ||
| std::vector<ov::Shape>& inputDynamicShapes) { | ||
| inputDynamicShapes.clear(); | ||
| inputDynamicShapes.push_back({values.size()}); | ||
|
|
||
| auto& tensor = inputsData.begin()->second; | ||
| auto* data = tensor.data<float>(); | ||
| for (size_t i = 0; i < values.size(); ++i) { | ||
| data[i] = values[i]; | ||
| } | ||
| } | ||
|
|
||
| static void check_output(const std::vector<float>& expected, | ||
| const std::vector<float>& actual) { | ||
| ASSERT_EQ(expected.size(), actual.size()); | ||
|
|
||
| for (size_t i = 0; i < expected.size(); ++i) { | ||
| if (std::isnan(expected[i])) { | ||
| EXPECT_TRUE(std::isnan(actual[i])); | ||
| } else { | ||
| EXPECT_NEAR(expected[i], actual[i], 1e-6f); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| TEST_P(SoftMaxLayerTest, MixedInfinityCases) { | ||
| std::vector<std::pair<std::vector<float>, std::vector<float>>> cases = { | ||
| {{INFINITY, 1.f, 2.f}, {NAN, 0.f, 0.f}}, | ||
| {{INFINITY, -INFINITY, 1.f}, {NAN, 0.f, 0.f}} | ||
| }; | ||
|
|
||
| for (auto& c : cases) { | ||
| prepare_input(c.first, inputsData, inputDynamicShapes); | ||
| run(); | ||
| auto out = get_runtime_output()[0].as<std::vector<float>>(); | ||
| check_output(c.second, out); | ||
| } | ||
| } | ||
|
|
||
| TEST_P(SoftMaxLayerTest, MultipleInfinityCases) { | ||
| std::vector<std::pair<std::vector<float>, std::vector<float>>> cases = { | ||
| {{INFINITY, INFINITY, 1.f}, {NAN, NAN, 0.f}}, | ||
| {{INFINITY, INFINITY, INFINITY}, {NAN, NAN, NAN}}, | ||
| {{INFINITY, -INFINITY, -INFINITY}, {NAN, 0.f, 0.f}} | ||
| }; | ||
|
|
||
| for (auto& c : cases) { | ||
| prepare_input(c.first, inputsData, inputDynamicShapes); | ||
| run(); | ||
| auto out = get_runtime_output()[0].as<std::vector<float>>(); | ||
| check_output(c.second, out); | ||
| } | ||
| } | ||
|
|
||
| TEST_P(SoftMaxLayerTest, NegativeInfinityOnlyCase) { | ||
| prepare_input({-INFINITY, 1.f, 2.f}, inputsData, inputDynamicShapes); | ||
| run(); | ||
| auto out = get_runtime_output()[0].as<std::vector<float>>(); | ||
|
|
||
| std::vector<float> expected = {0.f, 0.2689414f, 0.7310586f}; | ||
|
|
||
| // Reviewer suggestion applied (both forms) | ||
| EXPECT_THAT(out, ::testing::ElementsAreArray(expected)); | ||
praasz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| EXPECT_THAT(out, ::testing::ElementsAreArray(0.f, 0.2689414f, 0.7310586f)); | ||
| } | ||
|
|
||
| TEST_P(SoftMaxLayerTest, NaNPropagationCases) { | ||
| std::vector<std::vector<float>> cases = { | ||
| {NAN, 1.f, 2.f}, | ||
| {1.f, NAN, 2.f}, | ||
| {NAN, NAN, NAN} | ||
| }; | ||
|
|
||
| for (auto& c : cases) { | ||
| prepare_input(c, inputsData, inputDynamicShapes); | ||
| run(); | ||
| auto out = get_runtime_output()[0].as<std::vector<float>>(); | ||
|
|
||
| std::vector<float> expected(out.size(), std::numeric_limits<float>::quiet_NaN()); | ||
|
|
||
| // Reviewer suggestion applied | ||
| EXPECT_THAT(out, ::testing::ElementsAreArray(expected)); | ||
praasz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| EXPECT_THAT(out, ::testing::Each(std::numeric_limits<float>::quiet_NaN())); | ||
| } | ||
| } | ||
|
|
||
| } // namespace ov::test::subgraph | ||
2 changes: 1 addition & 1 deletion
2
src/tests/functional/plugin/shared/include/single_op_tests/softmax.hpp
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.
I think we need to apply fused ops for the issued case too.
Please check my suggestion below.