Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/bindings/python/thirdparty/pybind11
Submodule pybind11 updated 139 files
24 changes: 24 additions & 0 deletions src/frontends/pytorch/src/op/percent_format.cpp
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)};
};
Copy link

Copilot AI Feb 25, 2026

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.

Copilot uses AI. Check for mistakes.

}
}
}
}
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inconsistent spacing in closing braces. Lines 21, 23, and 24 have trailing spaces while line 22 does not. Remove trailing spaces for consistency.

Suggested change
}
}
}
}
}
}
}
}

Copilot uses AI. Check for mistakes.
2 changes: 2 additions & 0 deletions src/frontends/pytorch/src/op_table.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ OP_CONVERTER(translate_pad);
OP_CONVERTER(translate_pad_packed_sequence);
OP_CONVERTER(translate_permute);
OP_CONVERTER(translate_pairwise_distance);
OP_CONVERTER(translate_percent_format);
OP_CONVERTER(translate_pixel_shuffle);
OP_CONVERTER(translate_pixel_unshuffle);
OP_CONVERTER(translate_polar);
Expand Down Expand Up @@ -659,6 +660,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_ts() {
{"aten::outer", op::translate_outer},
{"aten::pad", op::translate_pad},
{"aten::pairwise_distance", op::translate_pairwise_distance},
{"aten::percentFormat", op::translate_percent_format},
{"aten::permute", op::translate_permute},
{"aten::pixel_shuffle", op::translate_pixel_shuffle},
{"aten::pixel_unshuffle", op::translate_pixel_unshuffle},
Expand Down
39 changes: 39 additions & 0 deletions tests/layer_tests/pytorch_tests/test_percent_format.py
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%%"
])
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The format_str parameter is defined but never used in the test. The create_model method accepts format_str but hardcodes the format string on line 20. Either remove the parameter or update the model to use it.

Copilot uses AI. Check for mistakes.
@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
Copy link

Copilot AI Feb 25, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The custom_eps value of 1e18 is extremely large and deserves a comment explaining why such a large epsilon is necessary for skipping result comparison.

Suggested change
kwargs["custom_eps"] = 1e18
kwargs["custom_eps"] = 1e18 # Use an extremely large epsilon to effectively disable numeric result comparison.

Copilot uses AI. Check for mistakes.
return super()._test(*args, **kwargs)
Loading