Skip to content

Re-enable explicit control of summary tag #59

Closed

Description

@teamdandelion

Migrated from tensorflow/tensorflow#6150

The basic issue is:
It used to be possible to precisely control the display name (or tag) of summary data in TensorBoard, because users had direct control over the tag field.

However, this meant that summary code ignored tf name scopes when generating summaries and tags. This was frustrating because it meant the following code was broken:

def layer(input):
  W = get_weights_variable(somehow)
  b = get_bias_variable(somehow)
  activation = tf.nn.relu(input * W + b)
  s = tf.summary.histogram("activation_histogram", activation)
  return activation

input = tf.placeholder(...)
layer1 = layer(input)
layer2 = layer(layer1)
...
merged = tf.summary.merge_all()
....

This code would be broken because the tag "activation_histogram" would be used twice, creating a conflict.

To fix this, the summary module (which was added in tf1.0) removes explicit control of the tag from the user. Instead, the first argument to the summary is the "name", and the generated node_name is used as the summary tag. As discussed in the linked issue, however, this creates its own set of frustrations and headaches.

I think a robust solution would be to add a display_name argument to summaries, which is used to create a SummaryMetadata that TensorBoard parses. Then, TensorBoard can use the display_name as the default name in tb, and fall back to the tag in case of conflicts.

I'm not sure how to implement this in a way that generalizes to the plugin system, though. I don't want to fix it just for individual plugins. We also need to continue to support the case where users manually generate the summary proto with an explicit tag.

@jart @wchargin @chihuahua thoughts?

Activity

  1. teamdandelion commented on Jun 16, 2017

    @teamdandelion
    Author

    Also see:
    "Allow dynamic summary names in new summary interface"
    tensorflow/tensorflow#6603

  2. wchargin commented on Jul 14, 2017

    @wchargin
    Contributor

    I'd like to increase the priority on this as we encourage summary ops to be implemented as high-level TensorFlow code instead of as core TensorFlow ops. Any op that needs to process its input at all will (should) create a name_scope for this computation, but then we can't provide a summary op of the same name.

    In the meantime, we can use the following workaround: a plugin scopes its computation and creates a summary op named __internal_image_summary or something (within the name scope). Then, when the plugin backend looks at any tag, it strips a suffix /__internal_image_summary. (Graph below.) But this is certainly not something that we want to actually require plugin authors to do, and it would be great to not have it in the graph at all, so it'd be nice to have this issue resolved before we publish these new APIs.
    image

  3. added a commit that references this issue on Jul 15, 2017
    391e0be
  4. ppwwyyxx commented on Jun 17, 2018

    @ppwwyyxx
    Contributor

    What's the status of the issue?

  5. teamdandelion commented on Jun 18, 2018

    @teamdandelion
    Author

    I had the most context on this issue, but I've stopped working on TensorBoard. So unless someone else has picked it up - it's basically abandoned.

  6. nfelt commented on Jun 18, 2018

    @nfelt
    Contributor

    Our own tb.summary summary APIs all support a display_name parameter that's rendered in the frontend. We are still working on making those ready for migrating people over from tf.summary, but once you're using tb.summary I think this issue is addressed.

  7. teamdandelion commented on Jun 19, 2018

    @teamdandelion
    Author

    Oh, sweet! 👍

  8. ppwwyyxx commented on Jun 26, 2018

    @ppwwyyxx
    Contributor

    @nfelt Apart from tf.summary and tb.summary, there is also a tf.contrib.summary. They all have different APIs. What's the differences and which one we should migrate to?

  9. teamdandelion commented on Jun 28, 2018

    @teamdandelion
    Author

    I may be out of date, but I believe the team wants tb.summary to be the canonical way to put data into TensorBoard. tf.contrib, as externally-contributed code, will not be as well supported.

  10. nfelt commented on Jul 3, 2018

    @nfelt
    Contributor

    @ppwwyyxx We're working on making tb.summary the future "standard" API, but it's not quite there yet and still may be subject to some changes. In particular, right now tb.summary is a layer on top of tf.summary, but in the future it will be a layer on top of tf.contrib.summary which has a somewhat different mechanism for actually emitting summaries.

    If you're interested in display_name right away, you can use tb.summary today, just be sure to check the release notes when upgrading your TF/TB installation since we may make changes to the API that require some adjustments to the calling code for it to continue working.

  11. changed the title [-]Re-enable explicit control of summary display name[/-] [+]Re-enable explicit control of summary tag[/+] on Dec 12, 2018
  12. SiegeLordEx commented on Apr 11, 2019

    @SiegeLordEx
    Member

    Is having this be configurable still the plan? I see the preview TF2.0 summary API does not have this feature.

  13. nfelt commented on Aug 14, 2019

    @nfelt
    Contributor

    Thanks for bearing with us and apologies for the delay. The TF 2.0 summary API actually does address the underlying issue here, even though it doesn't include display_name as I originally described.

    The tl;dr is that now the string given to TF 2.0 summary ops will be directly used as the tag, except that it will be prefixed with any active name scopes. If you disable name scopes using with tf.name_scope(""): ... then you have direct control over the tag.

    Here's an TF 2.0 example to illustrate:

    import tensorflow as tf
    writer = tf.summary.create_file_writer("/tmp/tb-tag-name")
    with writer.as_default():
      tf.summary.scalar("loss", 1.0, step=1)
      tf.summary.scalar("my/arbitrary/tag", 1.0, step=1)
      with tf.name_scope("myscope"):
        tf.summary.scalar("prefixed/tag", 1.0, step=1)
        with tf.name_scope(""):
          tf.summary.scalar("unprefixed/tag", 1.0, step=1)

    After running this code, pointing TensorBoard at the logdir will show the following tag names:

    • loss
    • my/arbitrary/tag
    • myscope/prefixed/tag
    • unprefixed/tag

    The goal of this approach is to provide a hopefully reasonable compromise that avoids the pitfalls of the previous iterations of this functionality. For context, in TF 0.x, the tag was entirely determined by the user's string, but this makes it easy to accidentally have summary tags that collide (especially in library code) and results in unusable merged data in TensorBoard. To avoid this issue, TF 1.x used the op name, which is guaranteed to be unique, but this led to the lack of control described above, and the inability to do things like have a tag name that matched an actual op name (as described in the original issue tensorflow/tensorflow#6150). This led to workarounds like display_name, which wasn't a great solution because it required extra work (passing the name twice) and only solved part of the problem - it allowed having a summary tag with the same name as an op, but it didn't allow intentionally using the same tag for two summary ops in the same graph in order to plot them on the same chart (which came up for some users when using a single graph with separate summary writers for e.g. train and eval runs).

    The new TF 2.x behavior is a halfway point that still inserts the name scope (if one is present) as a prefix to help modularize code and avoid collisions, but accepts the user-provided part of the name exactly as given. The latter makes it possible to completely customize the tag if you explicitly enter into the empty global scope. Note any code intended to be reused, like library code, should not use the global scope like this - the explicit control is there as an escape hatch for end users.

    I'm optimistically closing this issue in hopes that it addresses the concerns here, but let me know if you have questions and we can discuss further.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions