Skip to content

Commit

Permalink
backend: eliminate unnecessary metaprogramming (#2478)
Browse files Browse the repository at this point in the history
Summary:
This was a relic of a piecewise migration from the `event_accumulator`’s
old form to its current `plugin_event_accumulator` form. (See #345 for
an example of one of the intermediate states.) Now totally superfluous,
it incurs needless cognitive and CPU overhead, as the `getattr` blocks
standard optimizations.

Test Plan:
All tests pass, and TensorBoard can still load the standard demo data.

wchargin-branch: eliminate-metaprogramming
  • Loading branch information
wchargin committed Jul 30, 2019
1 parent 52361de commit c1c2771
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions tensorboard/backend/event_processing/plugin_event_accumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,6 @@

TensorEvent = namedtuple('TensorEvent', ['wall_time', 'step', 'tensor_proto'])

## Different types of summary events handled by the event_accumulator
SUMMARY_TYPES = {
'tensor': '_ProcessTensor',
}

## The tagTypes below are just arbitrary strings chosen to pass the type
## information of the tag from the backend to the frontend
TENSORS = 'tensors'
Expand Down Expand Up @@ -350,15 +345,14 @@ def _ProcessEvent(self, event):
('This summary with tag %r is oddly not associated with a '
'plugin.'), tag)

for summary_type, summary_func in SUMMARY_TYPES.items():
if value.HasField(summary_type):
datum = getattr(value, summary_type)
tag = value.tag
if summary_type == 'tensor' and not tag:
# This tensor summary was created using the old method that used
# plugin assets. We must still continue to support it.
tag = value.node_name
getattr(self, summary_func)(tag, event.wall_time, event.step, datum)
if value.HasField('tensor'):
datum = value.tensor
tag = value.tag
if not tag:
# This tensor summary was created using the old method that used
# plugin assets. We must still continue to support it.
tag = value.node_name
self._ProcessTensor(tag, event.wall_time, event.step, datum)

def Tags(self):
"""Return all tags found in the value stream.
Expand Down

0 comments on commit c1c2771

Please sign in to comment.