-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Add numpy.logaddexp to openvino backend #21043
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
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -848,9 +848,23 @@ def log2(x): | |
|
||
|
||
def logaddexp(x1, x2): | ||
raise NotImplementedError( | ||
"`logaddexp` is not supported with openvino backend" | ||
) | ||
element_type = None | ||
if isinstance(x1, OpenVINOKerasTensor): | ||
element_type = x1.output.get_element_type() | ||
if isinstance(x2, OpenVINOKerasTensor): | ||
element_type = x2.output.get_element_type() | ||
x1 = get_ov_output(x1, element_type) | ||
x2 = get_ov_output(x2, element_type) | ||
x1, x2 = _align_operand_types(x1, x2, "logaddexp()") | ||
x_type = x1.get_element_type() | ||
if x_type.is_integral(): | ||
ov_type = OPENVINO_DTYPES[config.floatx()] | ||
x1 = ov_opset.convert(x1, ov_type) | ||
x2 = ov_opset.convert(x2, ov_type) | ||
exp_x1 = ov_opset.exp(x1).output(0) | ||
exp_x2 = ov_opset.exp(x2).output(0) | ||
sum_exp = ov_opset.add(exp_x1, exp_x2).output(0) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I propose to make it more numerical stable for big ln(e^x1 + e^x2) = ln (e^k(e^(x1-k) + e^(x2-k))) = k ln (e^(x1-k) + e^(x2-k)), where k is maximum from x1 and x2. pay attention that by this trick x1-k and x2-k will be less than one that provides more compute stable for exponent that outputs non-negative value less than one that is better represented for floating point. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch on compute stability. I have made the changes |
||
return OpenVINOKerasTensor(ov_opset.log(sum_exp).output(0)) | ||
|
||
|
||
def logical_and(x1, x2): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please switch on tests for this functionality.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In issue you mentioned
./keras/src/ops/numpy_test.py
for testing. I initially thought that tests automatically invoke the numpy from correct backend. But on trackingknp
imports innumpy_test
file they seem to come from./keras/src/backend/numpy
module instead of openvino. I verify this by executing tests without implementinglogaddexp()
and theyPASSED
(a number of other unimplemented functions inside./keras/src/backend/openvino/numpy.py
also pass). What should I change exactly to test the function in current test setup?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please rebase to latest master and you will see corresponding lines for
logaddexp