openvino icon indicating copy to clipboard operation
openvino copied to clipboard

[Good First Issue][Keras 3 OpenVINO Backend]: Support numpy.prod operation

Open rkazants opened this issue 8 months ago • 4 comments

Context

🚀A great opportunity to contribute to two popular AI projects with just one PR:: Keras 3 and OpenVINO.🚀

Keras 3 enables seamless switching between supported backends—PyTorch, TensorFlow, and JAX—for both training and inference of traditional models and LLMs/GenAI pipelines. Since Keras 3.8.0, we've introduced a preview version of the OpenVINO backend (for inference only), allowing developers to leverage OpenVINO for model predictions directly within Keras 3 workflows. Activating the OpenVINO backend requires just one line of code to run inference on Keras 3-trained models. Here’s an example for a BERT model from Keras Hub:

import os
os.environ["KERAS_BACKEND"] = "openvino"
import numpy as np
import keras
import keras_hub

features = {
    "token_ids": np.ones(shape=(2, 12), dtype="int32"),
    "segment_ids": np.array([[0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0]] * 2),
    "padding_mask": np.array([[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0]] * 2),
}

classifier = keras_hub.models.BertTextClassifier.from_preset("bert_base_en_uncased", num_classes=4, preprocessor=None)
output = classifier.predict(features)

Currently, the OpenVINO backend lacks support for some operations. Our goal is to resolve this gap and to optimize it for inference on Intel devices—including CPUs, integrated GPUs, discrete GPUs, and NPUs—by supporting as many models as possible while delivering optimal performance. We aim to make the OpenVINO backend the No. 1 choice for model inference within the Keras 3 workflow.

What needs to be done?

Steps to Contribute

  1. Set up your developer environment:
  • fork and clone keras repo
  • install requirements for OpenVINO backend development pip install -r requirements-openvino.txt. The requirements file can be found in the root directory of cloned repository
  1. Provide decomposition in Python for numpy.prod using OpenVINO opset

  2. Include tests by removing line corresponding to the implemented operation in excluded_concrete_tests.txt file.

  3. Make sure that tests are passing

  • create pytest.ini file and place it in the root directory of the clone repository. This file should contain the following content:
[pytest]
env =
    KERAS_BACKEND=openvino
  • run tests pytest-c ./pytest.ini ./keras/src/ops/numpy_test.py
  1. Commit your changes and create PR in keras repository. Mention @rkazants in PR description for review.

Below is an exemplar PR of how support for numpy.amax has been implemented.

Example Pull Requests

  • https://github.com/keras-team/keras/pull/20883

Resources

Contact points

@rkazants

AI notice - Important!

We encourage contributors to use AI tools responsibly when creating Pull Requests. While AI can be a valuable aid, it is essential to ensure that your contributions meet the task requirements, build successfully, include relevant tests, and pass all linters. Submissions that do not meet these standards may be closed without warning to maintain the quality and integrity of the project. Please take the time to understand the changes you are proposing and their impact.

Ticket

No response

rkazants avatar Apr 19 '25 11:04 rkazants

Hi @rkazants, I'd like to work on this issue. While setting up the environment, I noticed that the specified JAX version (0.5.0) isn't available on PyPI, which caused an installation error. Since JAX isn't required for working on the OpenVINO backend, I’ve commented out that dependency for now. Please let me know if that’s okay.

Xim777 avatar Apr 19 '25 16:04 Xim777

.take

sanleo-wq avatar May 13 '25 08:05 sanleo-wq

Hi @rkazants ,

I'm excited about the opportunity to contribute to the OpenVINO backend in Keras 3. I'd like to work on implementing support for numpy.prod using the OpenVINO opset, following the pattern used in the recent numpy.amax implementation.

I've set up my development environment and will make sure to:

  • Add the required decomposition logic
  • Remove the corresponding entry in excluded_concrete_tests.txt
  • Ensure all tests pass using KERAS_BACKEND=openvino

Let me know if there's anything specific you'd like me to keep in mind before I begin. Looking forward to contributing!

Best,
Dimpu Nithish Karanam

Nithishkaranam2002 avatar May 23 '25 05:05 Nithishkaranam2002

.take

Imokutmfon avatar Jun 17 '25 05:06 Imokutmfon

pr okay for review and merging @rkazants
https://github.com/keras-team/keras/pull/21405

Imokutmfon avatar Jun 20 '25 13:06 Imokutmfon

.take

Hmm-1224 avatar Aug 23 '25 15:08 Hmm-1224