Skip to content

Conversation

@alykhantejani
Copy link
Contributor

This is a fix for the bug reported here in which binary_cross_entropy_with_logits gives the wrong gradient with input and target are 0.

After some investigation, this is because the gradient of abs at 0 is 0 (see here)

In this PR I have reformulated the numerically stable binary_cross_entropy_with_logits to not use abs (originally I used what tensorflow does, which is use abs).

I guess in general we should think about whether we want the grad of abs(0) to be 0?

@fmassa
Copy link
Member

fmassa commented Jul 24, 2017

About grad(abs(0)) = 0, well, it is not differentiable in x=0, and it's sub-derivative can be anything between -1 and 1.
I had a quick look at what TF does, and I have the impression that the gradient at 0 is defined in the same way as in PyTorch, compare TF abs and PyTorch abs, and the underlying sign function has the same derivative, TF sign and PyTorch sign

@soumith soumith merged commit 112728c into pytorch:master Jul 24, 2017
@soumith
Copy link
Contributor

soumith commented Jul 24, 2017

thanks Aly!

jjsjann123 pushed a commit to jjsjann123/pytorch that referenced this pull request Nov 30, 2022
…#2195)

* Add support for a symbolic output_shape for broadcast_in_dim in the Python Frontend

* Fixed compilation of BroadcastInDimOpRecord with template specialization for defining expand sizes.  Added SymbolicSizesRecord.  Added python binding for symbolic_sizes().

* Fix up code with some suggestions from Ivan.  Changed symbolic_sizes() to tensor_sizes().

* Add some tests and fix up python based Tensor and Scalar printing.

* Added testing for tensor_sizes(). Made some minor changes to faciliate string captured definition testing.

* Add comments and fix lint issues.

* Add an output broadcast test with tensor_sizes().

* Added a test for tensor_size usage when each operand of a binary op has a broadcast.

* Fix tensor_sizes() to reflect an expand in extent.  Add appropriate test.
jagadish-amd pushed a commit to jagadish-amd/pytorch that referenced this pull request Jun 2, 2025
- Changed to support new Hipblas 3.0.0 which is part of ROCm 7.0 is
done.

CP of
ROCm@ec0c539

Co-authored-by: Pruthvi Madugundu <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants