Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
62 changes: 62 additions & 0 deletions src/frontends/pytorch/src/op/poisson.cpp
Original file line number Diff line number Diff line change
@@ -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<PtFrameworkNode>(
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
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 @@ -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);
Expand Down Expand Up @@ -655,6 +656,7 @@ const std::unordered_map<std::string, CreatorFunction> get_supported_ops_ts() {
{"aten::pixel_unshuffle", op::translate_pixel_unshuffle},
{"aten::prelu", op::translate_1to1_match_2_inputs<opset10::PRelu>},
{"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},
Expand Down
42 changes: 42 additions & 0 deletions tests/layer_tests/pytorch_tests/test_poisson.py
Original file line number Diff line number Diff line change
@@ -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})