Skip to content

Commit 3cad6d6

Browse files
authored
Revert the changes in event_accumulator. (#6013)
Reverts changes in event_accumulator from #5998, this caused internal breakage, where users directly access `EventAccumulator` and unpack the events like tuples.
1 parent 5ccf430 commit 3cad6d6

File tree

1 file changed

+37
-131
lines changed

1 file changed

+37
-131
lines changed

tensorboard/backend/event_processing/event_accumulator.py

Lines changed: 37 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,8 @@
1515
"""Takes a generator of values, and accumulates them for a frontend."""
1616

1717
import collections
18-
import dataclasses
1918
import threading
2019

21-
from typing import Sequence, Tuple
22-
2320
from tensorboard.backend.event_processing import directory_watcher
2421
from tensorboard.backend.event_processing import event_file_loader
2522
from tensorboard.backend.event_processing import io_wrapper
@@ -30,137 +27,47 @@
3027
from tensorboard.compat.proto import event_pb2
3128
from tensorboard.compat.proto import graph_pb2
3229
from tensorboard.compat.proto import meta_graph_pb2
33-
from tensorboard.compat.proto import tensor_pb2
3430
from tensorboard.plugins.distribution import compressor
3531
from tensorboard.util import tb_logging
3632

3733

3834
logger = tb_logging.get_logger()
3935

40-
41-
@dataclasses.dataclass(frozen=True)
42-
class ScalarEvent:
43-
"""Contains information of a scalar event.
44-
45-
Attributes:
46-
wall_time: Timestamp of the event in seconds.
47-
step: Global step of the event.
48-
value: A float or int value of the scalar.
49-
"""
50-
51-
wall_time: float
52-
step: int
53-
value: float
54-
55-
56-
@dataclasses.dataclass(frozen=True)
57-
class CompressedHistogramEvent:
58-
"""Contains information of a compressed histogram event.
59-
60-
Attributes:
61-
wall_time: Timestamp of the event in seconds.
62-
step: Global step of the event.
63-
compressed_histogram_values: A sequence of tuples of basis points and
64-
associated values in a compressed histogram.
65-
"""
66-
67-
wall_time: float
68-
step: int
69-
compressed_histogram_values: Sequence[Tuple[float, float]]
70-
71-
72-
@dataclasses.dataclass(frozen=True)
73-
class HistogramValue:
74-
"""Holds the information of the histogram values.
75-
76-
Attributes:
77-
min: A float or int min value.
78-
max: A float or int max value.
79-
num: Total number of values.
80-
sum: Sum of all values.
81-
sum_squares: Sum of squares for all values.
82-
bucket_limit: Upper values per bucket.
83-
bucket: Numbers of values per bucket.
84-
"""
85-
86-
min: float
87-
max: float
88-
num: int
89-
sum: float
90-
sum_squares: float
91-
bucket_limit: Sequence[float]
92-
bucket: Sequence[int]
93-
94-
95-
@dataclasses.dataclass(frozen=True)
96-
class HistogramEvent:
97-
"""Contains information of a histogram event.
98-
99-
Attributes:
100-
wall_time: Timestamp of the event in seconds.
101-
step: Global step of the event.
102-
histogram_value: Information of the histogram values.
103-
"""
104-
105-
wall_time: float
106-
step: int
107-
histogram_value: HistogramValue
108-
109-
110-
@dataclasses.dataclass(frozen=True)
111-
class ImageEvent:
112-
"""Contains information of an image event.
113-
114-
Attributes:
115-
wall_time: Timestamp of the event in seconds.
116-
step: Global step of the event.
117-
encoded_image_string: Image content encoded in bytes.
118-
width: Width of the image.
119-
height: Height of the image.
120-
"""
121-
122-
wall_time: float
123-
step: int
124-
encoded_image_string: bytes
125-
width: int
126-
height: int
127-
128-
129-
@dataclasses.dataclass(frozen=True)
130-
class AudioEvent:
131-
"""Contains information of an audio event.
132-
133-
Attributes:
134-
wall_time: Timestamp of the event in seconds.
135-
step: Global step of the event.
136-
encoded_audio_string: Audio content encoded in bytes.
137-
content_type: A string describes the type of the audio content.
138-
sample_rate: Sample rate of the audio in Hz. Must be positive.
139-
length_frames: Length of the audio in frames (samples per channel).
140-
"""
141-
142-
wall_time: float
143-
step: int
144-
encoded_audio_string: bytes
145-
content_type: str
146-
sample_rate: float
147-
length_frames: int
148-
149-
150-
@dataclasses.dataclass(frozen=True)
151-
class TensorEvent:
152-
"""A tensor event.
153-
154-
Attributes:
155-
wall_time: Timestamp of the event in seconds.
156-
step: Global step of the event.
157-
tensor_proto: A `TensorProto`.
158-
"""
159-
160-
wall_time: float
161-
step: int
162-
tensor_proto: tensor_pb2.TensorProto
163-
36+
namedtuple = collections.namedtuple
37+
ScalarEvent = namedtuple("ScalarEvent", ["wall_time", "step", "value"])
38+
39+
CompressedHistogramEvent = namedtuple(
40+
"CompressedHistogramEvent",
41+
["wall_time", "step", "compressed_histogram_values"],
42+
)
43+
44+
HistogramEvent = namedtuple(
45+
"HistogramEvent", ["wall_time", "step", "histogram_value"]
46+
)
47+
48+
HistogramValue = namedtuple(
49+
"HistogramValue",
50+
["min", "max", "num", "sum", "sum_squares", "bucket_limit", "bucket"],
51+
)
52+
53+
ImageEvent = namedtuple(
54+
"ImageEvent",
55+
["wall_time", "step", "encoded_image_string", "width", "height"],
56+
)
57+
58+
AudioEvent = namedtuple(
59+
"AudioEvent",
60+
[
61+
"wall_time",
62+
"step",
63+
"encoded_audio_string",
64+
"content_type",
65+
"sample_rate",
66+
"length_frames",
67+
],
68+
)
69+
70+
TensorEvent = namedtuple("TensorEvent", ["wall_time", "step", "tensor_proto"])
16471

16572
## Different types of summary events handled by the event_accumulator
16673
SUMMARY_TYPES = {
@@ -757,8 +664,7 @@ def _CheckForOutOfOrderStepAndMaybePurge(self, event):
757664
self.most_recent_step = event.step
758665
self.most_recent_wall_time = event.wall_time
759666

760-
def _ConvertHistogramProtoToPopo(self, histo):
761-
"""Converts histogram proto to Python object."""
667+
def _ConvertHistogramProtoToTuple(self, histo):
762668
return HistogramValue(
763669
min=histo.min,
764670
max=histo.max,
@@ -771,7 +677,7 @@ def _ConvertHistogramProtoToPopo(self, histo):
771677

772678
def _ProcessHistogram(self, tag, wall_time, step, histo):
773679
"""Processes a proto histogram by adding it to accumulated state."""
774-
histo = self._ConvertHistogramProtoToPopo(histo)
680+
histo = self._ConvertHistogramProtoToTuple(histo)
775681
histo_ev = HistogramEvent(wall_time, step, histo)
776682
self.histograms.AddItem(tag, histo_ev)
777683
self.compressed_histograms.AddItem(

0 commit comments

Comments
 (0)