Skip to content

Resolve: [Good First Issue][Keras 3 OpenVINO Backend]: Support numpy.linspace operation #29485 #21140

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 16 commits into
base: master
Choose a base branch
from

Conversation

VLTisME
Copy link

@VLTisME VLTisME commented Apr 6, 2025

Reduced failed tests to 2 failed and 12 skipped.
two left unsolved failed tests:
1/
start = 0, stop = 10, num = <tf.Tensor: shape=(), dtype=int32, numpy=5>
endpoint = True, retstep = False, dtype = None, axis = 0

@keras_export(["keras.ops.linspace", "keras.ops.numpy.linspace"])
def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0, *, device=None):
    # Validate num
    if not isinstance(num, int):
      raise TypeError("num must be an integer")

E TypeError: num must be an integer

2/

  arrays = [np.empty(x, dtype=[]) for x in args]

E TypeError: 'NoneType' object cannot be interpreted as an integer

Copy link

google-cla bot commented Apr 6, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@VLTisME
Copy link
Author

VLTisME commented Apr 6, 2025

@rkazants may you review this?

@VLTisME
Copy link
Author

VLTisME commented Apr 6, 2025

I have collected some errors, gonna fix it:
1/

      start_np, stop_np = np.broadcast_arrays(start.numpy(), stop.numpy())

E AttributeError: 'OpenVINOKerasTensor' object has no attribute 'numpy'
2/

      start_np, stop_np = np.broadcast_arrays(start.numpy(), stop.numpy())

E AttributeError: 'numpy.ndarray' object has no attribute 'numpy'. Did you mean: 'dump'?
3/
if backend.shape(start) == () and backend.shape(stop) == ():
result = start + indices * step
else:

      start_np, stop_np = np.broadcast_arrays(start.numpy(), stop.numpy())

E AttributeError: 'jaxlib.xla_extension.ArrayImpl' object has no attribute 'numpy'
4/
def linspace(start, stop, num=50, endpoint=True, retstep=False, dtype=None, axis=0, *, device=None):
if not isinstance(num, int):

      raise TypeError("num must be an integer")

E TypeError: num must be an integer
5/

arrays = [np.empty(x, dtype=[]) for x in args]
E TypeError: 'NoneType' object cannot be interpreted as an integer

@gbaned gbaned requested a review from mattdangerw April 8, 2025 10:20
@gbaned gbaned added this to PR Queue Apr 8, 2025
@github-project-automation github-project-automation bot moved this to Assigned Reviewer in PR Queue Apr 8, 2025
@@ -3468,51 +3468,100 @@ def compute_output_spec(self, start, stop):

Copy link
Contributor

Choose a reason for hiding this comment

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

pytest.ini Outdated
@@ -0,0 +1,3 @@
[pytest]
Copy link
Contributor

Choose a reason for hiding this comment

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

please remove this file. It is needed only for developer purpose

@codecov-commenter
Copy link

codecov-commenter commented Apr 15, 2025

Codecov Report

Attention: Patch coverage is 0% with 74 lines in your changes missing coverage. Please review.

Project coverage is 79.83%. Comparing base (99a6bdc) to head (c4e8245).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
keras/src/backend/openvino/numpy.py 0.00% 74 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #21140      +/-   ##
==========================================
- Coverage   82.59%   79.83%   -2.76%     
==========================================
  Files         564      564              
  Lines       54367    54440      +73     
  Branches     8452     8466      +14     
==========================================
- Hits        44902    43460    -1442     
- Misses       7391     8966    +1575     
+ Partials     2074     2014      -60     
Flag Coverage Δ
keras 79.64% <0.00%> (-2.76%) ⬇️
keras-jax 63.69% <0.00%> (-0.09%) ⬇️
keras-numpy 58.80% <0.00%> (-0.08%) ⬇️
keras-openvino ?
keras-tensorflow 64.09% <0.00%> (-0.09%) ⬇️
keras-torch 63.77% <0.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

\q
ranch 'linspace_func' of https://github.com/VLTisME/keras_forked into linspace_func
@rkazants
Copy link
Contributor

@VLTisME, please fix test failures, see CI logs:

FAILED keras/src/ops/numpy_test.py::NumpyTwoInputOpsCorrectnessTest::test_linspace - TypeError: unsupported operand type(s) for -: 'openvino._pyopenvino.Output' and 'openvino._pyopenvino.Output'
FAILED keras/src/ops/numpy_test.py::NumpyDtypeTest::test_linspace_[0, 10]_0_bfloat16 - TypeError: unsupported operand type(s) for -: 'openvino._pyopenvino.Output' and 'openvino._pyopenvino.Output'
FAILED keras/src/ops/numpy_test.py::NumpyDtypeTest::test_linspace_[0, 10]_0_float16 - TypeError: unsupported operand type(s) for -: 'openvino._pyopenvino.Output' and 'openvino._pyopenvino.Output'
FAILED keras/src/ops/numpy_test.py::NumpyDtypeTest::test_linspace_[0, 10]_0_float32 - TypeError: unsupported operand type(s) for -: 'openvino._pyopenvino.Output' and 'openvino._pyopenvino.Output'
FAILED keras/src/ops/numpy_test.py::NumpyDtypeTest::test_linspace_[0, 10]_0_float64 - TypeError: unsupported operand type(s) for -: 'openvino._pyopenvino.Output' and 'openvino._pyopenvino.Output'
FAILED keras/src/ops/numpy_test.py::NumpyDtypeTest::test_linspace_[0, 10]_0_none - TypeError: unsupported operand type(s) for -: 'openvino._pyopenvino.Output' and 'openvino._pyopenvino.Output'

@VLTisME
Copy link
Author

VLTisME commented Apr 22, 2025

i am working on it, thanks for your review

@VLTisME
Copy link
Author

VLTisME commented Apr 23, 2025

Why do all the tests pass when I run them locally (except for a few skipped ones), but when I push the code here, so many tests fail?
P/S: I run locally by first creating a pytest.ini and write the content in there, then:

pytest-c ./pytest.ini ./keras/src/ops/numpy_test.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Assigned Reviewer
Development

Successfully merging this pull request may close these issues.

4 participants