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

Defer image/audio/histogram v2 summary preprocessing using LazyTensorCreator #2899

Merged
merged 7 commits into from
Nov 7, 2019

Conversation

nfelt
Copy link
Contributor

@nfelt nfelt commented Nov 6, 2019

Continuation of PRs #2893, #2894, #2895 by @hongjunChoi .

This takes advantage of a recent change in tf.summary.write() as of tensorflow/tensorflow@661f0ac that allows passing a callable as the tensor argument instead of an actual tf.Tensor. With this functionality, write() will call the callable to get the tensor only if the tensor is going to be used (i.e. the summary writer exists and the summary recording condition is met). This avoids overhead in executing preprocessing steps when they are not needed. Among V2 summaries, only image, audio, and histogram do any real preprocessing, so those are the only ones changed in this PR.

In order to maintain backwards compatibility with the previous write() API, this introduces a shim layer called LazyTensorCreator that uses tf.register_tensor_conversion_function() to ensure that the callable we pass in can be automatically converted to a tf.Tensor in many contexts (and in particular, in the context of the call to tf.identity() which is used inside write()). That way a version skew (e.g. TensorBoard 2.1 but TensorFlow 2.0) won't break the summary API integration; while technically we don't guarantee that a skew in this direction will work, this is a likely enough situation and a confusing enough error that it's worth a bit of work to avoid.

cc @alextp FYI

@@ -29,11 +29,14 @@
from __future__ import division
from __future__ import print_function

import functools
Copy link
Contributor

Choose a reason for hiding this comment

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

Unused?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed, thanks.


def test_reentrant_callable_does_not_deadlock(self):
@lazy_tensor_creator.LazyTensorCreator
def lazy_tensor(nested_call=False):
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this nested_call=False vestigial?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, removed. Thanks for the catch.

@nfelt nfelt merged commit 88dbe55 into tensorflow:master Nov 7, 2019
@nfelt nfelt deleted the summary-defer-preprocessing branch November 7, 2019 07:59
yatbear added a commit to yatbear/tensorboard that referenced this pull request Sep 30, 2021
  To defer image/audio/histogram v2 summary preprocessing. See
  tensorflow#2899 for more details.
yatbear added a commit that referenced this pull request Oct 1, 2021
* use LazyTensorCreator

  To defer image/audio/histogram v2 summary preprocessing. See
  #2899 for more details.

* add _buckets_v3 skeleton

  It's currently just a copy of _buckets(), modification for
  single value case handling will be added later.
yatbear added a commit to yatbear/tensorboard that referenced this pull request Mar 27, 2023
…low#5352)

* use LazyTensorCreator

  To defer image/audio/histogram v2 summary preprocessing. See
  tensorflow#2899 for more details.

* add _buckets_v3 skeleton

  It's currently just a copy of _buckets(), modification for
  single value case handling will be added later.
dna2github pushed a commit to dna2fork/tensorboard that referenced this pull request May 1, 2023
…low#5352)

* use LazyTensorCreator

  To defer image/audio/histogram v2 summary preprocessing. See
  tensorflow#2899 for more details.

* add _buckets_v3 skeleton

  It's currently just a copy of _buckets(), modification for
  single value case handling will be added later.
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