OpenVINO™ is an open source toolkit for optimizing and deploying AI inference
C++ aicomputer-visiondeep-learningdeploy-aidiffusion-modelsgenerative-aigood-first-issueinferencellm-inferencenatural-language-processingnlpopenvinooptimize-aiperformance-boostrecommendation-systemspeech-recognitionstable-diffusiontransformersyolo
[JAX FE] Support lt, le, and neg operations (#26847)
Akshat agarwalb6805b41100d
diff --git a/src/frontends/jax/src/op/binary_op.cpp b/src/frontends/jax/src/op/binary_op.cppindex 11e26166cfc..28c296e61e8 100644--- a/src/frontends/jax/src/op/binary_op.cpp+++ b/src/frontends/jax/src/op/binary_op.cpp@@ -6,6 +6,8 @@#include "openvino/op/equal.hpp"#include "openvino/op/greater.hpp"#include "openvino/op/greater_eq.hpp"+#include "openvino/op/less.hpp"+#include "openvino/op/less_eq.hpp"#include "openvino/op/not_equal.hpp"#include "utils.hpp"@@ -30,6 +32,8 @@ OutputVector translate_binary_op(const NodeContext& context) {template OutputVector translate_binary_op<v1::Equal>(const NodeContext& context);template OutputVector translate_binary_op<v1::GreaterEqual>(const NodeContext& context);template OutputVector translate_binary_op<v1::Greater>(const NodeContext& context);+template OutputVector translate_binary_op<v1::Less>(const NodeContext& context);+template OutputVector translate_binary_op<v1::LessEqual>(const NodeContext& context);template OutputVector translate_binary_op<v1::NotEqual>(const NodeContext& context);} // namespace opdiff --git a/src/frontends/jax/src/op_table.cpp b/src/frontends/jax/src/op_table.cppindex dcd54203f5b..5e92e3de6e2 100644--- a/src/frontends/jax/src/op_table.cpp+++ b/src/frontends/jax/src/op_table.cpp@@ -11,8 +11,11 @@#include "openvino/op/exp.hpp"#include "openvino/op/greater.hpp"#include "openvino/op/greater_eq.hpp"+#include "openvino/op/less.hpp"+#include "openvino/op/less_eq.hpp"#include "openvino/op/maximum.hpp"#include "openvino/op/multiply.hpp"+#include "openvino/op/negative.hpp"#include "openvino/op/not_equal.hpp"#include "openvino/op/reduce_max.hpp"#include "openvino/op/reduce_sum.hpp"@@ -71,8 +74,11 @@ const std::map<std::string, CreatorFunction> get_supported_ops_jaxpr() {{"ge", op::translate_binary_op<v1::GreaterEqual>},{"gt", op::translate_binary_op<v1::Greater>},{"integer_pow", op::translate_integer_pow},+ {"lt", op::translate_binary_op<v1::Less>},+ {"le", op::translate_binary_op<v1::LessEqual>},{"max", op::translate_1to1_match_2_inputs<v1::Maximum>},{"mul", op::translate_1to1_match_2_inputs<v1::Multiply>},+ {"neg", op::translate_1to1_match_1_input<v0::Negative>},{"ne", op::translate_binary_op<v1::NotEqual>},{"reduce_max", op::translate_reduce_op<v1::ReduceMax>},{"reduce_sum", op::translate_reduce_op<v1::ReduceSum>},diff --git a/tests/layer_tests/jax_tests/test_binary_comparison.py b/tests/layer_tests/jax_tests/test_binary_comparison.pyindex 2e2f7d917d6..2f735f3eecf 100644--- a/tests/layer_tests/jax_tests/test_binary_comparison.py+++ b/tests/layer_tests/jax_tests/test_binary_comparison.py@@ -30,6 +30,8 @@ class TestBinaryComparison(JaxLayerTest):'eq': lax.eq,'ge': lax.ge,'gt': lax.gt,+ 'lt': lax.lt,+ 'le': lax.le,'ne': lax.ne}@@ -44,7 +46,7 @@ class TestBinaryComparison(JaxLayerTest):@pytest.mark.parametrize('input_shapes', [[[5], [1]], [[1], [5]], [[2, 2, 4], [1, 1, 4]],[[5, 10], [5, 10]], [[2, 4, 6], [1, 4, 6]],[[5, 8, 10, 128], [5, 1, 10, 128]]])- @pytest.mark.parametrize('binary_op', ['eq', 'ge', 'gt', 'ne'])+ @pytest.mark.parametrize('binary_op', ['eq', 'ge', 'gt', 'lt', 'le','ne'])@pytest.mark.parametrize('input_type', [np.int8, np.uint8, np.int16, np.uint16,np.int32, np.uint32, np.int64, np.uint64,np.float16, np.float32, np.float64])diff --git a/tests/layer_tests/jax_tests/test_negative.py b/tests/layer_tests/jax_tests/test_negative.pynew file mode 100644index 00000000000..cd00553a09e--- /dev/null+++ b/tests/layer_tests/jax_tests/test_negative.py@@ -0,0 +1,51 @@+# Copyright (C) 2018-2024 Intel Corporation+# SPDX-License-Identifier: Apache-2.0++import numpy as np+import pytest+from jax import lax+from jax import numpy as jnp+++from jax_layer_test_class import JaxLayerTest++rng = np.random.default_rng(56342)+class TestNeg(JaxLayerTest):+ def _prepare_input(self):+ if np.issubdtype(self.input_type, np.floating):+ inp = rng.uniform(-5.0, 5.0, self.input_shape).astype(self.input_type)+ elif np.issubdtype(self.input_type, np.signedinteger):+ inp = rng.integers(-8, 8, self.input_shape).astype(self.input_type)+ else:+ inp = rng.integers(0, 8, self.input_shape).astype(self.input_type)+ inp = jnp.array(inp)+ return [inp]++ def create_model(self, input_shape, input_type):+ self.input_shape = input_shape+ self.input_type = input_type++ def jax_neg(inp):+ out = lax.neg(inp)+ return out++ return jax_neg, None, 'neg'++ @pytest.mark.parametrize("input_shape", [+ [10],+ [2, 3],+ [3, 4, 5],+ [7, 16, 11, 20],+ [6, 5, 4, 3, 2],+ [1, 1, 9, 1]+ ])+ @pytest.mark.parametrize('input_type', [np.int8, np.int16, np.int32,+ np.int64,np.float16,+ np.float32, np.float64])+ @pytest.mark.nightly+ @pytest.mark.precommit+ @pytest.mark.precommit_jax_fe+ def test_neg(self, ie_device, precision, ir_version, input_shape, input_type):+ self._test(*self.create_model(input_shape=input_shape, input_type=input_type),+ ie_device, precision,+ ir_version)\ No newline at end of file