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

support run_options and run_metadata for tf.keras.function #19932

Conversation

facaiy
Copy link
Member

@facaiy facaiy commented Jun 12, 2018

Fix #19911.
cc @fchollet

f = keras.backend.function(inputs=[x_placeholder, y_placeholder],
outputs=[x_placeholder + y_placeholder],
updates=[(x, x_placeholder + 1.)],
fetches=[keras.backend.update(y, 5.)])
fetches=[keras.backend.update(y, 5.)],
options=run_options)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd argue that this test is inadequate because it doesn't verify the effect of sending the run_options.
I suggest you use both the options and run_metadata keywords here and set output_partition_graphs of RunOptions to True. Then you can verify that the partition_graphs of run_metadata is set after the call.

Copy link
Member Author

@facaiy facaiy Jun 13, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that it's better to add run_metadata keyword, however I'm afraid _make_callable_from_options doesn't support run_metadata yet.

callable_fn = session._make_callable_from_options(callable_opts)

https://github.com/facaiy/tensorflow/blob/a5840964e0eb422fbe73dd3738c8d14c1147276f/tensorflow/python/keras/backend.py#L2853

The solution I can see is

  1. to replace session._make_callable_from_options by session.make_callable,
  2. or, to add run_metadata support for TF_SessionMakeCallable.

how do you think it? cc @fchollet @mrry

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@facaiy run_metadata support for TF_SessionMakeCallable has been added by @mrry 574a851

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for letting me know. I'd like to add the argument in the weekend.

@@ -2759,7 +2759,8 @@ class Function(object):
outputs: Output tensors to fetch.
updates: Additional update ops to be run at function call.
name: A name to help users identify what this function does.
session_kwargs: Arguments to `tf.Session.run()`: `fetches`, `feed_dict`.
session_kwargs: Arguments to `tf.Session.run()`:
`fetches`, `feed_dict`, `options`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is run_metadata as well, which is useful for things like getting the partition graphs and step_stats.

@@ -2844,6 +2846,9 @@ def _make_callable(self, feed_arrays, feed_symbols, symbol_vals, session):
callable_opts.fetch.append(x.name)
# Handle updates.
callable_opts.target.append(self.updates_op.name)
# Handle run_options.
if self.run_options:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As mentioned above, handle run_metadata as well.

@caisq caisq added the stat:awaiting response Status - Awaiting response from author label Jun 12, 2018
@caisq caisq self-assigned this Jun 12, 2018
@fchollet fchollet requested a review from mrry June 20, 2018 21:02
@fchollet
Copy link
Member

@mrry could you please take a look? Thank you!

@mrry
Copy link
Contributor

mrry commented Jun 20, 2018

Looks fine to me, but none of this is in code I own, so is there anything specific you'd like me to review?

@facaiy
Copy link
Member Author

facaiy commented Jun 22, 2018

@caisq I have added run_metadata argument, thanks for the work of @mrry . Could you take a look again?

@facaiy facaiy changed the title support RunOptions for tf.keras.function support run_options and run_metadata for tf.keras.function Jun 22, 2018
fetched = self._callable_fn(*array_vals)
if self.run_metadata:
fetched = self._callable_fn(*array_vals,
run_metadata=self.run_metadata)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to always use lines 2908-2099? I'm guessing (and not sure) that if self.run_metadata is None, it'll be handled correctly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, I think so.

@tensorflowbutler tensorflowbutler removed the stat:awaiting response Status - Awaiting response from author label Jun 23, 2018
@tensorflowbutler
Copy link
Member

Nagging Assignee @caisq: It has been 15 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

@facaiy
Copy link
Member Author

facaiy commented Jul 11, 2018

@fchollet @caisq Hi, could you take a look? Thanks.

hermansje added a commit to hermansje/keras that referenced this pull request Jul 19, 2018
tensorflow/tensorflow#19932
metadata can only be passed to the callable when the session is instrumented
hermansje added a commit to hermansje/keras that referenced this pull request Jul 20, 2018
tensorflow/tensorflow#19932
metadata can only be passed to the callable when the session is instrumented
hermansje added a commit to hermansje/keras that referenced this pull request Jul 24, 2018
tensorflow/tensorflow#19932
metadata can only be passed to the callable when the session is instrumented
@tensorflowbutler
Copy link
Member

Nagging Assignee @caisq: It has been 14 days with no activity and this issue has an assignee. Please update the label and/or status accordingly.

@facaiy
Copy link
Member Author

facaiy commented Jul 29, 2018

Hi, could anyone take a look? I think the PR has been pending for a long time. Thanks.

@ahundt
Copy link
Contributor

ahundt commented Aug 7, 2018

This would definitely be useful to have.

@facaiy
Copy link
Member Author

facaiy commented Aug 9, 2018

@martinwicke Could you take a look? I think the PR is pending for a long time.

Copy link
Member

@pavithrasv pavithrasv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code looks good to me. I am not very familiar with run_options so I will wait for one more person to review.

@facaiy
Copy link
Member Author

facaiy commented Aug 10, 2018

@pavithrasv Thank you. Could you ping a reviewer who you think is available now?

@@ -2762,7 +2762,8 @@ class Function(object):
outputs: Output tensors to fetch.
updates: Additional update ops to be run at function call.
name: A name to help users identify what this function does.
session_kwargs: Arguments to `tf.Session.run()`: `fetches`, `feed_dict`.
session_kwargs: Arguments to `tf.Session.run()`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in getting back. This PR LGTM except for a minor comment.

session_kwarg is not precise. It should be called session_run_kwarg, otherwise it may be confused with kwargs that you can use when creating a session (e.g., https://www.tensorflow.org/api_docs/python/tf/Session)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Never mind. This is an existing name and changing it would be breaking.

@caisq caisq added the stat:awaiting response Status - Awaiting response from author label Aug 10, 2018
@caisq caisq added awaiting testing (then merge) ready to pull PR ready for merge process and removed stat:awaiting response Status - Awaiting response from author labels Aug 10, 2018
@facaiy
Copy link
Member Author

facaiy commented Aug 10, 2018

many thanks. Py2 Build failed. Could you restart it?

@caisq caisq added ready to pull PR ready for merge process kokoro:force-run Tests on submitted change and removed ready to pull PR ready for merge process awaiting testing (then merge) labels Aug 11, 2018
@kokoro-team kokoro-team removed the kokoro:force-run Tests on submitted change label Aug 11, 2018
@caisq caisq added ready to pull PR ready for merge process and removed ready to pull PR ready for merge process labels Aug 11, 2018
Copy link
Member

@fchollet fchollet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thank you! Sorry for the delayed review.

hermansje added a commit to hermansje/keras that referenced this pull request Aug 20, 2018
tensorflow/tensorflow#19932
metadata can only be passed to the callable when the session is instrumented
@tensorflow-copybara tensorflow-copybara merged commit 144ffee into tensorflow:master Aug 21, 2018
tensorflow-copybara pushed a commit that referenced this pull request Aug 21, 2018
@facaiy facaiy deleted the ENH/support_run_configs_for_keras_model branch August 21, 2018 07:19
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

10 participants