Allow stable sort in TopK when sorting by indices (#16811)

* Allow stable sort in TopK when sorting by indices

* Clarification of stable sorting by index and unblocked test

* XFAIL the test again

* Clarification of sorting by indices

* Revert of changes in previous versions op TopK (spec)
This commit is contained in:
Tomasz Dołbniak authored and GitHub committed 2023-04-13 05:26:01 +02:00
1 parent 9c6d287a58
commit dcf6fb1e1a
5 files changed
+39 -25

No files matched your search

+4 -5
View File
@@ -323,11 +323,10 @@ void ov::op::v11::TopK::validate_and_infer_types() {
OV_OP_SCOPE(v11_TopK_validate_and_infer_types);
if (m_stable) {
NODE_VALIDATION_CHECK(
this,
m_sort == TopKSortType::SORT_VALUES,
"Stable sort can only be used when TopK's sorting mode is set to 'VALUE'. Current sorting mode = ",
AttributeAdapter<TopKSortType>(m_sort).get());
NODE_VALIDATION_CHECK(this,
m_sort == TopKSortType::SORT_VALUES || m_sort == TopKSortType::SORT_INDICES,
"Stable sort can only be used when TopK's sorting mode is set to 'VALUE' or 'INDEX'.",
AttributeAdapter<TopKSortType>(m_sort).get());
}
util::TopKBase::validate_and_infer_types();
+1 -15
View File
@@ -420,20 +420,6 @@ TEST(type_prop, top_k_partial_value) {
EXPECT_EQ(op->get_output_partial_shape(0), PartialShape({{0, 200}}));
}
TEST(type_prop, topk_v11_stable_sort_by_indices) {
const auto data = std::make_shared<Parameter>(element::f32, Shape{2, 3, 4});
const auto k = Constant::create(element::u32, Shape{}, {1});
OV_EXPECT_THROW(const auto op = std::make_shared<ov::op::v11::TopK>(data,
k,
1,
op::TopKMode::MAX,
op::TopKSortType::SORT_INDICES,
element::i32,
true),
NodeValidationFailure,
HasSubstr("Stable sort can only be used when TopK's sorting mode is set to 'VALUE'"));
}
TEST(type_prop, topk_v11_stable_sort_by_none) {
const auto data = std::make_shared<Parameter>(element::f32, Shape{2, 3, 4});
const auto k = Constant::create(element::u32, Shape{}, {1});
@@ -445,5 +431,5 @@ TEST(type_prop, topk_v11_stable_sort_by_none) {
element::i64,
true),
NodeValidationFailure,
HasSubstr("Stable sort can only be used when TopK's sorting mode is set to 'VALUE'"));
HasSubstr("Stable sort can only be used when TopK's sorting mode is set to 'VALUE' or 'INDEX'"));
}