Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions tensorboard/data/provider.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,8 @@ class DataProvider(object):

Unless otherwise noted, any methods on this class may raise errors
defined in `tensorboard.errors`, like `tensorboard.errors.NotFoundError`.

If not implemented, optional methods may return `None`.
"""

def data_location(self, ctx=None, *, experiment_id):
Expand Down
5 changes: 5 additions & 0 deletions tensorboard/plugins/metrics/metrics_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,11 @@ def _tags_impl(self, ctx, experiment=None):
experiment_id=experiment,
plugin_name=image_metadata.PLUGIN_NAME,
)
# Not all data providers support tensors and/or blob sequences.
if histogram_mapping is None:
histogram_mapping = {}
if image_mapping is None:
image_mapping = {}
Copy link
Contributor

Choose a reason for hiding this comment

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

If unimplemented DataProvider methods may return None, can we add the corresponding if scalar_mapping is None check as well, so that metrics_plugin.py doesn't rely on knowing which specific dataclasses have implemented list_*?

On the other hand, should GrpcDataProvider be responsible for implementing list_tensors that returns {}? [1] suggests that instances of classes with @abc.abstractmethod must have "all of its abstract methods and properties are overridden". Would it make sense to add GrpcDataProvider.list_tensors/blobs, or update the data/provider.py docstrings to indicate that they may return None?

[1] https://docs.python.org/3/library/abc.html#abc.abstractmethod

Copy link
Contributor Author

@wchargin wchargin Dec 7, 2020

Choose a reason for hiding this comment

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

The scalars methods are abc.abstractmethods whereas the methods for
other data classes are not. You cannot instantiate a DataProvider
without implementing read_scalars. It’ll hard-error.

That these methods pass when not implemented is (in my experience)
fairly standard. For example, the abc docs do so:

class C(ABC):
    @abstractmethod
    def my_abstract_method(self):
        ...  # will return None; this is equivalent to `pass`

But I’m happy to document it explicitly. Done.

Copy link
Contributor

Choose a reason for hiding this comment

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

The scalars methods are abc.abstractmethods whereas the methods for
other data classes are not

Ahh, thanks for pointing this out. I think my comment earlier was invalid, so feel free to keep or remove the data/provider.py change as you see fit!


result = {}
result["scalars"] = _format_basic_mapping(scalar_mapping)
Expand Down