Skip to content

[OpenVINO] Fix for SparseCategoricalCrossentropy: cast target to int before one_hot#22607

Merged
hertschuh merged 2 commits intokeras-team:masterfrom
goyaladitya05:openvino/sparseCCE
Apr 3, 2026
Merged

[OpenVINO] Fix for SparseCategoricalCrossentropy: cast target to int before one_hot#22607
hertschuh merged 2 commits intokeras-team:masterfrom
goyaladitya05:openvino/sparseCCE

Conversation

@goyaladitya05
Copy link
Copy Markdown
Contributor

@goyaladitya05 goyaladitya05 commented Apr 1, 2026

OpenVINO's one_hot op requires integer indices, but target in sparse_categorical_crossentropy was passed without casting, causing failures when float labels were provided.

This PR adds casting target to int64 unconditionally at the top of sparse_categorical_crossentropy, similar to how other backends do it.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Apr 1, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.28%. Comparing base (6c5956d) to head (38251a4).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #22607   +/-   ##
=======================================
  Coverage   83.28%   83.28%           
=======================================
  Files         596      596           
  Lines       68102    68103    +1     
  Branches    10610    10610           
=======================================
+ Hits        56720    56721    +1     
  Misses       8636     8636           
  Partials     2746     2746           
Flag Coverage Δ
keras 83.09% <100.00%> (+<0.01%) ⬆️
keras-jax 59.65% <0.00%> (-0.01%) ⬇️
keras-numpy 55.33% <0.00%> (-0.01%) ⬇️
keras-openvino 53.41% <100.00%> (+0.02%) ⬆️
keras-tensorflow 61.03% <0.00%> (-0.01%) ⬇️
keras-torch 59.84% <0.00%> (-0.01%) ⬇️

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request enables several SparseCategoricalCrossentropy tests for the OpenVINO backend by introducing an unconditional cast of the target tensor to i64 within the sparse_categorical_crossentropy implementation. While this change allows the tests to pass, the feedback indicates that hardcoding this cast within the loss function is an internal implementation detail that violates Keras API design guidelines. It is recommended to handle such type conversions through the backend's type promotion logic instead of within the specific function implementation.

@keerthanakadiri keerthanakadiri added the stat:awaiting keras-eng Awaiting response from Keras engineer label Apr 2, 2026
@goyaladitya05 goyaladitya05 changed the title [OpenVINO] Fix SparseCategoricalCrossentropy: cast target to int before one_hot [OpenVINO] Fix for SparseCategoricalCrossentropy: cast target to int before one_hot Apr 3, 2026
Copy link
Copy Markdown
Collaborator

@hertschuh hertschuh left a comment

Choose a reason for hiding this comment

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

Thanks for the fix!

@google-ml-butler google-ml-butler bot added kokoro:force-run ready to pull Ready to be merged into the codebase labels Apr 3, 2026
@hertschuh hertschuh merged commit 7ec6d64 into keras-team:master Apr 3, 2026
12 checks passed
@goyaladitya05 goyaladitya05 deleted the openvino/sparseCCE branch April 4, 2026 03:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kokoro:force-run ready to pull Ready to be merged into the codebase size:S stat:awaiting keras-eng Awaiting response from Keras engineer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants