-
Notifications
You must be signed in to change notification settings - Fork 1.7k
[DebuggerV2] Implement /runs route #3051
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
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
2cc8107
[DebuggerV2] Implement /runs route
caisq 84efdbc
Fix tests by using run_v2_only
caisq c52024e
Fix comment
caisq 38cccbc
Python style fix
caisq 7d73e20
Attempting to fix test in TF1
caisq d825e44
Merge branch 'dbg-v2-runs' of github.com:caisq/tensorboard into dbg-v…
caisq ef3aa59
Apply `black`; Remove unneeded pylint disables
caisq 1be2444
Add DataProvider impl
caisq 8b52a96
Merge branch 'dbg-v2-runs' of github.com:caisq/tensorboard into dbg-v…
caisq 48a9d4d
Fix typo
caisq 91f9089
Add read_blob_sequences() stub
caisq e6eea85
Fix lint issue
caisq af17873
Address review comments; Implement debug_data_multiplexer.py
caisq 8092d9c
Add more doc strings
caisq 55da5e7
Reinstate temporarily-commented code
caisq 6fbdfec
Adjust BUILD file
caisq 1580e30
Apply buildifier
caisq b90f738
Merge branch 'master' into dbg-v2-runs
caisq 5f132e2
Address review comments by wchargin@
caisq e91c2c4
Fix logic in FirstEventTimestamp()
caisq File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
tensorboard/plugins/debugger_v2/debug_data_multiplexer.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| # Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ============================================================================== | ||
| """A wrapper around DebugDataReader used for retrieving tfdbg v2 data.""" | ||
|
|
||
| from __future__ import absolute_import | ||
| from __future__ import division | ||
| from __future__ import print_function | ||
|
|
||
| # Dummy run name for the debugger. | ||
| # Currently, the `DebuggerV2ExperimentMultiplexer` class is tied to a single | ||
| # logdir, which holds at most one DebugEvent file set in the tfdbg v2 (tfdbg2 | ||
| # for short) format. | ||
| # TODO(cais): When tfdbg2 allows there to be multiple DebugEvent file sets in | ||
| # the same logdir, replace this magic string with actual run names. | ||
| DEFAULT_DEBUGGER_RUN_NAME = "__default_debugger_run__" | ||
|
|
||
|
|
||
| class DebuggerV2EventMultiplexer(object): | ||
| """A class used for accessing tfdbg v2 DebugEvent data on local filesystem. | ||
|
|
||
| This class is a short-term hack, mirroring the EventMultiplexer for the main | ||
| TensorBoard plugins (e.g., scalar, histogram and graphs.) As such, it only | ||
| implements the methods relevant to the Debugger V2 pluggin. | ||
|
|
||
| TODO(cais): Integrate it with EventMultiplexer and use the integrated class | ||
| from MultiplexerDataProvider for a single path of accessing debugger and | ||
| non-debugger data. | ||
| """ | ||
|
|
||
| def __init__(self, logdir): | ||
| """Constructor for the `DebugEventMultiplexer`. | ||
|
|
||
| Args: | ||
| logdir: Path to the directory to load the tfdbg v2 data from. | ||
| """ | ||
| self._logdir = logdir | ||
| # TODO(cais): Start off a reading thread here. | ||
|
|
||
| def FirstEventTimestamp(self, run): | ||
| """Return the timestamp of the first DebugEvent of the given run. | ||
|
|
||
| This may perform I/O if no events have been loaded yet for the run. | ||
|
|
||
| Args: | ||
| run: A string name of the run for which the timestamp is retrieved. | ||
| This currently must be hardcoded as `DEFAULT_DEBUGGER_RUN_NAME`, | ||
| as each logdir contains at most one DebugEvent file set (i.e., a | ||
| run of a tfdbg2-instrumented TensorFlow program.) | ||
|
|
||
| Returns: | ||
| The wall_time of the first event of the run, which will be in seconds | ||
| since the epoch as a `float`. | ||
| """ | ||
| if run != DEFAULT_DEBUGGER_RUN_NAME: | ||
| raise ValueError( | ||
| "Expected run name to be %s, but got %s" | ||
| % (DEFAULT_DEBUGGER_RUN_NAME, run) | ||
| ) | ||
| from tensorflow.python.debug.lib import debug_events_reader | ||
|
|
||
| with debug_events_reader.DebugEventsReader(self._logdir) as reader: | ||
| metadata_iterator, _ = reader.metadata_iterator() | ||
| return next(metadata_iterator).wall_time | ||
|
|
||
| def PluginRunToTagToContent(self, plugin_name): | ||
| raise NotImplementedError( | ||
| "DebugDataMultiplexer.PluginRunToTagToContent() has not been " | ||
| "implemented yet." | ||
| ) | ||
|
|
||
| def Runs(self): | ||
| """Return all the run names in the `EventMultiplexer`. | ||
|
|
||
| The `Run()` method of this class is specialized for the tfdbg2-format | ||
| DebugEvent files. It only returns runs | ||
|
|
||
| Returns: | ||
| If tfdbg2-format data exists in the `logdir` of this object, returns: | ||
| ``` | ||
| {runName: { "debugger-v2": [tag1, tag2, tag3] } } | ||
| ``` | ||
| where `runName` is the hard-coded string `DEFAULT_DEBUGGER_RUN_NAME` | ||
| string. This is related to the fact that tfdbg2 currently contains | ||
| at most one DebugEvent file set per directory. | ||
| If no tfdbg2-format data exists in the `logdir`, an empty `dict`. | ||
| """ | ||
| reader = None | ||
| from tensorflow.python.debug.lib import debug_events_reader | ||
|
|
||
| try: | ||
| reader = debug_events_reader.DebugDataReader(self._logdir) | ||
| # NOTE(cais): Currently each logdir is enforced to have only one | ||
| # DebugEvent file set. So we add hard-coded default run name. | ||
| except ValueError as error: | ||
| # When no DebugEvent file set is found in the logdir, a `ValueError` | ||
| # is thrown. | ||
| return {} | ||
| with reader: | ||
| return { | ||
| DEFAULT_DEBUGGER_RUN_NAME: { | ||
| # TODO(cais): Add the semantically meaningful tag names such as | ||
| # 'execution_digests_book', 'alerts_book' | ||
| "debugger-v2": [] | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| # Copyright 2019 The TensorFlow Authors. All Rights Reserved. | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| # ============================================================================== | ||
| """An implementation of DataProvider that serves tfdbg v2 data. | ||
|
|
||
| This implementation is: | ||
| 1. Based on reading data from a DebugEvent file set on the local filesystem. | ||
| 2. Implements only the relevant methods for the debugger v2 plugin, including | ||
| - list_runs() | ||
| - read_blob_sequences() | ||
| - read_blob() | ||
|
|
||
| This class is a short-term hack. To be used in production, it awaits integration | ||
| with a more complete implementation of DataProvider such as | ||
| MultiplexerDataProvider. | ||
| """ | ||
|
|
||
| from tensorboard.data import provider | ||
|
|
||
| from tensorboard.plugins.debugger_v2 import debug_data_multiplexer | ||
|
|
||
|
|
||
| class LocalDebuggerV2DataProvider(provider.DataProvider): | ||
| """A DataProvider implementation for tfdbg v2 data on local filesystem. | ||
|
|
||
| In this implementation, `experiment_id` is assumed to be the path to the | ||
| logdir that contains the DebugEvent file set. | ||
| """ | ||
|
|
||
| def __init__(self, logdir): | ||
| """Constructor of LocalDebuggerV2DataProvider. | ||
|
|
||
| Args: | ||
| logdir: Path to the directory from which the tfdbg v2 data will be | ||
| loaded. | ||
| """ | ||
| super(LocalDebuggerV2DataProvider, self).__init__() | ||
| self._multiplexer = debug_data_multiplexer.DebuggerV2EventMultiplexer( | ||
| logdir | ||
| ) | ||
|
|
||
| def list_runs(self, experiment_id): | ||
| """List runs available. | ||
|
|
||
| Args: | ||
| experiment_id: currently unused, because the backing | ||
| DebuggerV2EventMultiplexer does not accommodate multiple experiments. | ||
|
|
||
| Returns: | ||
| Run names as a list of str. | ||
| """ | ||
| return [ | ||
| provider.Run( | ||
| run_id=run, # use names as IDs | ||
| run_name=run, | ||
| start_time=self._get_first_event_timestamp(run), | ||
| ) | ||
| for run in self._multiplexer.Runs() | ||
| ] | ||
|
|
||
| def _get_first_event_timestamp(self, run_name): | ||
| try: | ||
| return self._multiplexer.FirstEventTimestamp(run_name) | ||
| except ValueError as e: | ||
| return None | ||
|
|
||
| def list_scalars(self, experiment_id, plugin_name, run_tag_filter=None): | ||
| del experiment_id, plugin_name, run_tag_filter # Unused. | ||
| raise TypeError("Debugger V2 DataProvider doesn't support scalars.") | ||
|
|
||
| def read_scalars( | ||
| self, experiment_id, plugin_name, downsample=None, run_tag_filter=None | ||
| ): | ||
| del experiment_id, plugin_name, downsample, run_tag_filter | ||
| raise TypeError("Debugger V2 DataProvider doesn't support scalars.") | ||
|
|
||
| def list_blob_sequences( | ||
| self, experiment_id, plugin_name, run_tag_filter=None | ||
| ): | ||
| del experiment_id, plugin_name, run_tag_filter # Unused currently. | ||
| # TODO(cais): Implement this. | ||
| raise NotImplementedError() | ||
|
|
||
| def read_blob_sequences( | ||
| self, experiment_id, plugin_name, downsample=None, run_tag_filter=None | ||
| ): | ||
| del experiment_id, plugin_name, downsample, run_tag_filter # Unused. | ||
| # TODO(cais): Implement this. | ||
| raise NotImplementedError() | ||
|
|
||
| def read_blob(self, blob_key): | ||
| del blob_key # Unused currently. | ||
| # TODO(cais): Implement this. | ||
| raise NotImplementedError() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/DebugDataReader/DebugEventsReader/ ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DebugDataReaderis actually the latest feature that the plugin that we intend to build on. So I'll keep this doc string for the (near) future.