Skip to content
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

[feature request] disable harmful broadcast #1406

Closed
raingo opened this issue Mar 6, 2016 · 5 comments
Closed

[feature request] disable harmful broadcast #1406

raingo opened this issue Mar 6, 2016 · 5 comments

Comments

@raingo
Copy link
Contributor

raingo commented Mar 6, 2016

Broadcast may lead to hidden bugs. For example, the following code,

xent = tf.nn. sigmoid_cross_entropy_with_logits(logits, y)
loss = tf.reduce_mean(xent)

When logits is of the shape (200,1) and the y is of the shape (200,), the xent becomes (200, 200), which is wrong. What's worse, the reduce_mean will hide this problem by reducing everything into a scalar.

Request,

  1. more shape validation in sigmoid_cross_entropy_with_logits
  2. option to totally disable broadcast
@vrv
Copy link

vrv commented Mar 6, 2016

  1. is done:
    raise ValueError(
    -- will be in our next binary release.

@raingo
Copy link
Contributor Author

raingo commented Mar 6, 2016

Thanks. I guess the second is impossible. so closing.

@raingo raingo closed this as completed Mar 6, 2016
@vrv
Copy link

vrv commented Mar 7, 2016

Nothing is impossible, it would just take a lot of work to plumb that through everywhere, to set the option globally, and for everything to work as well without broadcasting. For example, when computing gradients, automatic broadcasting is quite useful to simplify gradient expressions, particularly when the shapes are unknown at construction time. I've seen similar requests made for numpy, and it sounds like higher level libraries typically provide the 'safety' for those users who want it. However, I'm open to the idea if it can be done in a nice way.

@rasmusbergpalm
Copy link

I have spent 8 hours on exactly this bug. An option to disable broadcasting globally or raising a warning, etc. would be very nice.

@agentydragon
Copy link

Just ran into a bug which would also have been prevented by warning on broadcasting. A a * b operation ended up doing vector * vector -> matrix multiplication instead of vector * vector -> vector elementwise multiplication. Cost me on the order of tens of hours (writeup). Would be nice to either have the option for such a warning, or at least more specific operators that require the programmer to be more explicit about intent. (e.g.: tf.math.elementwise_multiply).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants