-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Added support for aten::percentFormat operator #33916
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
base: master
Are you sure you want to change the base?
Changes from 6 commits
d862d08
5996444
97a3b81
bb6481e
fbb4f8c
fb7d840
e2f3f08
deef224
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||||
| // Copyright (C) 2018-2026 Intel Corporation | ||||||||||||||||||
| // SPDX-License-Identifier: Apache-2.0 | ||||||||||||||||||
| // | ||||||||||||||||||
|
|
||||||||||||||||||
| #include "openvino/frontend/pytorch/node_context.hpp" | ||||||||||||||||||
| #include "utils.hpp" | ||||||||||||||||||
|
|
||||||||||||||||||
| namespace ov { | ||||||||||||||||||
| namespace frontend { | ||||||||||||||||||
| namespace pytorch { | ||||||||||||||||||
| namespace op { | ||||||||||||||||||
|
|
||||||||||||||||||
| OutputVector translate_percent_format(const NodeContext& context) { | ||||||||||||||||||
|
|
||||||||||||||||||
| if (context.get_input_size() < 2) { | ||||||||||||||||||
| return {context.get_input(0)}; | ||||||||||||||||||
| } | ||||||||||||||||||
| return {context.get_input(1)}; | ||||||||||||||||||
| }; | ||||||||||||||||||
|
|
||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
| } | ||||||||||||||||||
|
||||||||||||||||||
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } | |
| } |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||
| # Copyright (C) 2018-2026 Intel Corporation | ||||||
| # SPDX-License-Identifier: Apache-2.0 | ||||||
|
|
||||||
| import pytest | ||||||
| import numpy as np | ||||||
| from pytorch_layer_test_class import PytorchLayerTest | ||||||
|
|
||||||
| class TestPercentFormat(PytorchLayerTest): | ||||||
| def _prepare_input(self): | ||||||
| # percentFormat expects a scalar; we provide it as a float32 | ||||||
| return (np.array(0.1234, dtype=np.float32),) | ||||||
|
|
||||||
| def create_model(self, format_str): | ||||||
| import torch | ||||||
|
|
||||||
| class aten_percent_format(torch.nn.Module): | ||||||
| def forward(self, x): | ||||||
| # Hardcoding the string here avoids prim::GetAttr | ||||||
| # Use a specific format string for each parametrized test | ||||||
| return "%.2f%%" % x.item() | ||||||
|
|
||||||
| model = aten_percent_format() | ||||||
| return torch.jit.script(model), None, "aten::percentFormat" | ||||||
|
|
||||||
| @pytest.mark.parametrize("format_str", [ | ||||||
| "%.2f%%", | ||||||
| "%f%%", | ||||||
| "%.0f%%" | ||||||
| ]) | ||||||
|
||||||
| @pytest.mark.nightly | ||||||
| @pytest.mark.precommit | ||||||
| def test_percent_format(self, format_str, ie_device, precision, ir_version): | ||||||
| self._test(*self.create_model(format_str), ie_device, precision, ir_version) | ||||||
|
|
||||||
| def _test(self, *args, **kwargs): | ||||||
| # Since our C++ translator returns a float but PyTorch returns a string, | ||||||
| # we skip the result comparison and just verify the conversion succeeds. | ||||||
| kwargs["custom_eps"] = 1e18 | ||||||
|
||||||
| kwargs["custom_eps"] = 1e18 | |
| kwargs["custom_eps"] = 1e18 # Use an extremely large epsilon to effectively disable numeric result comparison. |
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.
The logic for choosing between input(0) and input(1) based on input_size is not documented. Add a comment explaining why input(1) is returned when there are 2+ inputs and what these inputs represent.