-
Notifications
You must be signed in to change notification settings - Fork 3.2k
[spec][ref][cpu][gpu]: Added OneHot v16 #31901
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
Merged
pkowalc1
merged 48 commits into
openvinotoolkit:master
from
pkowalc1:fix_one_hot_negative_indicies_with_new_op_ver
Sep 16, 2025
Merged
Changes from all commits
Commits
Show all changes
48 commits
Select commit
Hold shift + click to select a range
597c1e3
[ref][one_hot]: Added support for negative indicies. Fixed tests.
pkowalc1 04e718e
[ref][one_hot]: Fixed code style.
pkowalc1 972560b
[onnx]: Disabled onehot test.
pkowalc1 7304114
[gpu][one_hot]: Added support for negative indicies, added unittests.
pkowalc1 2f937d5
[cpu]: [one_hot]: Added support for negative indicies and and added t…
pkowalc1 deb076b
[doc]:[one_hot]: Added info about supporting negative indicies.
pkowalc1 5e61894
Merge branch 'master' into fix_one_hot_negative_indicies
pkowalc1 0ea1888
[TEMP][CI]: Add printing input to failing tests.
pkowalc1 b76c367
[ref]: Added NegativeIndicesMode to OneHot. Fixed ref and onnx tests.
pkowalc1 33459d7
[onnx]: Fixed doc check.
pkowalc1 c0c8d45
[one_hot]: Fixed code style.
pkowalc1 2d6e42c
[cpu][onehot]: Added support for oh mode. Fixed tests.
pkowalc1 f8ce920
[gpu][one_hot]: Added support for indicies mode with tests.
pkowalc1 fd4c4d8
Fixed clang-format.
pkowalc1 77fffc3
Merge branch 'master' into fix_one_hot_negative_indicies
pkowalc1 889ed07
[doc][onehot]: Added description of negative indices mode.
pkowalc1 3ff9d3d
Merge branch 'fix_one_hot_negative_indicies' of https://github.com/pk…
pkowalc1 42580f2
[gpu][cpu][ref]: Added OneHot v16 WIP
pkowalc1 28ad97c
[core]: Enabled shape infer for v16 One Hot.
pkowalc1 c275abe
[cpu]: Added tests for v16 shape infer.
pkowalc1 6727743
[onnx]: Fixed frontend tests.
pkowalc1 b11a989
[core]: Added shape inference tests for one hot v16.
pkowalc1 cc8c572
[core]: Add constant folding tests for OneHot v16.
pkowalc1 dcf4e91
[core]: Added attributes tests for one hot v16.
pkowalc1 28bd066
[template]: added onehot v16 tests
pkowalc1 5b416dd
Merge branch 'master' into fix_one_hot_negative_indicies_with_new_op_ver
pkowalc1 967dfb2
Fixed clang/build issues.
pkowalc1 681f0e1
[one_hot]: Fixes.
pkowalc1 4f56458
[one_hot]: Fixes.
pkowalc1 b7cd22f
[one_hot]: Fixed compilation.
pkowalc1 6afde05
[one_hot]: Fixed code style.
pkowalc1 e72fd40
[one_hot]: Fixes.
pkowalc1 8d42dea
[one_hot]: Conformance test
pkowalc1 ab3168f
[one_hot]: Removed typo.
pkowalc1 84f6b64
[one_hot]: Fixed cput shape inference tests.
pkowalc1 f523520
[one_hot]: Fixed tests.
pkowalc1 29f42a4
[one_hot]: Added functional tests
pkowalc1 e2e0a0a
[OneHot]: added new spec.
pkowalc1 2c921aa
[OneHotv1]: Restored spec.
pkowalc1 ad1654e
[OneHot1]: Restored spec.
pkowalc1 d8c1432
[OneHot1]: restored.
pkowalc1 6bbe914
[onehot]: Added transformation from v16 to v1
pkowalc1 e26471a
[onehot]: Fxied code style
pkowalc1 e99ce09
Update src/common/transformations/src/transformations/op_conversions/…
pkowalc1 1570297
Update src/core/shape_inference/include/one_hot_shape_inference.hpp
pkowalc1 90c900d
Update src/common/transformations/src/transformations/op_conversions/…
pkowalc1 dd498d8
[onehot]: Removed transformation v16 to v1.
pkowalc1 29908e4
[one_hote]: Removed transformation v16 to v1.
pkowalc1 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
127 changes: 127 additions & 0 deletions
127
...ation/openvino-ir-format/operation-sets/operation-specs/sequence/one-hot-16.rst
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,127 @@ | ||
| OneHot | ||
| ====== | ||
|
|
||
|
|
||
| .. meta:: | ||
| :description: Learn about OneHot-16 - a sequence processing operation, which | ||
| can be performed on four required input tensors. | ||
|
|
||
| **Versioned name**: *OneHot-16* | ||
|
|
||
| **Category**: *Sequence processing* | ||
|
|
||
| **Short description**: *OneHot* sets the elements in the output tensor with specified indices to ``on_value`` and fills all other locations with ``off_value``. | ||
|
|
||
| **Detailed description** | ||
|
|
||
| Taking a tensor with rank ``N`` as the first input ``indices``, OneHot produces a tensor with rank ``N+1`` extending the original | ||
| tensor with a new dimension at the ``axis`` position. The output tensor is populated with two scalar values: ``on_value`` | ||
| that comes from the 3rd input and ``off_value`` that comes from the 4nd input. The population is made in the following way: | ||
|
|
||
| .. code-block:: cpp | ||
|
|
||
| output[:, ... ,:, i, :, ... ,:] = on_value if (indices[:, ..., :, :, ..., :] == i) else off_value | ||
|
|
||
| where ``i`` is at the ``axis`` position in the ``output`` shape and has values from the range ``[0, ..., depth-1]``. | ||
|
|
||
| When some elements from the ``indices`` are greater or equal to the ``depth``, it is a well-formed operation. The corresponding output rows are populated with ``off_value`` in this case. | ||
|
|
||
| The types of input scalars ``on_value`` and ``off_value`` should match and be equal to any supported type. The output tensor type is derived from the ``on_value`` or the ``off_value``, they all have the same type. | ||
|
|
||
| **Attributes**: | ||
|
|
||
| * *axis* | ||
|
|
||
| * **Description**: *axis* is a new axis position in the output shape to fill with one-hot values. | ||
| * **Range of values**: an integer. Negative value means counting dimension from the end. | ||
| * **Type**: ``int`` | ||
| * **Required**: *yes* | ||
|
|
||
| * *negative_indices_mode* | ||
|
|
||
| * **Description**: controls how negative indices in indices tensor are handled. | ||
| * **Range of values**: | ||
|
|
||
| * ``ignore-negative``: negative indices are ignored, and the corresponding output rows are filled with ``off_value``. | ||
| * ``normalize``: negative indices in the range ``[-depth, -1]`` are normalized by ``depth + index``; which effectively maps the range ``[-depth, depth-1]`` to ``[0, depth-1]``. | ||
|
|
||
| * **Type**: ``string`` | ||
| * **Default value**: ignore-negative | ||
| * **Required**: *no* | ||
|
|
||
| .. note:: | ||
| OneHot-16 with negative_indices_mode set to ignore-negative mode behaves exactly as OneHot-1. | ||
|
|
||
| **Inputs**: | ||
|
|
||
| * **1**: ``indices``: input tensor of type *T1* with indices. Can be 0D. **Required.** | ||
| * **2**: ``depth``: positive scalar (0D tensor) of type *T1* that specifies the number of classes and thus the size of the one-hot dimension. **Required.** | ||
| * **3**: ``on_value``: scalar (0D tensor) of type *T2* that fills the locations in output tensor specified in ``indices``. **Required.** | ||
| * **4**: ``off_value``: scalar (0D tensor) of type *T2* that fills the locations not represented in ``indices``. **Required.** | ||
|
|
||
| **Outputs**: | ||
|
|
||
| * **1**: An ``N+1`` rank tensor of type *T2*, where ``N`` is a rank of the input tensor ``indices``. A new axis of the size ``depth`` is inserted at the dimension ``axis``. | ||
|
|
||
| **Types** | ||
|
|
||
| * *T1*: ``int32`` or ``int64``. | ||
|
|
||
| * *T2*: any supported data type. | ||
|
|
||
| **Examples** | ||
|
|
||
| .. code-block:: xml | ||
| :force: | ||
|
|
||
| <layer ... type="OneHot" ...> | ||
| <data axis="-1" negative_indices_mode="normalize"/> | ||
| <input> | ||
| <port id="0"> <!-- indices value: [0, -5, -2, 2] --> | ||
| <dim>4</dim> | ||
| </port> | ||
| <port id="1"> <!-- depth value: 3 --> | ||
| </port> | ||
| <port id="2"> <!-- on_value 1 --> | ||
| </port> | ||
| <port id="3"> <!-- off_value 2 --> | ||
| </port> | ||
| </input> | ||
| <output> | ||
| <port id="0"> <!-- output value # [[1, 2, 2], [2, 2, 2], [2, 1, 2], [2, 2, 1]] --> | ||
| <dim>4</dim> | ||
| <dim>3</dim> | ||
| </port> | ||
| </output> | ||
| </layer> | ||
|
|
||
|
|
||
|
|
||
| .. code-block:: xml | ||
| :force: | ||
|
|
||
| <layer ... type="OneHot" ...> | ||
| <data axis="1"/> | ||
| <input> | ||
| <port id="0"> <!-- indices value: [[0, 3, 1], [1, 2, 4]] --> | ||
| <dim>2</dim> | ||
| <dim>3</dim> | ||
| </port> | ||
| <port id="1"> <!-- depth value: 3 --> | ||
| </port> | ||
| <port id="2"> <!-- on_value 1 --> | ||
| </port> | ||
| <port id="3"> <!-- off_value 0 --> | ||
| </port> | ||
| </input> | ||
| <output> | ||
| <port id="0"> <!-- output value: [[[1, 0, 0], [0, 0, 1], [0, 0, 0]], --> | ||
| <dim>2</dim> <!-- [[0, 0, 0], [1, 0, 0], [0, 1, 0]]] --> | ||
| <dim>3</dim> | ||
| <dim>3</dim> | ||
| </port> | ||
| </output> | ||
| </layer> | ||
|
|
||
|
|
||
|
|
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,57 @@ | ||
| // Copyright (C) 2018-2025 Intel Corporation | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
| // | ||
|
|
||
| #pragma once | ||
|
|
||
| #include "openvino/op/op.hpp" | ||
| #include "openvino/op/util/attr_types.hpp" | ||
|
|
||
| namespace ov { | ||
| namespace op { | ||
| namespace util { | ||
| class OPENVINO_API OneHotBase : public Op { | ||
| public: | ||
| OPENVINO_OP("OneHot", "util"); | ||
|
|
||
| /// \brief Constructs a one-hot operation. | ||
| OneHotBase() = default; | ||
|
|
||
| /// \brief Constructs a one-hot operation. | ||
| /// | ||
| /// \param indices Input tensor containing indices. | ||
| /// \param depth Specifies number of classes and the size of one-hot dimension. | ||
| /// \param on_value Specifies value that the locations in output tensor represented | ||
| /// by indices in input take. | ||
| /// \param off_value Specifies value that the locations in output tensor not | ||
| /// represented | ||
| /// by indices in input take. | ||
| /// \param axis Axis along which one-hot representation in added. | ||
| OneHotBase(const Output<Node>& indices, | ||
| const Output<Node>& depth, | ||
| const Output<Node>& on_value, | ||
| const Output<Node>& off_value, | ||
| int64_t axis); | ||
|
|
||
| bool visit_attributes(AttributeVisitor& visitor) override; | ||
| void validate_and_infer_types() override; | ||
| std::shared_ptr<Node> clone_with_new_inputs(const OutputVector& new_args) const override; | ||
|
|
||
| /// \return The index of the one-hot axis. | ||
| const int64_t& get_axis() const { | ||
| return m_axis; | ||
| } | ||
|
|
||
| /// @brief Sets the index of the one-hot axis. | ||
| /// @param axis The index of the one-hot axis. | ||
| void set_axis(int64_t axis); | ||
|
|
||
| protected: | ||
| int64_t m_axis; | ||
|
|
||
| private: | ||
| friend void inline resolve_axis(OneHotBase* op); | ||
|
Comment on lines
+52
to
+53
Contributor
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 general friends has been removed in ops (looks like missed for this op). It can be removed also as we got |
||
| }; | ||
| } // namespace util | ||
| } // namespace op | ||
| } // namespace ov | ||
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.
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.
AS new file added: