tensorbored 2.21.0rc1769983804__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (271) hide show
  1. tensorbored/__init__.py +112 -0
  2. tensorbored/_vendor/__init__.py +0 -0
  3. tensorbored/_vendor/bleach/__init__.py +125 -0
  4. tensorbored/_vendor/bleach/_vendor/__init__.py +0 -0
  5. tensorbored/_vendor/bleach/_vendor/html5lib/__init__.py +35 -0
  6. tensorbored/_vendor/bleach/_vendor/html5lib/_ihatexml.py +289 -0
  7. tensorbored/_vendor/bleach/_vendor/html5lib/_inputstream.py +918 -0
  8. tensorbored/_vendor/bleach/_vendor/html5lib/_tokenizer.py +1735 -0
  9. tensorbored/_vendor/bleach/_vendor/html5lib/_trie/__init__.py +5 -0
  10. tensorbored/_vendor/bleach/_vendor/html5lib/_trie/_base.py +40 -0
  11. tensorbored/_vendor/bleach/_vendor/html5lib/_trie/py.py +67 -0
  12. tensorbored/_vendor/bleach/_vendor/html5lib/_utils.py +159 -0
  13. tensorbored/_vendor/bleach/_vendor/html5lib/constants.py +2946 -0
  14. tensorbored/_vendor/bleach/_vendor/html5lib/filters/__init__.py +0 -0
  15. tensorbored/_vendor/bleach/_vendor/html5lib/filters/alphabeticalattributes.py +29 -0
  16. tensorbored/_vendor/bleach/_vendor/html5lib/filters/base.py +12 -0
  17. tensorbored/_vendor/bleach/_vendor/html5lib/filters/inject_meta_charset.py +73 -0
  18. tensorbored/_vendor/bleach/_vendor/html5lib/filters/lint.py +93 -0
  19. tensorbored/_vendor/bleach/_vendor/html5lib/filters/optionaltags.py +207 -0
  20. tensorbored/_vendor/bleach/_vendor/html5lib/filters/sanitizer.py +916 -0
  21. tensorbored/_vendor/bleach/_vendor/html5lib/filters/whitespace.py +38 -0
  22. tensorbored/_vendor/bleach/_vendor/html5lib/html5parser.py +2795 -0
  23. tensorbored/_vendor/bleach/_vendor/html5lib/serializer.py +409 -0
  24. tensorbored/_vendor/bleach/_vendor/html5lib/treeadapters/__init__.py +30 -0
  25. tensorbored/_vendor/bleach/_vendor/html5lib/treeadapters/genshi.py +54 -0
  26. tensorbored/_vendor/bleach/_vendor/html5lib/treeadapters/sax.py +50 -0
  27. tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/__init__.py +88 -0
  28. tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/base.py +417 -0
  29. tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/dom.py +239 -0
  30. tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/etree.py +343 -0
  31. tensorbored/_vendor/bleach/_vendor/html5lib/treebuilders/etree_lxml.py +392 -0
  32. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/__init__.py +154 -0
  33. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/base.py +252 -0
  34. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/dom.py +43 -0
  35. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/etree.py +131 -0
  36. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/etree_lxml.py +215 -0
  37. tensorbored/_vendor/bleach/_vendor/html5lib/treewalkers/genshi.py +69 -0
  38. tensorbored/_vendor/bleach/_vendor/parse.py +1078 -0
  39. tensorbored/_vendor/bleach/callbacks.py +32 -0
  40. tensorbored/_vendor/bleach/html5lib_shim.py +757 -0
  41. tensorbored/_vendor/bleach/linkifier.py +633 -0
  42. tensorbored/_vendor/bleach/parse_shim.py +1 -0
  43. tensorbored/_vendor/bleach/sanitizer.py +638 -0
  44. tensorbored/_vendor/bleach/six_shim.py +19 -0
  45. tensorbored/_vendor/webencodings/__init__.py +342 -0
  46. tensorbored/_vendor/webencodings/labels.py +231 -0
  47. tensorbored/_vendor/webencodings/mklabels.py +59 -0
  48. tensorbored/_vendor/webencodings/x_user_defined.py +325 -0
  49. tensorbored/assets.py +36 -0
  50. tensorbored/auth.py +102 -0
  51. tensorbored/backend/__init__.py +0 -0
  52. tensorbored/backend/application.py +604 -0
  53. tensorbored/backend/auth_context_middleware.py +38 -0
  54. tensorbored/backend/client_feature_flags.py +113 -0
  55. tensorbored/backend/empty_path_redirect.py +46 -0
  56. tensorbored/backend/event_processing/__init__.py +0 -0
  57. tensorbored/backend/event_processing/data_ingester.py +276 -0
  58. tensorbored/backend/event_processing/data_provider.py +535 -0
  59. tensorbored/backend/event_processing/directory_loader.py +142 -0
  60. tensorbored/backend/event_processing/directory_watcher.py +272 -0
  61. tensorbored/backend/event_processing/event_accumulator.py +950 -0
  62. tensorbored/backend/event_processing/event_file_inspector.py +463 -0
  63. tensorbored/backend/event_processing/event_file_loader.py +292 -0
  64. tensorbored/backend/event_processing/event_multiplexer.py +521 -0
  65. tensorbored/backend/event_processing/event_util.py +68 -0
  66. tensorbored/backend/event_processing/io_wrapper.py +223 -0
  67. tensorbored/backend/event_processing/plugin_asset_util.py +104 -0
  68. tensorbored/backend/event_processing/plugin_event_accumulator.py +721 -0
  69. tensorbored/backend/event_processing/plugin_event_multiplexer.py +522 -0
  70. tensorbored/backend/event_processing/reservoir.py +266 -0
  71. tensorbored/backend/event_processing/tag_types.py +29 -0
  72. tensorbored/backend/experiment_id.py +71 -0
  73. tensorbored/backend/experimental_plugin.py +51 -0
  74. tensorbored/backend/http_util.py +263 -0
  75. tensorbored/backend/json_util.py +70 -0
  76. tensorbored/backend/path_prefix.py +67 -0
  77. tensorbored/backend/process_graph.py +74 -0
  78. tensorbored/backend/security_validator.py +202 -0
  79. tensorbored/compat/__init__.py +69 -0
  80. tensorbored/compat/proto/__init__.py +0 -0
  81. tensorbored/compat/proto/allocation_description_pb2.py +35 -0
  82. tensorbored/compat/proto/api_def_pb2.py +82 -0
  83. tensorbored/compat/proto/attr_value_pb2.py +80 -0
  84. tensorbored/compat/proto/cluster_pb2.py +58 -0
  85. tensorbored/compat/proto/config_pb2.py +271 -0
  86. tensorbored/compat/proto/coordination_config_pb2.py +45 -0
  87. tensorbored/compat/proto/cost_graph_pb2.py +87 -0
  88. tensorbored/compat/proto/cpp_shape_inference_pb2.py +70 -0
  89. tensorbored/compat/proto/debug_pb2.py +65 -0
  90. tensorbored/compat/proto/event_pb2.py +149 -0
  91. tensorbored/compat/proto/full_type_pb2.py +74 -0
  92. tensorbored/compat/proto/function_pb2.py +157 -0
  93. tensorbored/compat/proto/graph_debug_info_pb2.py +111 -0
  94. tensorbored/compat/proto/graph_pb2.py +41 -0
  95. tensorbored/compat/proto/histogram_pb2.py +39 -0
  96. tensorbored/compat/proto/meta_graph_pb2.py +254 -0
  97. tensorbored/compat/proto/node_def_pb2.py +61 -0
  98. tensorbored/compat/proto/op_def_pb2.py +81 -0
  99. tensorbored/compat/proto/resource_handle_pb2.py +48 -0
  100. tensorbored/compat/proto/rewriter_config_pb2.py +93 -0
  101. tensorbored/compat/proto/rpc_options_pb2.py +35 -0
  102. tensorbored/compat/proto/saved_object_graph_pb2.py +193 -0
  103. tensorbored/compat/proto/saver_pb2.py +38 -0
  104. tensorbored/compat/proto/step_stats_pb2.py +116 -0
  105. tensorbored/compat/proto/struct_pb2.py +144 -0
  106. tensorbored/compat/proto/summary_pb2.py +111 -0
  107. tensorbored/compat/proto/tensor_description_pb2.py +38 -0
  108. tensorbored/compat/proto/tensor_pb2.py +68 -0
  109. tensorbored/compat/proto/tensor_shape_pb2.py +46 -0
  110. tensorbored/compat/proto/tfprof_log_pb2.py +307 -0
  111. tensorbored/compat/proto/trackable_object_graph_pb2.py +90 -0
  112. tensorbored/compat/proto/types_pb2.py +105 -0
  113. tensorbored/compat/proto/variable_pb2.py +62 -0
  114. tensorbored/compat/proto/verifier_config_pb2.py +38 -0
  115. tensorbored/compat/proto/versions_pb2.py +35 -0
  116. tensorbored/compat/tensorflow_stub/__init__.py +38 -0
  117. tensorbored/compat/tensorflow_stub/app.py +124 -0
  118. tensorbored/compat/tensorflow_stub/compat/__init__.py +131 -0
  119. tensorbored/compat/tensorflow_stub/compat/v1/__init__.py +20 -0
  120. tensorbored/compat/tensorflow_stub/dtypes.py +692 -0
  121. tensorbored/compat/tensorflow_stub/error_codes.py +169 -0
  122. tensorbored/compat/tensorflow_stub/errors.py +507 -0
  123. tensorbored/compat/tensorflow_stub/flags.py +124 -0
  124. tensorbored/compat/tensorflow_stub/io/__init__.py +17 -0
  125. tensorbored/compat/tensorflow_stub/io/gfile.py +1011 -0
  126. tensorbored/compat/tensorflow_stub/pywrap_tensorflow.py +285 -0
  127. tensorbored/compat/tensorflow_stub/tensor_shape.py +1035 -0
  128. tensorbored/context.py +129 -0
  129. tensorbored/data/__init__.py +0 -0
  130. tensorbored/data/grpc_provider.py +365 -0
  131. tensorbored/data/ingester.py +46 -0
  132. tensorbored/data/proto/__init__.py +0 -0
  133. tensorbored/data/proto/data_provider_pb2.py +517 -0
  134. tensorbored/data/proto/data_provider_pb2_grpc.py +374 -0
  135. tensorbored/data/provider.py +1365 -0
  136. tensorbored/data/server_ingester.py +301 -0
  137. tensorbored/data_compat.py +159 -0
  138. tensorbored/dataclass_compat.py +224 -0
  139. tensorbored/default.py +124 -0
  140. tensorbored/errors.py +130 -0
  141. tensorbored/lazy.py +99 -0
  142. tensorbored/main.py +48 -0
  143. tensorbored/main_lib.py +62 -0
  144. tensorbored/manager.py +487 -0
  145. tensorbored/notebook.py +441 -0
  146. tensorbored/plugin_util.py +266 -0
  147. tensorbored/plugins/__init__.py +0 -0
  148. tensorbored/plugins/audio/__init__.py +0 -0
  149. tensorbored/plugins/audio/audio_plugin.py +229 -0
  150. tensorbored/plugins/audio/metadata.py +69 -0
  151. tensorbored/plugins/audio/plugin_data_pb2.py +37 -0
  152. tensorbored/plugins/audio/summary.py +230 -0
  153. tensorbored/plugins/audio/summary_v2.py +124 -0
  154. tensorbored/plugins/base_plugin.py +367 -0
  155. tensorbored/plugins/core/__init__.py +0 -0
  156. tensorbored/plugins/core/core_plugin.py +981 -0
  157. tensorbored/plugins/custom_scalar/__init__.py +0 -0
  158. tensorbored/plugins/custom_scalar/custom_scalars_plugin.py +320 -0
  159. tensorbored/plugins/custom_scalar/layout_pb2.py +85 -0
  160. tensorbored/plugins/custom_scalar/metadata.py +35 -0
  161. tensorbored/plugins/custom_scalar/summary.py +79 -0
  162. tensorbored/plugins/debugger_v2/__init__.py +0 -0
  163. tensorbored/plugins/debugger_v2/debug_data_multiplexer.py +631 -0
  164. tensorbored/plugins/debugger_v2/debug_data_provider.py +634 -0
  165. tensorbored/plugins/debugger_v2/debugger_v2_plugin.py +504 -0
  166. tensorbored/plugins/distribution/__init__.py +0 -0
  167. tensorbored/plugins/distribution/compressor.py +158 -0
  168. tensorbored/plugins/distribution/distributions_plugin.py +116 -0
  169. tensorbored/plugins/distribution/metadata.py +19 -0
  170. tensorbored/plugins/graph/__init__.py +0 -0
  171. tensorbored/plugins/graph/graph_util.py +129 -0
  172. tensorbored/plugins/graph/graphs_plugin.py +336 -0
  173. tensorbored/plugins/graph/keras_util.py +328 -0
  174. tensorbored/plugins/graph/metadata.py +42 -0
  175. tensorbored/plugins/histogram/__init__.py +0 -0
  176. tensorbored/plugins/histogram/histograms_plugin.py +144 -0
  177. tensorbored/plugins/histogram/metadata.py +63 -0
  178. tensorbored/plugins/histogram/plugin_data_pb2.py +34 -0
  179. tensorbored/plugins/histogram/summary.py +234 -0
  180. tensorbored/plugins/histogram/summary_v2.py +292 -0
  181. tensorbored/plugins/hparams/__init__.py +14 -0
  182. tensorbored/plugins/hparams/_keras.py +93 -0
  183. tensorbored/plugins/hparams/api.py +130 -0
  184. tensorbored/plugins/hparams/api_pb2.py +208 -0
  185. tensorbored/plugins/hparams/backend_context.py +606 -0
  186. tensorbored/plugins/hparams/download_data.py +158 -0
  187. tensorbored/plugins/hparams/error.py +26 -0
  188. tensorbored/plugins/hparams/get_experiment.py +71 -0
  189. tensorbored/plugins/hparams/hparams_plugin.py +206 -0
  190. tensorbored/plugins/hparams/hparams_util_pb2.py +69 -0
  191. tensorbored/plugins/hparams/json_format_compat.py +38 -0
  192. tensorbored/plugins/hparams/list_metric_evals.py +57 -0
  193. tensorbored/plugins/hparams/list_session_groups.py +1040 -0
  194. tensorbored/plugins/hparams/metadata.py +125 -0
  195. tensorbored/plugins/hparams/metrics.py +41 -0
  196. tensorbored/plugins/hparams/plugin_data_pb2.py +69 -0
  197. tensorbored/plugins/hparams/summary.py +205 -0
  198. tensorbored/plugins/hparams/summary_v2.py +597 -0
  199. tensorbored/plugins/image/__init__.py +0 -0
  200. tensorbored/plugins/image/images_plugin.py +232 -0
  201. tensorbored/plugins/image/metadata.py +65 -0
  202. tensorbored/plugins/image/plugin_data_pb2.py +34 -0
  203. tensorbored/plugins/image/summary.py +159 -0
  204. tensorbored/plugins/image/summary_v2.py +130 -0
  205. tensorbored/plugins/mesh/__init__.py +14 -0
  206. tensorbored/plugins/mesh/mesh_plugin.py +292 -0
  207. tensorbored/plugins/mesh/metadata.py +152 -0
  208. tensorbored/plugins/mesh/plugin_data_pb2.py +37 -0
  209. tensorbored/plugins/mesh/summary.py +251 -0
  210. tensorbored/plugins/mesh/summary_v2.py +214 -0
  211. tensorbored/plugins/metrics/__init__.py +0 -0
  212. tensorbored/plugins/metrics/metadata.py +17 -0
  213. tensorbored/plugins/metrics/metrics_plugin.py +623 -0
  214. tensorbored/plugins/pr_curve/__init__.py +0 -0
  215. tensorbored/plugins/pr_curve/metadata.py +75 -0
  216. tensorbored/plugins/pr_curve/plugin_data_pb2.py +34 -0
  217. tensorbored/plugins/pr_curve/pr_curves_plugin.py +241 -0
  218. tensorbored/plugins/pr_curve/summary.py +574 -0
  219. tensorbored/plugins/profile_redirect/__init__.py +0 -0
  220. tensorbored/plugins/profile_redirect/profile_redirect_plugin.py +49 -0
  221. tensorbored/plugins/projector/__init__.py +67 -0
  222. tensorbored/plugins/projector/metadata.py +26 -0
  223. tensorbored/plugins/projector/projector_config_pb2.py +54 -0
  224. tensorbored/plugins/projector/projector_plugin.py +795 -0
  225. tensorbored/plugins/projector/tf_projector_plugin/index.js +32 -0
  226. tensorbored/plugins/projector/tf_projector_plugin/projector_binary.html +524 -0
  227. tensorbored/plugins/projector/tf_projector_plugin/projector_binary.js +15536 -0
  228. tensorbored/plugins/scalar/__init__.py +0 -0
  229. tensorbored/plugins/scalar/metadata.py +60 -0
  230. tensorbored/plugins/scalar/plugin_data_pb2.py +34 -0
  231. tensorbored/plugins/scalar/scalars_plugin.py +181 -0
  232. tensorbored/plugins/scalar/summary.py +109 -0
  233. tensorbored/plugins/scalar/summary_v2.py +124 -0
  234. tensorbored/plugins/text/__init__.py +0 -0
  235. tensorbored/plugins/text/metadata.py +62 -0
  236. tensorbored/plugins/text/plugin_data_pb2.py +34 -0
  237. tensorbored/plugins/text/summary.py +114 -0
  238. tensorbored/plugins/text/summary_v2.py +124 -0
  239. tensorbored/plugins/text/text_plugin.py +288 -0
  240. tensorbored/plugins/wit_redirect/__init__.py +0 -0
  241. tensorbored/plugins/wit_redirect/wit_redirect_plugin.py +49 -0
  242. tensorbored/program.py +910 -0
  243. tensorbored/summary/__init__.py +35 -0
  244. tensorbored/summary/_output.py +124 -0
  245. tensorbored/summary/_tf/__init__.py +14 -0
  246. tensorbored/summary/_tf/summary/__init__.py +178 -0
  247. tensorbored/summary/_writer.py +105 -0
  248. tensorbored/summary/v1.py +51 -0
  249. tensorbored/summary/v2.py +25 -0
  250. tensorbored/summary/writer/__init__.py +13 -0
  251. tensorbored/summary/writer/event_file_writer.py +291 -0
  252. tensorbored/summary/writer/record_writer.py +50 -0
  253. tensorbored/util/__init__.py +0 -0
  254. tensorbored/util/encoder.py +116 -0
  255. tensorbored/util/grpc_util.py +311 -0
  256. tensorbored/util/img_mime_type_detector.py +40 -0
  257. tensorbored/util/io_util.py +20 -0
  258. tensorbored/util/lazy_tensor_creator.py +110 -0
  259. tensorbored/util/op_evaluator.py +104 -0
  260. tensorbored/util/platform_util.py +20 -0
  261. tensorbored/util/tb_logging.py +24 -0
  262. tensorbored/util/tensor_util.py +617 -0
  263. tensorbored/util/timing.py +122 -0
  264. tensorbored/version.py +21 -0
  265. tensorbored/webfiles.zip +0 -0
  266. tensorbored-2.21.0rc1769983804.dist-info/METADATA +49 -0
  267. tensorbored-2.21.0rc1769983804.dist-info/RECORD +271 -0
  268. tensorbored-2.21.0rc1769983804.dist-info/WHEEL +5 -0
  269. tensorbored-2.21.0rc1769983804.dist-info/entry_points.txt +6 -0
  270. tensorbored-2.21.0rc1769983804.dist-info/licenses/LICENSE +739 -0
  271. tensorbored-2.21.0rc1769983804.dist-info/top_level.txt +1 -0
@@ -0,0 +1,721 @@
1
+ # Copyright 2015 The TensorFlow Authors. All Rights Reserved.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+ # ==============================================================================
15
+ """Takes a generator of values, and accumulates them for a frontend."""
16
+
17
+ import collections
18
+ import dataclasses
19
+ import threading
20
+
21
+ from typing import Optional
22
+
23
+ from tensorbored.backend.event_processing import directory_loader
24
+ from tensorbored.backend.event_processing import directory_watcher
25
+ from tensorbored.backend.event_processing import event_file_loader
26
+ from tensorbored.backend.event_processing import event_util
27
+ from tensorbored.backend.event_processing import io_wrapper
28
+ from tensorbored.backend.event_processing import plugin_asset_util
29
+ from tensorbored.backend.event_processing import reservoir
30
+ from tensorbored.backend.event_processing import tag_types
31
+ from tensorbored.compat.proto import config_pb2
32
+ from tensorbored.compat.proto import event_pb2
33
+ from tensorbored.compat.proto import graph_pb2
34
+ from tensorbored.compat.proto import meta_graph_pb2
35
+ from tensorbored.compat.proto import tensor_pb2
36
+ from tensorbored.util import tb_logging
37
+
38
+ logger = tb_logging.get_logger()
39
+
40
+
41
+ # Legacy aliases
42
+ TENSORS = tag_types.TENSORS
43
+ GRAPH = tag_types.GRAPH
44
+ META_GRAPH = tag_types.META_GRAPH
45
+ RUN_METADATA = tag_types.RUN_METADATA
46
+
47
+ DEFAULT_SIZE_GUIDANCE = {
48
+ TENSORS: 500,
49
+ }
50
+
51
+ STORE_EVERYTHING_SIZE_GUIDANCE = {
52
+ TENSORS: 0,
53
+ }
54
+
55
+ _TENSOR_RESERVOIR_KEY = "." # arbitrary
56
+
57
+
58
+ @dataclasses.dataclass(frozen=True)
59
+ class TensorEvent:
60
+ """A tensor event.
61
+
62
+ Attributes:
63
+ wall_time: Timestamp of the event in seconds.
64
+ step: Global step of the event.
65
+ tensor_proto: A `TensorProto`.
66
+ """
67
+
68
+ wall_time: float
69
+ step: int
70
+ tensor_proto: tensor_pb2.TensorProto
71
+
72
+
73
+ class EventAccumulator:
74
+ """An `EventAccumulator` takes an event generator, and accumulates the
75
+ values.
76
+
77
+ The `EventAccumulator` is intended to provide a convenient Python
78
+ interface for loading Event data written during a TensorFlow run.
79
+ TensorFlow writes out `Event` protobuf objects, which have a timestamp
80
+ and step number, and often contain a `Summary`. Summaries can have
81
+ different kinds of data stored as arbitrary tensors. The Summaries
82
+ also have a tag, which we use to organize logically related data. The
83
+ `EventAccumulator` supports retrieving the `Event` and `Summary` data
84
+ by its tag.
85
+
86
+ Calling `Tags()` gets a map from `tagType` (i.e., `tensors`) to the
87
+ associated tags for those data types. Then, the functional endpoint
88
+ (i.g., `Accumulator.Tensors(tag)`) allows for the retrieval of all
89
+ data associated with that tag.
90
+
91
+ The `Reload()` method synchronously loads all of the data written so far.
92
+
93
+ Fields:
94
+ most_recent_step: Step of last Event proto added. This should only
95
+ be accessed from the thread that calls Reload. This is -1 if
96
+ nothing has been loaded yet.
97
+ most_recent_wall_time: Timestamp of last Event proto added. This is
98
+ a float containing seconds from the UNIX epoch, or -1 if
99
+ nothing has been loaded yet. This should only be accessed from
100
+ the thread that calls Reload.
101
+ path: A file path to a directory containing tf events files, or a single
102
+ tf events file. The accumulator will load events from this path.
103
+ tensors_by_tag: A dictionary mapping each tag name to a
104
+ reservoir.Reservoir of tensor summaries. Each such reservoir will
105
+ only use a single key, given by `_TENSOR_RESERVOIR_KEY`.
106
+
107
+ @@Tensors
108
+ """
109
+
110
+ def __init__(
111
+ self,
112
+ path,
113
+ size_guidance=None,
114
+ tensor_size_guidance=None,
115
+ purge_orphaned_data=True,
116
+ event_file_active_filter=None,
117
+ detect_file_replacement=None,
118
+ ):
119
+ """Construct the `EventAccumulator`.
120
+
121
+ Args:
122
+ path: A file path to a directory containing tf events files, or a single
123
+ tf events file. The accumulator will load events from this path.
124
+ size_guidance: Information on how much data the EventAccumulator should
125
+ store in memory. The DEFAULT_SIZE_GUIDANCE tries not to store too much
126
+ so as to avoid OOMing the client. The size_guidance should be a map
127
+ from a `tagType` string to an integer representing the number of
128
+ items to keep per tag for items of that `tagType`. If the size is 0,
129
+ all events are stored.
130
+ tensor_size_guidance: Like `size_guidance`, but allowing finer
131
+ granularity for tensor summaries. Should be a map from the
132
+ `plugin_name` field on the `PluginData` proto to an integer
133
+ representing the number of items to keep per tag. Plugins for
134
+ which there is no entry in this map will default to the value of
135
+ `size_guidance[event_accumulator.TENSORS]`. Defaults to `{}`.
136
+ purge_orphaned_data: Whether to discard any events that were "orphaned" by
137
+ a TensorFlow restart.
138
+ event_file_active_filter: Optional predicate for determining whether an
139
+ event file latest load timestamp should be considered active. If passed,
140
+ this will enable multifile directory loading.
141
+ detect_file_replacement: Optional boolean; if True, event file loading
142
+ will try to detect when a file has been replaced with a new version
143
+ that contains additional data, by monitoring the file size.
144
+ """
145
+ size_guidance = dict(size_guidance or DEFAULT_SIZE_GUIDANCE)
146
+ sizes = {}
147
+ for key in DEFAULT_SIZE_GUIDANCE:
148
+ if key in size_guidance:
149
+ sizes[key] = size_guidance[key]
150
+ else:
151
+ sizes[key] = DEFAULT_SIZE_GUIDANCE[key]
152
+ self._size_guidance = size_guidance
153
+ self._tensor_size_guidance = dict(tensor_size_guidance or {})
154
+
155
+ self._first_event_timestamp = None
156
+
157
+ self._graph = None
158
+ self._graph_from_metagraph = False
159
+ self._meta_graph = None
160
+ self._tagged_metadata = {}
161
+ self.summary_metadata = {}
162
+ self.tensors_by_tag = {}
163
+ self._tensors_by_tag_lock = threading.Lock()
164
+
165
+ # Keep a mapping from plugin name to a dict mapping from tag to plugin data
166
+ # content obtained from the SummaryMetadata (metadata field of Value) for
167
+ # that plugin (This is not the entire SummaryMetadata proto - only the
168
+ # content for that plugin). The SummaryWriter only keeps the content on the
169
+ # first event encountered per tag, so we must store that first instance of
170
+ # content for each tag.
171
+ self._plugin_to_tag_to_content = collections.defaultdict(dict)
172
+ # Locks the dict `_plugin_to_tag_to_content` as well as the
173
+ # dicts `_plugin_to_tag_to_content[p]` for each `p`.
174
+ self._plugin_tag_lock = threading.Lock()
175
+
176
+ self.path = path
177
+ self._generator = _GeneratorFromPath(
178
+ path, event_file_active_filter, detect_file_replacement
179
+ )
180
+ self._generator_mutex = threading.Lock()
181
+
182
+ self.purge_orphaned_data = purge_orphaned_data
183
+ self._seen_session_start = False
184
+
185
+ self.most_recent_step = -1
186
+ self.most_recent_wall_time = -1
187
+ self.file_version = None
188
+
189
+ # Name of the source writer that writes the event.
190
+ self._source_writer = None
191
+
192
+ def Reload(self):
193
+ """Loads all events added since the last call to `Reload`.
194
+
195
+ If `Reload` was never called, loads all events in the file.
196
+
197
+ Returns:
198
+ The `EventAccumulator`.
199
+ """
200
+ with self._generator_mutex:
201
+ for event in self._generator.Load():
202
+ self._ProcessEvent(event)
203
+ return self
204
+
205
+ def PluginAssets(self, plugin_name):
206
+ """Return a list of all plugin assets for the given plugin.
207
+
208
+ Args:
209
+ plugin_name: The string name of a plugin to retrieve assets for.
210
+
211
+ Returns:
212
+ A list of string plugin asset names, or empty list if none are available.
213
+ If the plugin was not registered, an empty list is returned.
214
+ """
215
+ return plugin_asset_util.ListAssets(self.path, plugin_name)
216
+
217
+ def RetrievePluginAsset(self, plugin_name, asset_name):
218
+ """Return the contents of a given plugin asset.
219
+
220
+ Args:
221
+ plugin_name: The string name of a plugin.
222
+ asset_name: The string name of an asset.
223
+
224
+ Returns:
225
+ The string contents of the plugin asset.
226
+
227
+ Raises:
228
+ KeyError: If the asset is not available.
229
+ """
230
+ return plugin_asset_util.RetrieveAsset(
231
+ self.path, plugin_name, asset_name
232
+ )
233
+
234
+ def FirstEventTimestamp(self):
235
+ """Returns the timestamp in seconds of the first event.
236
+
237
+ If the first event has been loaded (either by this method or by `Reload`,
238
+ this returns immediately. Otherwise, it will load in the first event. Note
239
+ that this means that calling `Reload` will cause this to block until
240
+ `Reload` has finished.
241
+
242
+ Returns:
243
+ The timestamp in seconds of the first event that was loaded.
244
+
245
+ Raises:
246
+ ValueError: If no events have been loaded and there were no events found
247
+ on disk.
248
+ """
249
+ if self._first_event_timestamp is not None:
250
+ return self._first_event_timestamp
251
+ with self._generator_mutex:
252
+ try:
253
+ event = next(self._generator.Load())
254
+ self._ProcessEvent(event)
255
+ return self._first_event_timestamp
256
+
257
+ except StopIteration:
258
+ raise ValueError("No event timestamp could be found")
259
+
260
+ def GetSourceWriter(self) -> Optional[str]:
261
+ """Returns the name of the event writer."""
262
+ if self._source_writer is not None:
263
+ return self._source_writer
264
+ with self._generator_mutex:
265
+ try:
266
+ event = next(self._generator.Load())
267
+ self._ProcessEvent(event)
268
+ return self._source_writer
269
+ except StopIteration:
270
+ logger.info(
271
+ "End of file in %s, no source writer was found.", self.path
272
+ )
273
+
274
+ def PluginTagToContent(self, plugin_name):
275
+ """Returns a dict mapping tags to content specific to that plugin.
276
+
277
+ Args:
278
+ plugin_name: The name of the plugin for which to fetch plugin-specific
279
+ content.
280
+
281
+ Raises:
282
+ KeyError: if the plugin name is not found.
283
+
284
+ Returns:
285
+ A dict mapping tag names to bytestrings of plugin-specific content-- by
286
+ convention, in the form of binary serialized protos.
287
+ """
288
+ with self._plugin_tag_lock:
289
+ if plugin_name not in self._plugin_to_tag_to_content:
290
+ raise KeyError("Plugin %r could not be found." % plugin_name)
291
+ # Return a snapshot to avoid concurrent mutation and iteration issues.
292
+ return dict(self._plugin_to_tag_to_content[plugin_name])
293
+
294
+ def ActivePlugins(self):
295
+ """Return a set of plugins with summary data.
296
+
297
+ Returns:
298
+ The distinct union of `plugin_data.plugin_name` fields from
299
+ all the `SummaryMetadata` protos stored in this accumulator.
300
+ """
301
+ with self._plugin_tag_lock:
302
+ return frozenset(self._plugin_to_tag_to_content)
303
+
304
+ def SummaryMetadata(self, tag):
305
+ """Given a summary tag name, return the associated metadata object.
306
+
307
+ Args:
308
+ tag: The name of a tag, as a string.
309
+
310
+ Raises:
311
+ KeyError: If the tag is not found.
312
+
313
+ Returns:
314
+ A `SummaryMetadata` protobuf.
315
+ """
316
+ return self.summary_metadata[tag]
317
+
318
+ def AllSummaryMetadata(self):
319
+ """Return summary metadata for all tags.
320
+
321
+ Returns:
322
+ A dict `d` such that `d[tag]` is a `SummaryMetadata` proto for
323
+ the keyed tag.
324
+ """
325
+ return dict(self.summary_metadata)
326
+
327
+ def _ProcessEvent(self, event):
328
+ """Called whenever an event is loaded."""
329
+ if self._first_event_timestamp is None:
330
+ self._first_event_timestamp = event.wall_time
331
+
332
+ if event.HasField("source_metadata"):
333
+ new_source_writer = event_util.GetSourceWriter(
334
+ event.source_metadata
335
+ )
336
+ if self._source_writer and self._source_writer != new_source_writer:
337
+ logger.info(
338
+ (
339
+ "Found new source writer for event.proto. "
340
+ "Old: {0}, New: {1}"
341
+ ).format(self._source_writer, new_source_writer)
342
+ )
343
+ self._source_writer = new_source_writer
344
+
345
+ if event.HasField("file_version"):
346
+ new_file_version = event_util.ParseFileVersion(event.file_version)
347
+ if self.file_version and self.file_version != new_file_version:
348
+ ## This should not happen.
349
+ logger.warning(
350
+ (
351
+ "Found new file_version for event.proto. This will "
352
+ "affect purging logic for TensorFlow restarts. "
353
+ "Old: {0} New: {1}"
354
+ ).format(self.file_version, new_file_version)
355
+ )
356
+ self.file_version = new_file_version
357
+
358
+ self._MaybePurgeOrphanedData(event)
359
+
360
+ ## Process the event.
361
+ # GraphDef and MetaGraphDef are handled in a special way:
362
+ # If no graph_def Event is available, but a meta_graph_def is, and it
363
+ # contains a graph_def, then use the meta_graph_def.graph_def as our graph.
364
+ # If a graph_def Event is available, always prefer it to the graph_def
365
+ # inside the meta_graph_def.
366
+ if event.HasField("graph_def"):
367
+ if self._graph is not None:
368
+ logger.warning(
369
+ (
370
+ "Found more than one graph event per run, or there was "
371
+ "a metagraph containing a graph_def, as well as one or "
372
+ "more graph events. Overwriting the graph with the "
373
+ "newest event."
374
+ )
375
+ )
376
+ self._graph = event.graph_def
377
+ self._graph_from_metagraph = False
378
+ elif event.HasField("meta_graph_def"):
379
+ if self._meta_graph is not None:
380
+ logger.warning(
381
+ (
382
+ "Found more than one metagraph event per run. "
383
+ "Overwriting the metagraph with the newest event."
384
+ )
385
+ )
386
+ self._meta_graph = event.meta_graph_def
387
+ if self._graph is None or self._graph_from_metagraph:
388
+ # We may have a graph_def in the metagraph. If so, and no
389
+ # graph_def is directly available, use this one instead.
390
+ meta_graph = meta_graph_pb2.MetaGraphDef()
391
+ meta_graph.ParseFromString(self._meta_graph)
392
+ if meta_graph.graph_def:
393
+ if self._graph is not None:
394
+ logger.warning(
395
+ (
396
+ "Found multiple metagraphs containing graph_defs,"
397
+ "but did not find any graph events. Overwriting the "
398
+ "graph with the newest metagraph version."
399
+ )
400
+ )
401
+ self._graph_from_metagraph = True
402
+ self._graph = meta_graph.graph_def.SerializeToString()
403
+ elif event.HasField("tagged_run_metadata"):
404
+ tag = event.tagged_run_metadata.tag
405
+ if tag in self._tagged_metadata:
406
+ logger.warning(
407
+ 'Found more than one "run metadata" event with tag '
408
+ + tag
409
+ + ". Overwriting it with the newest event."
410
+ )
411
+ self._tagged_metadata[tag] = event.tagged_run_metadata.run_metadata
412
+ elif event.HasField("summary"):
413
+ for value in event.summary.value:
414
+ if value.HasField("metadata"):
415
+ tag = value.tag
416
+ # We only store the first instance of the metadata. This check
417
+ # is important: the `FileWriter` does strip metadata from all
418
+ # values except the first one per each tag, but a new
419
+ # `FileWriter` is created every time a training job stops and
420
+ # restarts. Hence, we must also ignore non-initial metadata in
421
+ # this logic.
422
+ if tag not in self.summary_metadata:
423
+ self.summary_metadata[tag] = value.metadata
424
+ plugin_data = value.metadata.plugin_data
425
+ if plugin_data.plugin_name:
426
+ with self._plugin_tag_lock:
427
+ self._plugin_to_tag_to_content[
428
+ plugin_data.plugin_name
429
+ ][tag] = plugin_data.content
430
+ else:
431
+ logger.warning(
432
+ (
433
+ "This summary with tag %r is oddly not associated with a "
434
+ "plugin."
435
+ ),
436
+ tag,
437
+ )
438
+
439
+ if value.HasField("tensor"):
440
+ datum = value.tensor
441
+ tag = value.tag
442
+ if not tag:
443
+ # This tensor summary was created using the old method that used
444
+ # plugin assets. We must still continue to support it.
445
+ tag = value.node_name
446
+ self._ProcessTensor(tag, event.wall_time, event.step, datum)
447
+
448
+ def Tags(self):
449
+ """Return all tags found in the value stream.
450
+
451
+ Returns:
452
+ A `{tagType: ['list', 'of', 'tags']}` dictionary.
453
+ """
454
+ return {
455
+ TENSORS: list(self.tensors_by_tag.keys()),
456
+ # Use a heuristic: if the metagraph is available, but
457
+ # graph is not, then we assume the metagraph contains the graph.
458
+ GRAPH: self._graph is not None,
459
+ META_GRAPH: self._meta_graph is not None,
460
+ RUN_METADATA: list(self._tagged_metadata.keys()),
461
+ }
462
+
463
+ def Graph(self):
464
+ """Return the graph definition, if there is one.
465
+
466
+ If the graph is stored directly, return that. If no graph is stored
467
+ directly but a metagraph is stored containing a graph, return that.
468
+
469
+ Raises:
470
+ ValueError: If there is no graph for this run.
471
+
472
+ Returns:
473
+ The `graph_def` proto.
474
+ """
475
+ graph = graph_pb2.GraphDef()
476
+ if self._graph is not None:
477
+ graph.ParseFromString(self._graph)
478
+ return graph
479
+ raise ValueError("There is no graph in this EventAccumulator")
480
+
481
+ def SerializedGraph(self):
482
+ """Return the graph definition in serialized form, if there is one."""
483
+ return self._graph
484
+
485
+ def MetaGraph(self):
486
+ """Return the metagraph definition, if there is one.
487
+
488
+ Raises:
489
+ ValueError: If there is no metagraph for this run.
490
+
491
+ Returns:
492
+ The `meta_graph_def` proto.
493
+ """
494
+ if self._meta_graph is None:
495
+ raise ValueError("There is no metagraph in this EventAccumulator")
496
+ meta_graph = meta_graph_pb2.MetaGraphDef()
497
+ meta_graph.ParseFromString(self._meta_graph)
498
+ return meta_graph
499
+
500
+ def RunMetadata(self, tag):
501
+ """Given a tag, return the associated session.run() metadata.
502
+
503
+ Args:
504
+ tag: A string tag associated with the event.
505
+
506
+ Raises:
507
+ ValueError: If the tag is not found.
508
+
509
+ Returns:
510
+ The metadata in form of `RunMetadata` proto.
511
+ """
512
+ if tag not in self._tagged_metadata:
513
+ raise ValueError("There is no run metadata with this tag name")
514
+
515
+ run_metadata = config_pb2.RunMetadata()
516
+ run_metadata.ParseFromString(self._tagged_metadata[tag])
517
+ return run_metadata
518
+
519
+ def Tensors(self, tag):
520
+ """Given a summary tag, return all associated tensors.
521
+
522
+ Args:
523
+ tag: A string tag associated with the events.
524
+
525
+ Raises:
526
+ KeyError: If the tag is not found.
527
+
528
+ Returns:
529
+ An array of `TensorEvent`s.
530
+ """
531
+ return self.tensors_by_tag[tag].Items(_TENSOR_RESERVOIR_KEY)
532
+
533
+ def _MaybePurgeOrphanedData(self, event):
534
+ """Maybe purge orphaned data due to a TensorFlow crash.
535
+
536
+ When TensorFlow crashes at step T+O and restarts at step T, any events
537
+ written after step T are now "orphaned" and will be at best misleading if
538
+ they are included in TensorBoard.
539
+
540
+ This logic attempts to determine if there is orphaned data, and purge it
541
+ if it is found.
542
+
543
+ Args:
544
+ event: The event to use as a reference, to determine if a purge is needed.
545
+ """
546
+ if not self.purge_orphaned_data:
547
+ return
548
+ ## Check if the event happened after a crash, and purge expired tags.
549
+ if self.file_version and self.file_version >= 2:
550
+ ## If the file_version is recent enough, use the SessionLog enum
551
+ ## to check for restarts.
552
+ self._CheckForRestartAndMaybePurge(event)
553
+ else:
554
+ ## If there is no file version, default to old logic of checking for
555
+ ## out of order steps.
556
+ self._CheckForOutOfOrderStepAndMaybePurge(event)
557
+ # After checking, update the most recent summary step and wall time.
558
+ if event.HasField("summary"):
559
+ self.most_recent_step = event.step
560
+ self.most_recent_wall_time = event.wall_time
561
+
562
+ def _CheckForRestartAndMaybePurge(self, event):
563
+ """Check and discard expired events using SessionLog.START.
564
+
565
+ The first SessionLog.START event in a run indicates the start of a
566
+ supervisor session. Subsequent SessionLog.START events indicate a
567
+ *restart*, which may need to preempt old events. This method checks
568
+ for a session restart event and purges all previously seen events whose
569
+ step is larger than or equal to this event's step.
570
+
571
+ Because of supervisor threading, it is possible that this logic will
572
+ cause the first few event messages to be discarded since supervisor
573
+ threading does not guarantee that the START message is deterministically
574
+ written first.
575
+
576
+ This method is preferred over _CheckForOutOfOrderStepAndMaybePurge which
577
+ can inadvertently discard events due to supervisor threading.
578
+
579
+ Args:
580
+ event: The event to use as reference. If the event is a START event, all
581
+ previously seen events with a greater event.step will be purged.
582
+ """
583
+ if event.session_log.status != event_pb2.SessionLog.START:
584
+ return
585
+ if not self._seen_session_start:
586
+ # Initial start event: does not indicate a restart.
587
+ self._seen_session_start = True
588
+ return
589
+ self._Purge(event, by_tags=False)
590
+
591
+ def _CheckForOutOfOrderStepAndMaybePurge(self, event):
592
+ """Check for out-of-order event.step and discard expired events for
593
+ tags.
594
+
595
+ Check if the event is out of order relative to the global most recent step.
596
+ If it is, purge outdated summaries for tags that the event contains.
597
+
598
+ Args:
599
+ event: The event to use as reference. If the event is out-of-order, all
600
+ events with the same tags, but with a greater event.step will be purged.
601
+ """
602
+ if event.step < self.most_recent_step and event.HasField("summary"):
603
+ self._Purge(event, by_tags=True)
604
+
605
+ def _ProcessTensor(self, tag, wall_time, step, tensor):
606
+ tv = TensorEvent(wall_time=wall_time, step=step, tensor_proto=tensor)
607
+ with self._tensors_by_tag_lock:
608
+ if tag not in self.tensors_by_tag:
609
+ reservoir_size = self._GetTensorReservoirSize(tag)
610
+ self.tensors_by_tag[tag] = reservoir.Reservoir(reservoir_size)
611
+ self.tensors_by_tag[tag].AddItem(_TENSOR_RESERVOIR_KEY, tv)
612
+
613
+ def _GetTensorReservoirSize(self, tag):
614
+ default = self._size_guidance[TENSORS]
615
+ summary_metadata = self.summary_metadata.get(tag)
616
+ if summary_metadata is None:
617
+ return default
618
+ return self._tensor_size_guidance.get(
619
+ summary_metadata.plugin_data.plugin_name, default
620
+ )
621
+
622
+ def _Purge(self, event, by_tags):
623
+ """Purge all events that have occurred after the given event.step.
624
+
625
+ If by_tags is True, purge all events that occurred after the given
626
+ event.step, but only for the tags that the event has. Non-sequential
627
+ event.steps suggest that a TensorFlow restart occurred, and we discard
628
+ the out-of-order events to display a consistent view in TensorBoard.
629
+
630
+ Discarding by tags is the safer method, when we are unsure whether a restart
631
+ has occurred, given that threading in supervisor can cause events of
632
+ different tags to arrive with unsynchronized step values.
633
+
634
+ If by_tags is False, then purge all events with event.step greater than the
635
+ given event.step. This can be used when we are certain that a TensorFlow
636
+ restart has occurred and these events can be discarded.
637
+
638
+ Args:
639
+ event: The event to use as reference for the purge. All events with
640
+ the same tags, but with a greater event.step will be purged.
641
+ by_tags: Bool to dictate whether to discard all out-of-order events or
642
+ only those that are associated with the given reference event.
643
+ """
644
+ ## Keep data in reservoirs that has a step less than event.step
645
+ _NotExpired = lambda x: x.step < event.step
646
+
647
+ num_expired = 0
648
+ if by_tags:
649
+ for value in event.summary.value:
650
+ if value.tag in self.tensors_by_tag:
651
+ tag_reservoir = self.tensors_by_tag[value.tag]
652
+ num_expired += tag_reservoir.FilterItems(
653
+ _NotExpired, _TENSOR_RESERVOIR_KEY
654
+ )
655
+ else:
656
+ for tag_reservoir in self.tensors_by_tag.values():
657
+ num_expired += tag_reservoir.FilterItems(
658
+ _NotExpired, _TENSOR_RESERVOIR_KEY
659
+ )
660
+ if num_expired > 0:
661
+ purge_msg = _GetPurgeMessage(
662
+ self.most_recent_step,
663
+ self.most_recent_wall_time,
664
+ event.step,
665
+ event.wall_time,
666
+ num_expired,
667
+ )
668
+ logger.warning(purge_msg)
669
+
670
+
671
+ def _GetPurgeMessage(
672
+ most_recent_step,
673
+ most_recent_wall_time,
674
+ event_step,
675
+ event_wall_time,
676
+ num_expired,
677
+ ):
678
+ """Return the string message associated with TensorBoard purges."""
679
+ return (
680
+ "Detected out of order event.step likely caused by a TensorFlow "
681
+ "restart. Purging {} expired tensor events from Tensorboard display "
682
+ "between the previous step: {} (timestamp: {}) and current step: {} "
683
+ "(timestamp: {})."
684
+ ).format(
685
+ num_expired,
686
+ most_recent_step,
687
+ most_recent_wall_time,
688
+ event_step,
689
+ event_wall_time,
690
+ )
691
+
692
+
693
+ def _GeneratorFromPath(
694
+ path, event_file_active_filter=None, detect_file_replacement=None
695
+ ):
696
+ """Create an event generator for file or directory at given path string."""
697
+ if not path:
698
+ raise ValueError("path must be a valid string")
699
+ if io_wrapper.IsSummaryEventsFile(path):
700
+ return event_file_loader.EventFileLoader(path, detect_file_replacement)
701
+ elif event_file_active_filter:
702
+ loader_factory = (
703
+ lambda path: event_file_loader.TimestampedEventFileLoader(
704
+ path, detect_file_replacement
705
+ )
706
+ )
707
+ return directory_loader.DirectoryLoader(
708
+ path,
709
+ loader_factory,
710
+ path_filter=io_wrapper.IsSummaryEventsFile,
711
+ active_filter=event_file_active_filter,
712
+ )
713
+ else:
714
+ loader_factory = lambda path: event_file_loader.EventFileLoader(
715
+ path, detect_file_replacement
716
+ )
717
+ return directory_watcher.DirectoryWatcher(
718
+ path,
719
+ loader_factory,
720
+ io_wrapper.IsSummaryEventsFile,
721
+ )