diff --git a/src/frontends/pytorch/src/op/poisson.cpp b/src/frontends/pytorch/src/op/poisson.cpp new file mode 100644 index 00000000000000..8755aec03984e7 --- /dev/null +++ b/src/frontends/pytorch/src/op/poisson.cpp @@ -0,0 +1,62 @@ +// Copyright (C) 2018-2025 Intel Corporation +// SPDX-License-Identifier: Apache-2.0 +// + +#include "openvino/frontend/pytorch/node_context.hpp" +#include "openvino/op/constant.hpp" +#include "pt_framework_node.hpp" +#include "utils.hpp" + +namespace ov { +namespace frontend { +namespace pytorch { +namespace op { + +using namespace ov::op; + +OutputVector translate_poisson(const NodeContext& context) { + // aten::poisson(Tensor self, Generator? generator=None) -> Tensor + num_inputs_check(context, 1, 2); + + auto rates = context.get_input(0); + + // Check if generator (seed) is provided + if (!context.input_is_none(1)) { + PYTORCH_OP_CONVERSION_CHECK(false, + "aten::poisson conversion with generator is not supported"); + } + + // Use PtFrameworkNode as a passthrough + auto fw_node = std::make_shared( + context.get_decoder(), + OutputVector{rates}, + 1 + ); + + // Set output type same as input + fw_node->set_output_type(0, + rates.get_element_type(), + rates.get_partial_shape() + ); + + auto res = context.mark_node(fw_node); + return {res}; +} + +} // namespace op +} // namespace pytorch +} // namespace frontend +} // namespace ov +``` + +4. **Save it** + +--- + +## Step 4: Register the Operation + +Now modify `op_table.cpp`: + +1. Open: +``` + C:\Users\ACER\Desktop\Openvino\openvino\src\frontends\pytorch\src\op_table.cpp \ No newline at end of file diff --git a/src/frontends/pytorch/src/op_table.cpp b/src/frontends/pytorch/src/op_table.cpp index a4636e822c0971..04debb64676c95 100644 --- a/src/frontends/pytorch/src/op_table.cpp +++ b/src/frontends/pytorch/src/op_table.cpp @@ -203,6 +203,7 @@ OP_CONVERTER(translate_pairwise_distance); OP_CONVERTER(translate_pixel_shuffle); OP_CONVERTER(translate_pixel_unshuffle); OP_CONVERTER(translate_polar); +OP_CONVERTER(translate_poisson); OP_CONVERTER(translate_pow); OP_CONVERTER(translate_prod); OP_CONVERTER(translate_pythonop); @@ -655,6 +656,7 @@ const std::unordered_map get_supported_ops_ts() { {"aten::pixel_unshuffle", op::translate_pixel_unshuffle}, {"aten::prelu", op::translate_1to1_match_2_inputs}, {"aten::polar", op::translate_polar}, + {"aten::poisson", op::translate_poisson}, {"aten::pow", op::translate_pow}, {"aten::pow_", op::translate_pow}, {"aten::prod", op::translate_prod}, diff --git a/tests/layer_tests/pytorch_tests/test_poisson.py b/tests/layer_tests/pytorch_tests/test_poisson.py new file mode 100644 index 00000000000000..b6fe13f9506c34 --- /dev/null +++ b/tests/layer_tests/pytorch_tests/test_poisson.py @@ -0,0 +1,42 @@ +# Copyright (C) 2018-2025 Intel Corporation +# SPDX-License-Identifier: Apache-2.0 + +import numpy as np +import pytest +import torch + +from pytorch_layer_test_class import PytorchLayerTest + + +class TestPoisson(PytorchLayerTest): + def _prepare_input(self, rates, input_type): + return [rates.astype(input_type)] + + def create_model(self, seed): + class aten_poisson(torch.nn.Module): + def __init__(self, seed): + super().__init__() + self.gen = torch.Generator() + self.seed = seed + + def forward(self, rates): + self.gen.manual_seed(self.seed) + return torch.poisson(rates, generator=self.gen) + + ref_net = None + return aten_poisson(seed), ref_net, "aten::poisson" + + @pytest.mark.parametrize("rates", [ + np.array([1.0, 2.0, 3.0, 5.0]), + np.array([[1.0, 2.0], [3.0, 4.0]]), + np.array([0.5, 1.5, 2.5]), + ]) + @pytest.mark.parametrize("input_type", [np.float32, np.float64]) + @pytest.mark.parametrize("seed", [1, 50, 1234]) + @pytest.mark.nightly + @pytest.mark.precommit + @pytest.mark.precommit_fx_backend + def test_poisson(self, rates, input_type, seed, ie_device, precision, ir_version): + self._test(*self.create_model(seed), + ie_device, precision, ir_version, + kwargs_to_prepare_input={"rates": rates, "input_type": input_type}) \ No newline at end of file