-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Added Relevant support for aten::quantile and it's tests. #28599
Open
geeky33
wants to merge
21
commits into
openvinotoolkit:master
Choose a base branch
from
geeky33:quantile
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.
+118
−0
Open
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
f0f82e4
Implemented CPU plugin just-in-time emitter for NotEqual operation
geeky33 353e043
Merge branch 'openvinotoolkit:master' into master
geeky33 613904b
Merge branch 'openvinotoolkit:master' into master
geeky33 6797eec
Updated jit_eltwise_emitters.cpp
geeky33 25f3506
Merge branch 'openvinotoolkit:master' into master
geeky33 6aaea6d
Updated jit_eltwise_emitters.cpp
geeky33 0507f00
Updated jit_eltwise_emitters.hpp
geeky33 78e5b4d
Updated jit_eltwise.cpp
geeky33 d06a086
Merge branch 'openvinotoolkit:master' into master
geeky33 a55d4e8
Updated jit_eltwise_emitters.cpp
geeky33 5ee07f0
switching to new branch for new PR
geeky33 7c1f575
Added support for aten::quantile and its tests
geeky33 2ff9819
Added support for aten::quantile and its tests
geeky33 ae08bd3
Reverted some relevant changes
geeky33 4f15abe
Merge branch 'openvinotoolkit:master' into quantile
geeky33 156d2f0
Updated quantile.cpp
geeky33 4b8cc1c
Merge branch 'openvinotoolkit:master' into quantile
geeky33 96f8166
Merge branch 'openvinotoolkit:master' into quantile
geeky33 0381b66
Merge branch 'openvinotoolkit:master' into quantile
geeky33 dcd43e3
Merge branch 'openvinotoolkit:master' into quantile
geeky33 0c0075e
Merge branch 'openvinotoolkit:master' into quantile
geeky33 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 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,80 @@ | ||
// Copyright (C) 2018-2025 Intel Corporation | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
|
||
#include "openvino/frontend/pytorch/node_context.hpp" | ||
#include "openvino/op/convert.hpp" | ||
#include "openvino/op/gather.hpp" | ||
#include "openvino/op/range.hpp" | ||
#include "openvino/op/reshape.hpp" | ||
#include "openvino/opsets/opset10.hpp" | ||
#include "openvino/op/multiply.hpp" | ||
#include "openvino/op/floor.hpp" | ||
#include "openvino/op/add.hpp" | ||
#include "openvino/op/subtract.hpp" | ||
#include "openvino/op/maximum.hpp" | ||
#include "openvino/op/minimum.hpp" | ||
#include "utils.hpp" | ||
|
||
using namespace ov::op; | ||
|
||
OutputVector translate_quantile(const NodeContext& context) { | ||
num_inputs_check(context, 2, 5); | ||
|
||
auto input = context.get_input(0); | ||
auto q = context.get_input(1); // Quantile(s), can be float or tensor | ||
|
||
auto dim = context.input_is_none(2) ? -1 : context.get_input<int64_t>(2); | ||
auto keepdim = context.input_is_none(3) ? false : context.get_input<bool>(3); | ||
auto interpolation = context.input_is_none(4) ? "linear" : context.get_input<std::string>(4); | ||
|
||
|
||
if (dim == -1) { | ||
input = context.mark_node(std::make_shared<v0::Reshape>( | ||
input, context.mark_node(std::make_shared<v0::Range>(0, input.get_shape().size(), 1)), true)); | ||
dim = 0; | ||
} | ||
|
||
auto sorted = context.mark_node(std::make_shared<v0::Sort>(input, dim, true)); // Ascending order | ||
|
||
auto dim_size = input.get_shape()[dim]; | ||
|
||
auto indices = context.mark_node(std::make_shared<v0::Multiply>(q, dim_size - 1)); | ||
auto lower_indices = context.mark_node(std::make_shared<v0::Floor>(indices)); | ||
auto upper_indices = context.mark_node(std::make_shared<v1::Add>(lower_indices, 1)); | ||
auto weights = context.mark_node(std::make_shared<v1::Subtract>(indices, lower_indices)); | ||
auto lower_values = context.mark_node(std::make_shared<v1::Gather>(sorted, lower_indices, dim)); | ||
auto upper_values = context.mark_node(std::make_shared<v1::Gather>(sorted, upper_indices, dim)); | ||
|
||
Output<Node> result; | ||
if (interpolation == "linear") { | ||
result = context.mark_node(std::make_shared<v1::Add>( | ||
lower_values, context.mark_node(std::make_shared<v1::Multiply>(weights, upper_values)))); | ||
} else if (interpolation == "lower") { | ||
result = lower_values; | ||
} else if (interpolation == "higher") { | ||
result = upper_values; | ||
} else if (interpolation == "nearest") { | ||
auto nearest_indices = context.mark_node(std::make_shared<v0::Round>(indices)); | ||
result = context.mark_node(std::make_shared<v1::Gather>(sorted, nearest_indices, dim)); | ||
} else if (interpolation == "midpoint") { | ||
result = context.mark_node(std::make_shared<v1::Add>( | ||
lower_values, context.mark_node(std::make_shared<v1::Multiply>( | ||
context.mark_node(std::make_shared<v0::Constant>(element::f32, Shape{}, 0.5)), | ||
context.mark_node(std::make_shared<v1::Subtract>(upper_values, lower_values)))))); | ||
} else { | ||
throw std::runtime_error("Unsupported interpolation method: " + interpolation); | ||
} | ||
if (!keepdim) { | ||
auto reshape_dims = input.get_shape(); | ||
reshape_dims.erase(reshape_dims.begin() + dim); | ||
result = context.mark_node(std::make_shared<v0::Reshape>(result, reshape_dims, true)); | ||
} | ||
|
||
return {result}; | ||
} | ||
|
||
} // namespace op | ||
} // namespace pytorch | ||
} // namespace frontend | ||
} // namespace ov |
This file contains 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 | ||||
---|---|---|---|---|---|---|
|
@@ -191,6 +191,7 @@ OP_CONVERTER(translate_quantized_add); | |||||
OP_CONVERTER(translate_quantized_add_relu); | ||||||
OP_CONVERTER(translate_quantized_hardswish); | ||||||
OP_CONVERTER(translate_quantized_mul); | ||||||
OP_CONVERTER(translate_quantile); | ||||||
OP_CONVERTER(translate_range_length); | ||||||
OP_CONVERTER(translate_rand); | ||||||
OP_CONVERTER(translate_randn); | ||||||
|
@@ -747,6 +748,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_ts() { | |||||
{"quantized::hardswish", op::translate_quantized_hardswish}, | ||||||
{"quantized::linear", op::translate_quantized_linear}, | ||||||
{"quantized::mul", op::translate_quantized_mul}, | ||||||
{"quantized::relu", op::translate_quantile}, | ||||||
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.
Suggested change
|
||||||
{"torchvision::deform_conv2d", op::translate_deform_conv}, | ||||||
{"torchvision::nms", op::translate_nms}, | ||||||
{"torchvision::roi_align", op::translate_roi_align}, | ||||||
|
This file contains 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,36 @@ | ||
# Copyright (C) 2018-2025 Intel Corporation | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
import pytest | ||
import numpy as np | ||
import torch | ||
from pytorch_layer_test_class import PytorchLayerTest | ||
|
||
|
||
class TestQuantile(PytorchLayerTest): | ||
def _prepare_input(self): | ||
input_tensor = np.random.randn(1, 3, 224, 224).astype(np.float32) | ||
quantile = np.array(0.5, dtype=np.float32) | ||
return (input_tensor, quantile) | ||
|
||
def create_model(self, dim=None, keepdim=False): | ||
class aten_quantile(torch.nn.Module): | ||
def __init__(self, dim, keepdim): | ||
super(aten_quantile, self).__init__() | ||
self.dim = dim | ||
self.keepdim = keepdim | ||
|
||
def forward(self, x, q): | ||
return torch.quantile(x, q, dim=self.dim, keepdim=self.keepdim) | ||
|
||
ref_net = None | ||
|
||
return aten_quantile(dim, keepdim), ref_net, "aten::quantile" | ||
|
||
@pytest.mark.parametrize("dim", [None, 0, 1, 2, 3, -1, -2, -3]) | ||
@pytest.mark.parametrize("keepdim", [True, False]) | ||
@pytest.mark.nightly | ||
@pytest.mark.precommit | ||
def test_quantile(self, dim, keepdim, ie_device, precision, ir_version): | ||
self._test(*self.create_model(dim, keepdim), ie_device, precision, ir_version) | ||
|
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.
You forgot to open namespaces