Skip to content

OpenVINO™ is an open source toolkit for optimizing and deploying AI inference

[PT FE] Support scalar (rank-0) input for aten::log_softmax and aten::softmax (#34065)

Evgeny Kotovba4782cd9d6e
diff --git a/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp b/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp
index 9319554ded7..de6c4af5db7 100644
--- a/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp
+++ b/src/common/transformations/src/transformations/op_conversions/convert_softmax_downgrade.cpp
@@ -8,11 +8,13 @@
#include "openvino/core/graph_util.hpp"
#include "openvino/core/rt_info.hpp"
#include "openvino/core/validation_util.hpp"
+#include "openvino/op/constant.hpp"
#include "openvino/op/softmax.hpp"
#include "openvino/pass/pattern/op/wrap_type.hpp"
using ov::pass::pattern::Matcher;
+namespace v0 = ov::op::v0;
namespace v8 = ov::op::v8;
ov::pass::ConvertSoftMax8ToSoftMax1::ConvertSoftMax8ToSoftMax1() {
MATCHER_SCOPE(ConvertSoftMax8ToSoftMax1);
@@ -27,6 +29,17 @@ ov::pass::ConvertSoftMax8ToSoftMax1::ConvertSoftMax8ToSoftMax1() {
auto v8_axis = softmax_v8_node->get_axis();
auto rank = softmax_v8_node->get_input_partial_shape(0).rank().get_length();
+
+ // Scalar (rank-0) input: softmax of a single value is always 1.
+ // Replace with constant to avoid axis validation issues downstream.
+ if (rank == 0) {
+ auto one_const = v0::Constant::create(softmax_v8_node->get_output_element_type(0), ov::Shape{}, {1});
+ one_const->set_friendly_name(softmax_v8_node->get_friendly_name());
+ copy_runtime_info(softmax_v8_node, one_const);
+ replace_node(softmax_v8_node, one_const);
+ return true;
+ }
+
auto v1_axis = ov::util::try_normalize_axis(v8_axis, rank, *softmax_v8_node);
auto softmax_v1_node = std::make_shared<ov::op::v1::Softmax>(softmax_v8_node->input_value(0), v1_axis);
diff --git a/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp
index 6bc60616b68..c537da6f7d2 100644
--- a/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp
+++ b/src/common/transformations/src/transformations/op_conversions/log_softmax_decomposition.cpp
@@ -38,6 +38,16 @@ ov::pass::LogSoftmaxDecomposition::LogSoftmaxDecomposition() {
return false;
}
+ // Handle scalar (rank-0) input: log_softmax of a single value is always 0.
+ const auto& input_pshape = log_softmax_node->get_input_partial_shape(0);
+ if (input_pshape.rank().is_static() && input_pshape.rank().get_length() == 0) {
+ auto zero_const = v0::Constant::create(log_softmax_node->get_output_element_type(0), ov::Shape{}, {0});
+ zero_const->set_friendly_name(m.get_match_root()->get_friendly_name());
+ ov::copy_runtime_info(log_softmax_node, zero_const);
+ ov::replace_node(m.get_match_root(), zero_const);
+ return true;
+ }
+
auto axis1 = v0::Constant::create(element::Type_t::i64, ov::Shape{1}, {log_softmax_node->get_axis()});
auto axis2 = v0::Constant::create(element::Type_t::i64, ov::Shape{1}, {log_softmax_node->get_axis()});
auto max = std::make_shared<v1::ReduceMax>(log_softmax_node->input_value(0), axis1, true);
diff --git a/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp b/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp
index 5159d7575c1..bf8b79aff45 100644
--- a/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp
+++ b/src/common/transformations/src/transformations/op_conversions/softmax_decomposition.cpp
@@ -38,6 +38,16 @@ ov::pass::SoftmaxDecomposition::SoftmaxDecomposition() {
return false;
}
+ // Handle scalar (rank-0) input: softmax of a single value is always 1.
+ const auto& input_pshape = m_softmax->get_input_partial_shape(0);
+ if (input_pshape.rank().is_static() && input_pshape.rank().get_length() == 0) {
+ auto one_const = v0::Constant::create(m_softmax->get_output_element_type(0), ov::Shape{}, {1});
+ one_const->set_friendly_name(m_softmax->get_friendly_name());
+ ov::copy_runtime_info(m_softmax, one_const);
+ ov::replace_node(m_softmax, one_const);
+ return true;
+ }
+
if (auto m_softmax_v1 = ov::as_type_ptr<v1::Softmax>(m_softmax)) {
input = m_softmax_v1->input_value(0);
softmax_axis = static_cast<int64_t>(m_softmax_v1->get_axis());
diff --git a/src/common/transformations/tests/op_conversions/convert_softmax_downgrade_test.cpp b/src/common/transformations/tests/op_conversions/convert_softmax_downgrade_test.cpp
index 9f4d07c5eb3..ad1275c5ef3 100644
--- a/src/common/transformations/tests/op_conversions/convert_softmax_downgrade_test.cpp
+++ b/src/common/transformations/tests/op_conversions/convert_softmax_downgrade_test.cpp
@@ -11,6 +11,7 @@
#include "common_test_utils/ov_test_utils.hpp"
#include "openvino/core/model.hpp"
+#include "openvino/op/constant.hpp"
#include "openvino/op/softmax.hpp"
#include "openvino/opsets/opset1_decl.hpp"
#include "openvino/opsets/opset8_decl.hpp"
@@ -94,3 +95,21 @@ TEST_F(TransformationTestsF, negative_ConvertSoftMax8ToSoftMax1_dynamic_rank) {
model_ref = std::make_shared<ov::Model>(OutputVector{softmax_8}, ParameterVector{data});
}
}
+
+TEST_F(TransformationTestsF, ConvertSoftMax8ToSoftMax1_scalar) {
+ {
+ auto data = std::make_shared<opset1::Parameter>(element::f32, Shape{});
+ int64_t axis = 0;
+ auto softmax_8 = std::make_shared<opset8::Softmax>(data, axis);
+
+ model = std::make_shared<ov::Model>(OutputVector{softmax_8}, ParameterVector{data});
+ manager.register_pass<ov::pass::ConvertSoftMax8ToSoftMax1>();
+ }
+
+ {
+ auto data = std::make_shared<opset1::Parameter>(element::f32, Shape{});
+ auto one_const = ov::op::v0::Constant::create(element::f32, Shape{}, {1});
+
+ model_ref = std::make_shared<ov::Model>(OutputVector{one_const}, ParameterVector{data});
+ }
+}
diff --git a/src/common/transformations/tests/op_conversions/log_softmax_decomposition_test.cpp b/src/common/transformations/tests/op_conversions/log_softmax_decomposition_test.cpp
index a6dca6925a1..229a226efc9 100644
--- a/src/common/transformations/tests/op_conversions/log_softmax_decomposition_test.cpp
+++ b/src/common/transformations/tests/op_conversions/log_softmax_decomposition_test.cpp
@@ -11,6 +11,7 @@
#include "common_test_utils/ov_test_utils.hpp"
#include "openvino/core/model.hpp"
+#include "openvino/op/constant.hpp"
#include "openvino/op/exp.hpp"
#include "openvino/op/log.hpp"
#include "openvino/op/log_softmax.hpp"
@@ -48,3 +49,21 @@ TEST_F(TransformationTestsF, LogSoftmaxDecomposition) {
model_ref = std::make_shared<ov::Model>(OutputVector{sub_end}, ParameterVector{input0});
}
}
+
+TEST_F(TransformationTestsF, LogSoftmaxDecompositionScalar) {
+ {
+ auto data = std::make_shared<opset5::Parameter>(element::f32, Shape{});
+ auto log_softmax = std::make_shared<opset5::LogSoftmax>(data, 0);
+
+ model = std::make_shared<ov::Model>(OutputVector{log_softmax}, ParameterVector{data});
+
+ manager.register_pass<ov::pass::LogSoftmaxDecomposition>();
+ }
+
+ {
+ auto data = std::make_shared<opset5::Parameter>(element::f32, Shape{});
+ auto zero_const = ov::op::v0::Constant::create(element::f32, Shape{}, {0});
+
+ model_ref = std::make_shared<ov::Model>(OutputVector{zero_const}, ParameterVector{data});
+ }
+}
diff --git a/src/common/transformations/tests/op_conversions/softmax_decomposition_test.cpp b/src/common/transformations/tests/op_conversions/softmax_decomposition_test.cpp
new file mode 100644
index 00000000000..fb6955f4469
--- /dev/null
+++ b/src/common/transformations/tests/op_conversions/softmax_decomposition_test.cpp
@@ -0,0 +1,38 @@
+// Copyright (C) 2018-2026 Intel Corporation
+// SPDX-License-Identifier: Apache-2.0
+//
+
+#include "transformations/op_conversions/softmax_decomposition.hpp"
+
+#include <gtest/gtest.h>
+
+#include <memory>
+#include <string>
+
+#include "common_test_utils/ov_test_utils.hpp"
+#include "openvino/core/model.hpp"
+#include "openvino/op/constant.hpp"
+#include "openvino/op/parameter.hpp"
+#include "openvino/op/softmax.hpp"
+#include "openvino/pass/manager.hpp"
+namespace ov::test {
+
+TEST_F(TransformationTestsF, SoftmaxDecompositionScalar) {
+ {
+ auto data = std::make_shared<op::v0::Parameter>(element::f32, Shape{});
+ auto softmax = std::make_shared<op::v8::Softmax>(data, 0);
+
+ model = std::make_shared<ov::Model>(OutputVector{softmax}, ParameterVector{data});
+
+ manager.register_pass<ov::pass::SoftmaxDecomposition>();
+ }
+
+ {
+ auto data = std::make_shared<op::v0::Parameter>(element::f32, Shape{});
+ auto one_const = op::v0::Constant::create(element::f32, Shape{}, {1});
+
+ model_ref = std::make_shared<ov::Model>(OutputVector{one_const}, ParameterVector{data});
+ }
+}
+
+} // namespace ov::test
diff --git a/src/core/dev_api/openvino/core/validation_util.hpp b/src/core/dev_api/openvino/core/validation_util.hpp
index 8ee9b9ecddb..6cef56e3070 100644
--- a/src/core/dev_api/openvino/core/validation_util.hpp
+++ b/src/core/dev_api/openvino/core/validation_util.hpp
@@ -146,7 +146,7 @@ OPENVINO_API bool is_axis_valid(const int64_t axis, const int64_t rank);
OPENVINO_API void validate_axis(const int64_t axis, const Rank& rank, const Node& node);
/// \brief Normalize axis against the rank.
-/// \note No input validation.
+/// \note No input validation. For rank-0 (scalar), any valid axis maps to 0.
///
/// \param axis Axis value to be normalized.
/// \param rank Rank value used for axis normalization.
diff --git a/src/core/src/op/log_softmax.cpp b/src/core/src/op/log_softmax.cpp
index 0777aa01a7d..b031e76e563 100644
--- a/src/core/src/op/log_softmax.cpp
+++ b/src/core/src/op/log_softmax.cpp
@@ -5,6 +5,7 @@
#include "openvino/op/log_softmax.hpp"
#include "itt.hpp"
+#include "openvino/core/validation_util.hpp"
namespace ov {
@@ -21,14 +22,9 @@ bool op::v5::LogSoftmax::visit_attributes(AttributeVisitor& visitor) {
void op::v5::LogSoftmax::validate_and_infer_types() {
OV_OP_SCOPE(v5_LogSoftmax_validate_and_infer_types);
const ov::PartialShape& input_shape = get_input_partial_shape(0);
- if (input_shape.rank().is_static())
- NODE_VALIDATION_CHECK(this,
- m_axis < input_shape.rank().get_length() && m_axis >= -input_shape.rank().get_length(),
- "Reduction axis (",
- m_axis,
- ") is out of bounds (argument shape: ",
- input_shape,
- ").");
+ if (const auto& rank = input_shape.rank(); rank.is_static()) {
+ ov::util::validate_axis(m_axis, rank, *this);
+ }
set_output_type(0, get_input_element_type(0), input_shape);
}
diff --git a/src/core/src/op/softmax.cpp b/src/core/src/op/softmax.cpp
index 9f692f086a5..e3ce2d2f3e2 100644
--- a/src/core/src/op/softmax.cpp
+++ b/src/core/src/op/softmax.cpp
@@ -42,14 +42,16 @@ bool Softmax::visit_attributes(AttributeVisitor& visitor) {
void Softmax::validate_and_infer_types() {
OV_OP_SCOPE(v1_Softmax_validate_and_infer_types);
const auto& input_shape = get_input_partial_shape(0);
- if (input_shape.rank().is_static())
+ if (const auto& rank = input_shape.rank(); rank.is_static()) {
+ const auto r = static_cast<size_t>(rank.get_length());
NODE_VALIDATION_CHECK(this,
- m_axis < static_cast<size_t>(input_shape.rank().get_length()),
+ r == 0 ? (m_axis == 0) : (m_axis < r),
"Reduction axis (",
m_axis,
") is out of bounds (argument shape: ",
input_shape,
").");
+ }
set_output_type(0, get_input_element_type(0), input_shape);
}
@@ -66,7 +68,11 @@ bool Softmax::evaluate(TensorVector& outputs, const TensorVector& inputs) const
OPENVINO_ASSERT(inputs.size() == 1);
const auto& input_shape = inputs[0].get_shape();
+ const auto rank = input_shape.size();
outputs[0].set_shape(input_shape);
+
+ const auto& eval_shape = (rank == 0) ? Shape{1} : input_shape;
+
using namespace ov::element;
return IF_TYPE_OF_CONVERT_TENSORS(v1_Softmax_evaluate,
this,
@@ -77,7 +83,7 @@ bool Softmax::evaluate(TensorVector& outputs, const TensorVector& inputs) const
inputs[0].get_element_type(),
inputs[0],
outputs[0],
- input_shape,
+ eval_shape,
AxisSet{m_axis});
}
@@ -109,15 +115,8 @@ bool Softmax::visit_attributes(AttributeVisitor& visitor) {
void Softmax::validate_and_infer_types() {
OV_OP_SCOPE(v8_Softmax_validate_and_infer_types);
const auto& input_shape = get_input_partial_shape(0);
- if (input_shape.rank().is_static()) {
- auto rank = static_cast<int64_t>(input_shape.size());
- NODE_VALIDATION_CHECK(this,
- -rank <= m_axis && m_axis < rank,
- "Reduction axis (",
- m_axis,
- ") is out of bounds (argument shape: ",
- input_shape,
- ").");
+ if (const auto& rank = input_shape.rank(); rank.is_static()) {
+ ov::util::validate_axis(m_axis, rank, *this);
}
set_output_type(0, get_input_element_type(0), input_shape);
@@ -136,15 +135,11 @@ bool Softmax::evaluate(TensorVector& outputs, const TensorVector& inputs) const
const auto& input_shape = inputs[0].get_shape();
const auto rank = static_cast<int64_t>(input_shape.size());
- OPENVINO_ASSERT(-rank <= m_axis && m_axis < rank,
- "Reduction axis (",
- m_axis,
- ") is out of bounds (argument shape: ",
- input_shape,
- ").");
- const auto axis = static_cast<size_t>(ov::util::normalize(m_axis, rank));
-
outputs[0].set_shape(input_shape);
+
+ const auto& eval_shape = (rank == 0) ? Shape{1} : input_shape;
+ const auto axis = (rank == 0) ? size_t{0} : ov::util::normalize_axis(m_axis, rank);
+
using namespace ov::element;
return IF_TYPE_OF_CONVERT_TENSORS(v8_Softmax_evaluate,
this,
@@ -155,7 +150,7 @@ bool Softmax::evaluate(TensorVector& outputs, const TensorVector& inputs) const
inputs[0].get_element_type(),
inputs[0],
outputs[0],
- input_shape,
+ eval_shape,
AxisSet{axis});
}
diff --git a/src/core/src/validation_util.cpp b/src/core/src/validation_util.cpp
index 827e118a4a4..5e9e8cbf314 100644
--- a/src/core/src/validation_util.cpp
+++ b/src/core/src/validation_util.cpp
@@ -30,7 +30,7 @@ std::string normalize_axis_error_msg(const int64_t axis, const int64_t rank) {
return std::string("Axis ")
.append(std::to_string(axis))
.append(" out of the tensor rank range [")
- .append(std::to_string(-rank))
+ .append(std::to_string(rank == 0 ? -1 : -rank))
.append(", ")
.append(std::to_string(rank == 0 ? 0 : rank - 1))
.append("].");
@@ -324,7 +324,7 @@ bool has_no_symbols(const ov::TensorSymbol& symbols) {
}
bool is_axis_valid(int64_t axis, int64_t rank) {
- return (axis == 0) || (-rank <= axis && axis < rank);
+ return (axis == 0) || (axis == -1) || (-rank <= axis && axis < rank);
}
void validate_axis(const int64_t axis, const Rank& rank, const Node& node) {
@@ -333,7 +333,7 @@ void validate_axis(const int64_t axis, const Rank& rank, const Node& node) {
}
size_t normalize_axis(const int64_t axis, const int64_t rank) {
- return static_cast<size_t>(normalize(axis, rank));
+ return rank > 0 ? static_cast<size_t>(normalize(axis, rank)) : 0U;
}
size_t try_normalize_axis(const int64_t axis, const Rank& rank) {
@@ -355,7 +355,7 @@ void validate_axes(const std::vector<int64_t>& axes, const Rank& rank, const Nod
void normalize_axes(std::vector<int64_t>& axes, const int64_t rank) {
for (auto&& axis : axes) {
- axis = normalize(axis, rank);
+ axis = rank > 0 ? normalize(axis, rank) : 0;
}
}
diff --git a/src/core/tests/type_prop/log_softmax.cpp b/src/core/tests/type_prop/log_softmax.cpp
index 6af4a6cfee7..7cb82970038 100644
--- a/src/core/tests/type_prop/log_softmax.cpp
+++ b/src/core/tests/type_prop/log_softmax.cpp
@@ -4,6 +4,7 @@
#include "openvino/op/log_softmax.hpp"
+#include "common_test_utils/test_assertions.hpp"
#include "common_test_utils/type_prop.hpp"
using namespace std;
@@ -19,12 +20,9 @@ TEST(type_prop, log_softmax) {
TEST(type_prop, log_softmax_incorrect_axis) {
const auto data = make_shared<ov::op::v0::Parameter>(element::f32, Shape{1, 3, 6});
- try {
- auto log_softmax_func = make_shared<op::v5::LogSoftmax>(data, 3);
- FAIL() << "LogSoftmax node was created with incorrect axis.";
- } catch (const NodeValidationFailure& error) {
- EXPECT_HAS_SUBSTRING(error.what(), std::string("Reduction axis (3) is out of bounds"));
- }
+ OV_EXPECT_THROW(std::ignore = make_shared<op::v5::LogSoftmax>(data, 3),
+ NodeValidationFailure,
+ testing::HasSubstr("Axis 3 out of the tensor rank range"));
}
// TEST(type_prop, log_softmax_partial)
@@ -49,3 +47,17 @@ TEST(type_prop, log_softmax_partial_static_rank) {
ASSERT_TRUE(log_softmax_func->get_output_partial_shape(0).same_scheme((PartialShape{1, Dimension::dynamic(), 6})));
ASSERT_TRUE(log_softmax_func->get_output_partial_shape(0).rank().is_static());
}
+
+TEST(type_prop, log_softmax_scalar) {
+ auto data = make_shared<ov::op::v0::Parameter>(element::f32, Shape{});
+ auto log_softmax_func = make_shared<op::v5::LogSoftmax>(data, 0);
+ EXPECT_EQ(log_softmax_func->get_element_type(), element::f32);
+ EXPECT_EQ(log_softmax_func->get_output_partial_shape(0), (PartialShape{}));
+}
+
+TEST(type_prop, log_softmax_scalar_neg_axis) {
+ auto data = make_shared<ov::op::v0::Parameter>(element::f32, Shape{});
+ auto log_softmax_func = make_shared<op::v5::LogSoftmax>(data, -1);
+ EXPECT_EQ(log_softmax_func->get_element_type(), element::f32);
+ EXPECT_EQ(log_softmax_func->get_output_partial_shape(0), (PartialShape{}));
+}
diff --git a/src/core/tests/type_prop/softmax.cpp b/src/core/tests/type_prop/softmax.cpp
index a91296ca610..eb5d1e741cb 100644
--- a/src/core/tests/type_prop/softmax.cpp
+++ b/src/core/tests/type_prop/softmax.cpp
@@ -61,3 +61,24 @@ TEST(type_prop, softmax_8_negative_axis) {
ASSERT_EQ(softmax->get_element_type(), element::f32);
ASSERT_EQ(softmax->get_shape(), (Shape{1, 10}));
}
+
+TEST(type_prop, softmax_v1_scalar) {
+ auto arg = make_shared<ov::op::v0::Parameter>(element::f32, Shape{});
+ auto softmax = make_shared<op::v1::Softmax>(arg, 0);
+ ASSERT_EQ(softmax->get_element_type(), element::f32);
+ ASSERT_EQ(softmax->get_output_partial_shape(0), (PartialShape{}));
+}
+
+TEST(type_prop, softmax_8_scalar) {
+ auto arg = make_shared<ov::op::v0::Parameter>(element::f32, Shape{});
+ auto softmax = make_shared<op::v8::Softmax>(arg, 0);
+ ASSERT_EQ(softmax->get_element_type(), element::f32);
+ ASSERT_EQ(softmax->get_output_partial_shape(0), (PartialShape{}));
+}
+
+TEST(type_prop, softmax_8_scalar_neg_axis) {
+ auto arg = make_shared<ov::op::v0::Parameter>(element::f32, Shape{});
+ auto softmax = make_shared<op::v8::Softmax>(arg, -1);
+ ASSERT_EQ(softmax->get_element_type(), element::f32);
+ ASSERT_EQ(softmax->get_output_partial_shape(0), (PartialShape{}));
+}
diff --git a/src/core/tests/validation_utils.cpp b/src/core/tests/validation_utils.cpp
index 123761d31a0..6e8c9190c36 100644
--- a/src/core/tests/validation_utils.cpp
+++ b/src/core/tests/validation_utils.cpp
@@ -235,7 +235,8 @@ INSTANTIATE_TEST_SUITE_P(negative_axis,
NormalizeAxisTestP,
Values(NormalizeAxisParam{-5, 0, Rank{5}},
NormalizeAxisParam{-3, 2, Rank{5}},
- NormalizeAxisParam{-1, 4, Rank{5}}),
+ NormalizeAxisParam{-1, 4, Rank{5}},
+ NormalizeAxisParam{-1, 0, Rank{0}}),
testing::PrintToStringParamName());
TEST_P(NormalizeAxisTestP, is_axis_valid) {
@@ -248,14 +249,17 @@ TEST_P(NormalizeAxisTestP, is_axis_valid) {
TEST_P(NormalizeAxisTestP, is_axis_valid_scalar_rank) {
const auto& axis = std::get<0>(GetParam());
- if (axis) {
+ if (axis == 0 || axis == -1) {
+ EXPECT_TRUE(util::is_axis_valid(axis, 0));
+ } else {
EXPECT_FALSE(util::is_axis_valid(axis, 0));
}
}
TEST_P(NormalizeAxisTestP, validate_axis) {
- const auto axes_node = Parameter(element::i64, PartialShape::dynamic(5));
const auto& axis = std::get<0>(GetParam());
+ const auto& rank = std::get<2>(GetParam());
+ const auto axes_node = Parameter(element::i64, PartialShape::dynamic(rank));
EXPECT_NO_THROW(util::validate_axis(axis, axes_node.get_output_partial_shape(0).rank(), axes_node));
}
diff --git a/tests/layer_tests/pytorch_tests/test_log_softmax.py b/tests/layer_tests/pytorch_tests/test_log_softmax.py
index 6361b003ca8..03e6a9b150d 100644
--- a/tests/layer_tests/pytorch_tests/test_log_softmax.py
+++ b/tests/layer_tests/pytorch_tests/test_log_softmax.py
@@ -44,3 +44,26 @@ class TestLogSoftmax(PytorchLayerTest):
self.input_dtype = input_dtype
self._test(aten_log_softmax(dim, convert_dtype), "aten::log_softmax",
ie_device, precision, ir_version)
+
+
+class aten_log_softmax_scalar(torch.nn.Module):
+ def __init__(self, dim) -> None:
+ super().__init__()
+ self.dim = dim
+
+ def forward(self, input_tensor):
+ return F.log_softmax(input_tensor, dim=self.dim)
+
+
+class TestLogSoftmaxScalar(PytorchLayerTest):
+ def _prepare_input(self):
+ return (self.random.randn(),)
+
+ @pytest.mark.parametrize("dim", [-1, 0])
+ @pytest.mark.nightly
+ @pytest.mark.precommit
+ @pytest.mark.precommit_torch_export
+ @pytest.mark.precommit_fx_backend
+ def test_log_softmax_scalar(self, dim, ie_device, precision, ir_version):
+ self._test(aten_log_softmax_scalar(dim), "aten::log_softmax",
+ ie_device, precision, ir_version)
diff --git a/tests/layer_tests/pytorch_tests/test_softmax.py b/tests/layer_tests/pytorch_tests/test_softmax.py
index 51264995369..e31154d2dd5 100644
--- a/tests/layer_tests/pytorch_tests/test_softmax.py
+++ b/tests/layer_tests/pytorch_tests/test_softmax.py
@@ -2,6 +2,8 @@
# SPDX-License-Identifier: Apache-2.0
import pytest
+import torch
+import torch.nn.functional as F
from pytorch_layer_test_class import PytorchLayerTest
@@ -65,3 +67,26 @@ class TestSoftmax(PytorchLayerTest):
input_kwargs["second_input_dtype"] = dtype
self._test(*self.create_model(dim, dtype, use_prim_dtype), ie_device,
precision, ir_version, kwargs_to_prepare_input=input_kwargs)
+
+
+class aten_softmax_scalar(torch.nn.Module):
+ def __init__(self, dim):
+ super().__init__()
+ self.dim = dim
+
+ def forward(self, x):
+ return F.softmax(x, self.dim)
+
+
+class TestSoftmaxScalar(PytorchLayerTest):
+ def _prepare_input(self):
+ return (self.random.randn(),)
+
+ @pytest.mark.parametrize("dim", [-1, 0])
+ @pytest.mark.nightly
+ @pytest.mark.precommit
+ @pytest.mark.precommit_torch_export
+ @pytest.mark.precommit_fx_backend
+ def test_softmax_scalar(self, dim, ie_device, precision, ir_version):
+ self._test(aten_softmax_scalar(dim), "aten::softmax",
+ ie_device, precision, ir_version)