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

demo: fix example plugin #5366

Merged
merged 9 commits into from
Oct 28, 2021
Merged

Conversation

japie1235813
Copy link
Contributor

@japie1235813 japie1235813 commented Oct 7, 2021

  • Replace old multiplexer with MultiplexerDataProvider and make related changes.
  • Add Description column

Screen Shot 2021-10-27 at 4 07 59 PM

@google-cla google-cla bot added the cla: yes label Oct 7, 2021
@japie1235813 japie1235813 linked an issue Oct 7, 2021 that may be closed by this pull request
@AnimeshSinha1309
Copy link

I tested this, it works great for me, thanks and that solve #5355.

Copy link
Contributor

@nfelt nfelt left a comment

Choose a reason for hiding this comment

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

Thanks for the fixes!

run_tag_filter=provider.RunTagFilter(runs=[run], tags=[tag]),
)

data = read_result.get(run, {}).get(tag, {})
Copy link
Contributor

Choose a reason for hiding this comment

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

If there is no actual data for this run and tag, the result will be an empty dictionary, but then on the next line data[0] will fail. It's also not actually the right type - to match read_tensors(), that type should be a list.

I'd just change it to .get(tag, []) and then add an explicit check, like

if not data:
    raise werkzeug.exceptions.BadRequest("Invalid run or tag")
event_data = [data[0].numpy.item().decode("utf-8")]

The except KeyError below only worked with multiplexer.Tensors(), it won't work with the code you have now since .get() on a dict won't actually raise a KeyError.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Would data[0] be caught in the except by replacing KeyError with IndexError? (I ran a quick python terminal and looks like it does)
However I prefer add if not data but then I think the try...except could just be removed (or is there anything I miss?)

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I wasn't totally clear but with the suggested if not data code, you don't need the try...except any more.

FWIW, just to clarify my earlier comment a little - the except KeyError in the previous code was there in order to handle the case where multiplexer.Tensors() is called with a run/tag combination that has no data, since in that case the API would raise a KeyError. In the new code, the equivalent path that produces the list of Events (which is read_tensors().get(run, {}).get(tag, [])) won't raise any exception at all, even if the run and tag don't exist, because each .get() will just return the default value, so you get an empty list rather than an exception. The new code will still raise an exception eventually - but it's the next step where we call data[0] that would raise the exception here, which is a little different. That said, you're right that even if it's coming from a different step in the lookup process, we could preserve the try...except and just catch IndexError instead of KeyError. Up to you which you prefer.

Update: this will probably change anyway since we most likely don't want to do data[0] after all, see other comment.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the clarification. I remove the try...except and use the condition to raise the exception. Also made some related changes.

run_tag_filter=provider.RunTagFilter(runs=[run], tags=[tag]),
)

data = read_result.get(run, {}).get(tag, {})
Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, I wasn't totally clear but with the suggested if not data code, you don't need the try...except any more.

FWIW, just to clarify my earlier comment a little - the except KeyError in the previous code was there in order to handle the case where multiplexer.Tensors() is called with a run/tag combination that has no data, since in that case the API would raise a KeyError. In the new code, the equivalent path that produces the list of Events (which is read_tensors().get(run, {}).get(tag, [])) won't raise any exception at all, even if the run and tag don't exist, because each .get() will just return the default value, so you get an empty list rather than an exception. The new code will still raise an exception eventually - but it's the next step where we call data[0] that would raise the exception here, which is a little different. That said, you're right that even if it's coming from a different step in the lookup process, we could preserve the try...except and just catch IndexError instead of KeyError. Up to you which you prefer.

Update: this will probably change anyway since we most likely don't want to do data[0] after all, see other comment.

)

data = read_result.get(run, {}).get(tag, {})
event_data = [data[0].numpy.item().decode("utf-8")]
Copy link
Contributor

Choose a reason for hiding this comment

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

Actually, rather than what I said earlier, in order to handle multiple events (for the case where we allow downsample to be >1, i.e. we might return multiple steps' worth of data for a given time series), we should process all the elements of data - something like:

event_data = [datum.numpy.item().decode("utf-8") for datum in data]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for the example code. I've applied and checked the result. It makes more sense to me now (screenshot updated in the pr description above). Please have a second look. Thanks!

Copy link
Contributor

@nfelt nfelt left a comment

Choose a reason for hiding this comment

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

🎉 Thanks again for updating this!

@japie1235813 japie1235813 merged commit 3c384fd into tensorflow:master Oct 28, 2021
yatbear pushed a commit to yatbear/tensorboard that referenced this pull request Mar 27, 2023
* Replace old multiplexer with data provider (`MultiplexerDataProvider`) and make related changes.
* Add Description column
dna2github pushed a commit to dna2fork/tensorboard that referenced this pull request May 1, 2023
* Replace old multiplexer with data provider (`MultiplexerDataProvider`) and make related changes.
* Add Description column
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

context.multiplexer is None, example_basic plugin doesn't work
3 participants