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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement torch.xlogy #22656
Comments
perfect! thanks :) |
will this work? i think it can be simplified further.
|
It's a good start, but ideally we would get it fused. Maybe the JIT can automatically fuse this code? |
@ezyang I think the JIT can fuse pretty much everything (we can instead just use an expanded tensor as in Issam's example)
|
To be clear the request is to implement this function as a public API, not to make sure that the JIT can fuse a multi-op implementation. The Python implementation with @torch.jit.script is probably not sufficient (currently) for a public API:
|
Will gradients still be bad if (gradients of) |
馃殌 Feature
Implement
torch.xlogy
which computesx * log(y)
ifx != 0
and 0 ifx == 0
.Motivation
Often one wants to compute
x * log(x)
orx * log(y)
but define the result to be zero if x is 0 (instead of NaN). The current alternatives is to use torch.where to mask out NaN values or to add a small epsilon to x, like we do in binary cross entropy loss.Additional context
This is implemented in both SciPy and TensorFlow:
https://docs.scipy.org/doc/scipy/reference/generated/scipy.special.xlogy.html
https://www.tensorflow.org/api_docs/python/tf/math/xlogy
cc @IssamLaradji
The text was updated successfully, but these errors were encountered: