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

parallel_for: use absl wrapper and add converter for SoftplusGrad #21716

Merged
merged 2 commits into from
Sep 5, 2018

Conversation

artsobolev
Copy link
Contributor

Consider the following snippet

import tensorflow as tf
from tensorflow.python.ops.parallel_for import gradients

x = tf.placeholder(tf.float32, (None,))
y = tf.nn.softplus(x)

print(gradients.jacobian(y, x))

On the current master it fails with

Traceback (most recent call last):
  File "test.py", line 7, in <module>
    print(gradients.jacobian(y, x))
  File "/Users/asobolev/dev/tensorflow/pfor_test/venv/lib/python3.6/site-packages/tensorflow/python/ops/parallel_for/gradients.py", line 58, in jacobian
    pfor_outputs = control_flow_ops.pfor(loop_fn, output_size)
  File "/Users/asobolev/dev/tensorflow/pfor_test/venv/lib/python3.6/site-packages/tensorflow/python/ops/parallel_for/control_flow_ops.py", line 122, in pfor
    outputs.append(converter.convert(loop_fn_output))
  File "/Users/asobolev/dev/tensorflow/pfor_test/venv/lib/python3.6/site-packages/tensorflow/python/ops/parallel_for/pfor.py", line 1075, in convert
    output = self._convert_helper(y)
  File "/Users/asobolev/dev/tensorflow/pfor_test/venv/lib/python3.6/site-packages/tensorflow/python/ops/parallel_for/pfor.py", line 1214, in _convert_helper
    if flags.FLAGS.op_conversion_fallback_to_while_loop:
  File "/Users/asobolev/dev/tensorflow/pfor_test/venv/lib/python3.6/site-packages/absl/flags/_flagvalues.py", line 488, in __getattr__
    raise _exceptions.UnparsedFlagAccessError(error_message)
absl.flags._exceptions.UnparsedFlagAccessError: Trying to access flag --op_conversion_fallback_to_while_loop before flags were parsed.

This is caused by the fact that no converter is registered for the SoftplusGrad op, and when parallel_for sees no converter defined, it tries to fall back to a while loop, if this is allowed with a special CLI flag. The problem, though, is that it uses raw absl call which requires one to first explicitly parse command line arguments. To mitigate that, one should use a flags wrapper from the tensorflow.platform, which is what I did.

Also, this pull introduces a converter for SoftplusGrad in the same way as, say, SigmoidGrad.

@akshaym akshaym added the ready to pull PR ready for merge process label Aug 22, 2018
@artsobolev
Copy link
Contributor Author

@agarwal-ashish, any news?

@yifeif yifeif added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels Sep 5, 2018
@tensorflow-copybara tensorflow-copybara merged commit 0c8c6fc into tensorflow:master Sep 5, 2018
tensorflow-copybara pushed a commit that referenced this pull request Sep 5, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cla: yes ready to pull PR ready for merge process
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants