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,606 @@
1
+ # Copyright 2019 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
+ """Wraps the base_plugin.TBContext to stores additional data shared across API
16
+ handlers for the HParams plugin backend."""
17
+
18
+ import collections
19
+ import os
20
+
21
+
22
+ from tensorbored.data import provider
23
+ from tensorbored.plugins.hparams import api_pb2
24
+ from tensorbored.plugins.hparams import json_format_compat
25
+ from tensorbored.plugins.hparams import metadata
26
+ from google.protobuf import json_format
27
+ from tensorbored.plugins.scalar import metadata as scalar_metadata
28
+
29
+ _DISCRETE_DOMAIN_TYPE_TO_DATA_TYPE = {
30
+ provider.HyperparameterDomainType.DISCRETE_BOOL: api_pb2.DATA_TYPE_BOOL,
31
+ provider.HyperparameterDomainType.DISCRETE_FLOAT: api_pb2.DATA_TYPE_FLOAT64,
32
+ provider.HyperparameterDomainType.DISCRETE_STRING: api_pb2.DATA_TYPE_STRING,
33
+ }
34
+
35
+
36
+ class Context:
37
+ """Wraps the base_plugin.TBContext to stores additional data shared across
38
+ API handlers for the HParams plugin backend.
39
+
40
+ Before adding fields to this class, carefully consider whether the
41
+ field truly needs to be accessible to all API handlers or if it
42
+ can be passed separately to the handler constructor. We want to
43
+ avoid this class becoming a magic container of variables that have
44
+ no better place. See http://wiki.c2.com/?MagicContainer
45
+ """
46
+
47
+ def __init__(self, tb_context):
48
+ """Instantiates a context.
49
+
50
+ Args:
51
+ tb_context: base_plugin.TBContext. The "base" context we extend.
52
+ """
53
+ self._tb_context = tb_context
54
+
55
+ def experiment_from_metadata(
56
+ self,
57
+ ctx,
58
+ experiment_id,
59
+ include_metrics,
60
+ hparams_run_to_tag_to_content,
61
+ data_provider_hparams,
62
+ hparams_limit=None,
63
+ ):
64
+ """Returns the experiment proto defining the experiment.
65
+
66
+ This method first attempts to find a metadata.EXPERIMENT_TAG tag and
67
+ retrieve the associated proto.
68
+
69
+ If no such tag is found, the method will attempt to build a minimal
70
+ experiment proto by scanning for all metadata.SESSION_START_INFO_TAG
71
+ tags (to compute the hparam_infos field of the experiment) and for all
72
+ scalar tags (to compute the metric_infos field of the experiment).
73
+
74
+ If no metadata.EXPERIMENT_TAG nor metadata.SESSION_START_INFO_TAG tags
75
+ are found, then will build an experiment proto using the results from
76
+ DataProvider.list_hyperparameters().
77
+
78
+ Args:
79
+ experiment_id: String, from `plugin_util.experiment_id`.
80
+ include_metrics: Whether to determine metrics_infos and include them
81
+ in the result.
82
+ hparams_run_to_tag_to_content: The output from an hparams_metadata()
83
+ call. A dict `d` such that `d[run][tag]` is a `bytes` value with the
84
+ summary metadata content for the keyed time series.
85
+ data_provider_hparams: The output from an hparams_from_data_provider()
86
+ call, corresponding to DataProvider.list_hyperparameters().
87
+ A provider.ListHyperpararametersResult.
88
+ hparams_limit: Optional number of hyperparameter metadata to include in the
89
+ result. If unset or zero, all metadata will be included.
90
+
91
+ Returns:
92
+ The experiment proto. If no data is found for an experiment proto to
93
+ be built, returns an entirely empty experiment.
94
+ """
95
+ experiment = self._find_experiment_tag(
96
+ hparams_run_to_tag_to_content, include_metrics
97
+ )
98
+ if experiment:
99
+ _sort_and_reduce_to_hparams_limit(experiment, hparams_limit)
100
+ return experiment
101
+
102
+ experiment_from_runs = self._compute_experiment_from_runs(
103
+ ctx, experiment_id, include_metrics, hparams_run_to_tag_to_content
104
+ )
105
+ if experiment_from_runs:
106
+ _sort_and_reduce_to_hparams_limit(
107
+ experiment_from_runs, hparams_limit
108
+ )
109
+ return experiment_from_runs
110
+
111
+ experiment_from_data_provider_hparams = (
112
+ self._experiment_from_data_provider_hparams(
113
+ ctx, experiment_id, include_metrics, data_provider_hparams
114
+ )
115
+ )
116
+ return (
117
+ experiment_from_data_provider_hparams
118
+ if experiment_from_data_provider_hparams
119
+ else api_pb2.Experiment()
120
+ )
121
+
122
+ @property
123
+ def tb_context(self):
124
+ return self._tb_context
125
+
126
+ def _convert_plugin_metadata(self, data_provider_output):
127
+ return {
128
+ run: {
129
+ tag: time_series.plugin_content
130
+ for (tag, time_series) in tag_to_time_series.items()
131
+ }
132
+ for (run, tag_to_time_series) in data_provider_output.items()
133
+ }
134
+
135
+ def hparams_metadata(self, ctx, experiment_id, run_tag_filter=None):
136
+ """Reads summary metadata for all hparams time series.
137
+
138
+ Args:
139
+ experiment_id: String, from `plugin_util.experiment_id`.
140
+ run_tag_filter: Optional `data.provider.RunTagFilter`, with
141
+ the semantics as in `list_tensors`.
142
+
143
+ Returns:
144
+ A dict `d` such that `d[run][tag]` is a `bytes` value with the
145
+ summary metadata content for the keyed time series.
146
+ """
147
+ return self._convert_plugin_metadata(
148
+ self._tb_context.data_provider.list_tensors(
149
+ ctx,
150
+ experiment_id=experiment_id,
151
+ plugin_name=metadata.PLUGIN_NAME,
152
+ run_tag_filter=run_tag_filter,
153
+ )
154
+ )
155
+
156
+ def scalars_metadata(self, ctx, experiment_id):
157
+ """Reads summary metadata for all scalar time series.
158
+
159
+ Args:
160
+ experiment_id: String, from `plugin_util.experiment_id`.
161
+
162
+ Returns:
163
+ A dict `d` such that `d[run][tag]` is a `bytes` value with the
164
+ summary metadata content for the keyed time series.
165
+ """
166
+ return self._convert_plugin_metadata(
167
+ self._tb_context.data_provider.list_scalars(
168
+ ctx,
169
+ experiment_id=experiment_id,
170
+ plugin_name=scalar_metadata.PLUGIN_NAME,
171
+ )
172
+ )
173
+
174
+ def read_last_scalars(self, ctx, experiment_id, run_tag_filter):
175
+ """Reads the most recent values from scalar time series.
176
+
177
+ Args:
178
+ experiment_id: String.
179
+ run_tag_filter: Required `data.provider.RunTagFilter`, with
180
+ the semantics as in `read_last_scalars`.
181
+
182
+ Returns:
183
+ A dict `d` such that `d[run][tag]` is a `provider.ScalarDatum`
184
+ value, with keys only for runs and tags that actually had
185
+ data, which may be a subset of what was requested.
186
+ """
187
+ return self._tb_context.data_provider.read_last_scalars(
188
+ ctx,
189
+ experiment_id=experiment_id,
190
+ plugin_name=scalar_metadata.PLUGIN_NAME,
191
+ run_tag_filter=run_tag_filter,
192
+ )
193
+
194
+ def hparams_from_data_provider(self, ctx, experiment_id, limit):
195
+ """Calls DataProvider.list_hyperparameters() and returns the result."""
196
+ return self._tb_context.data_provider.list_hyperparameters(
197
+ ctx, experiment_ids=[experiment_id], limit=limit
198
+ )
199
+
200
+ def session_groups_from_data_provider(
201
+ self, ctx, experiment_id, filters, sort, hparams_to_include
202
+ ):
203
+ """Calls DataProvider.read_hyperparameters() and returns the result."""
204
+ return self._tb_context.data_provider.read_hyperparameters(
205
+ ctx,
206
+ experiment_ids=[experiment_id],
207
+ filters=filters,
208
+ sort=sort,
209
+ hparams_to_include=hparams_to_include,
210
+ )
211
+
212
+ def _find_experiment_tag(
213
+ self, hparams_run_to_tag_to_content, include_metrics
214
+ ):
215
+ """Finds the experiment associated with the metadata.EXPERIMENT_TAG
216
+ tag.
217
+
218
+ Returns:
219
+ The experiment or None if no such experiment is found.
220
+ """
221
+ # We expect only one run to have an `EXPERIMENT_TAG`; look
222
+ # through all of them and arbitrarily pick the first one.
223
+ for tags in hparams_run_to_tag_to_content.values():
224
+ maybe_content = tags.get(metadata.EXPERIMENT_TAG)
225
+ if maybe_content is not None:
226
+ experiment = metadata.parse_experiment_plugin_data(
227
+ maybe_content
228
+ )
229
+ if not include_metrics:
230
+ # metric_infos haven't technically been "calculated" in this
231
+ # case. They have been read directly from the Experiment
232
+ # proto.
233
+ # Delete them from the result so that they are not returned
234
+ # to the client.
235
+ experiment.ClearField("metric_infos")
236
+ return experiment
237
+ return None
238
+
239
+ def _compute_experiment_from_runs(
240
+ self, ctx, experiment_id, include_metrics, hparams_run_to_tag_to_content
241
+ ):
242
+ """Computes a minimal Experiment protocol buffer by scanning the runs.
243
+
244
+ Returns None if there are no hparam infos logged.
245
+ """
246
+ hparam_infos = self._compute_hparam_infos(hparams_run_to_tag_to_content)
247
+ metric_infos = (
248
+ self._compute_metric_infos_from_runs(
249
+ ctx, experiment_id, hparams_run_to_tag_to_content
250
+ )
251
+ if hparam_infos and include_metrics
252
+ else []
253
+ )
254
+ if not hparam_infos and not metric_infos:
255
+ return None
256
+
257
+ return api_pb2.Experiment(
258
+ hparam_infos=hparam_infos, metric_infos=metric_infos
259
+ )
260
+
261
+ def _compute_hparam_infos(self, hparams_run_to_tag_to_content):
262
+ """Computes a list of api_pb2.HParamInfo from the current run, tag
263
+ info.
264
+
265
+ Finds all the SessionStartInfo messages and collects the hparams values
266
+ appearing in each one. For each hparam attempts to deduce a type that fits
267
+ all its values. Finally, sets the 'domain' of the resulting HParamInfo
268
+ to be discrete if the type is string or boolean.
269
+
270
+ Returns:
271
+ A list of api_pb2.HParamInfo messages.
272
+ """
273
+ # Construct a dict mapping an hparam name to its list of values.
274
+ hparams = collections.defaultdict(list)
275
+ for tag_to_content in hparams_run_to_tag_to_content.values():
276
+ if metadata.SESSION_START_INFO_TAG not in tag_to_content:
277
+ continue
278
+ start_info = metadata.parse_session_start_info_plugin_data(
279
+ tag_to_content[metadata.SESSION_START_INFO_TAG]
280
+ )
281
+ for name, value in start_info.hparams.items():
282
+ hparams[name].append(value)
283
+
284
+ # Try to construct an HParamInfo for each hparam from its name and list
285
+ # of values.
286
+ result = []
287
+ for name, values in hparams.items():
288
+ hparam_info = self._compute_hparam_info_from_values(name, values)
289
+ if hparam_info is not None:
290
+ result.append(hparam_info)
291
+ return result
292
+
293
+ def _compute_hparam_info_from_values(self, name, values):
294
+ """Builds an HParamInfo message from the hparam name and list of
295
+ values.
296
+
297
+ Args:
298
+ name: string. The hparam name.
299
+ values: list of google.protobuf.Value messages. The list of values for the
300
+ hparam.
301
+
302
+ Returns:
303
+ An api_pb2.HParamInfo message.
304
+ """
305
+ # Figure out the type from the values.
306
+ # Ignore values whose type is not listed in api_pb2.DataType
307
+ # If all values have the same type, then that is the type used.
308
+ # Otherwise, the returned type is DATA_TYPE_STRING.
309
+ result = api_pb2.HParamInfo(name=name, type=api_pb2.DATA_TYPE_UNSET)
310
+ for v in values:
311
+ v_type = _protobuf_value_type(v)
312
+ if not v_type:
313
+ continue
314
+ if result.type == api_pb2.DATA_TYPE_UNSET:
315
+ result.type = v_type
316
+ elif result.type != v_type:
317
+ result.type = api_pb2.DATA_TYPE_STRING
318
+ if result.type == api_pb2.DATA_TYPE_STRING:
319
+ # A string result.type does not change, so we can exit the loop.
320
+ break
321
+
322
+ # If we couldn't figure out a type, then we can't compute the hparam_info.
323
+ if result.type == api_pb2.DATA_TYPE_UNSET:
324
+ return None
325
+
326
+ if result.type == api_pb2.DATA_TYPE_STRING:
327
+ distinct_string_values = set(
328
+ _protobuf_value_to_string(v)
329
+ for v in values
330
+ if _can_be_converted_to_string(v)
331
+ )
332
+ result.domain_discrete.extend(distinct_string_values)
333
+ result.differs = len(distinct_string_values) > 1
334
+
335
+ if result.type == api_pb2.DATA_TYPE_BOOL:
336
+ distinct_bool_values = set(v.bool_value for v in values)
337
+ result.domain_discrete.extend(distinct_bool_values)
338
+ result.differs = len(distinct_bool_values) > 1
339
+
340
+ if result.type == api_pb2.DATA_TYPE_FLOAT64:
341
+ # Always uses interval domain type for numeric hparam values.
342
+ distinct_float_values = sorted([v.number_value for v in values])
343
+ if distinct_float_values:
344
+ result.domain_interval.min_value = distinct_float_values[0]
345
+ result.domain_interval.max_value = distinct_float_values[-1]
346
+ result.differs = len(set(distinct_float_values)) > 1
347
+
348
+ return result
349
+
350
+ def _experiment_from_data_provider_hparams(
351
+ self,
352
+ ctx,
353
+ experiment_id,
354
+ include_metrics,
355
+ data_provider_hparams,
356
+ ):
357
+ """Returns an experiment protobuffer based on data provider hparams.
358
+
359
+ Args:
360
+ experiment_id: String, from `plugin_util.experiment_id`.
361
+ include_metrics: Whether to determine metrics_infos and include them
362
+ in the result.
363
+ data_provider_hparams: The output from an hparams_from_data_provider()
364
+ call, corresponding to DataProvider.list_hyperparameters().
365
+ A provider.ListHyperparametersResult.
366
+
367
+ Returns:
368
+ The experiment proto. If there are no hyperparameters in the input,
369
+ returns None.
370
+ """
371
+ if isinstance(data_provider_hparams, list):
372
+ # TODO: Support old return value of Collection[provider.Hyperparameters]
373
+ # until all internal implementations of DataProvider can be
374
+ # migrated to use new return value of provider.ListHyperparametersResult.
375
+ hyperparameters = data_provider_hparams
376
+ session_groups = []
377
+ else:
378
+ # Is instance of provider.ListHyperparametersResult
379
+ hyperparameters = data_provider_hparams.hyperparameters
380
+ session_groups = data_provider_hparams.session_groups
381
+
382
+ hparam_infos = [
383
+ self._convert_data_provider_hparam(dp_hparam)
384
+ for dp_hparam in hyperparameters
385
+ ]
386
+ metric_infos = (
387
+ self.compute_metric_infos_from_data_provider_session_groups(
388
+ ctx, experiment_id, session_groups
389
+ )
390
+ if include_metrics
391
+ else []
392
+ )
393
+ return api_pb2.Experiment(
394
+ hparam_infos=hparam_infos, metric_infos=metric_infos
395
+ )
396
+
397
+ def _convert_data_provider_hparam(self, dp_hparam):
398
+ """Builds an HParamInfo message from data provider Hyperparameter.
399
+
400
+ Args:
401
+ dp_hparam: The provider.Hyperparameter returned by the call to
402
+ provider.DataProvider.list_hyperparameters().
403
+
404
+ Returns:
405
+ An HParamInfo to include in the Experiment.
406
+ """
407
+ hparam_info = api_pb2.HParamInfo(
408
+ name=dp_hparam.hyperparameter_name,
409
+ display_name=dp_hparam.hyperparameter_display_name,
410
+ differs=dp_hparam.differs,
411
+ )
412
+ if dp_hparam.domain_type == provider.HyperparameterDomainType.INTERVAL:
413
+ hparam_info.type = api_pb2.DATA_TYPE_FLOAT64
414
+ dp_hparam_min, dp_hparam_max = dp_hparam.domain
415
+ hparam_info.domain_interval.min_value = dp_hparam_min
416
+ hparam_info.domain_interval.max_value = dp_hparam_max
417
+ elif dp_hparam.domain_type in _DISCRETE_DOMAIN_TYPE_TO_DATA_TYPE.keys():
418
+ hparam_info.type = _DISCRETE_DOMAIN_TYPE_TO_DATA_TYPE.get(
419
+ dp_hparam.domain_type
420
+ )
421
+ hparam_info.domain_discrete.extend(dp_hparam.domain)
422
+ return hparam_info
423
+
424
+ def _compute_metric_infos_from_runs(
425
+ self, ctx, experiment_id, hparams_run_to_tag_to_content
426
+ ):
427
+ session_runs = set(
428
+ run
429
+ for run, tags in hparams_run_to_tag_to_content.items()
430
+ if metadata.SESSION_START_INFO_TAG in tags
431
+ )
432
+ return (
433
+ api_pb2.MetricInfo(name=api_pb2.MetricName(group=group, tag=tag))
434
+ for tag, group in self._compute_metric_names(
435
+ ctx, experiment_id, session_runs
436
+ )
437
+ )
438
+
439
+ def compute_metric_infos_from_data_provider_session_groups(
440
+ self, ctx, experiment_id, session_groups
441
+ ):
442
+ session_runs = set(
443
+ generate_data_provider_session_name(s)
444
+ for sg in session_groups
445
+ for s in sg.sessions
446
+ )
447
+ return [
448
+ api_pb2.MetricInfo(name=api_pb2.MetricName(group=group, tag=tag))
449
+ for tag, group in self._compute_metric_names(
450
+ ctx, experiment_id, session_runs
451
+ )
452
+ ]
453
+
454
+ def _compute_metric_names(self, ctx, experiment_id, session_runs):
455
+ """Computes the list of metric names from all the scalar (run, tag)
456
+ pairs.
457
+
458
+ The return value is a list of (tag, group) pairs representing the metric
459
+ names. The list is sorted in Python tuple-order (lexicographical).
460
+
461
+ For example, if the scalar (run, tag) pairs are:
462
+ ("exp/session1", "loss")
463
+ ("exp/session2", "loss")
464
+ ("exp/session2/eval", "loss")
465
+ ("exp/session2/validation", "accuracy")
466
+ ("exp/no-session", "loss_2"),
467
+ and the runs corresponding to sessions are "exp/session1", "exp/session2",
468
+ this method will return [("loss", ""), ("loss", "/eval"), ("accuracy",
469
+ "/validation")]
470
+
471
+ More precisely, each scalar (run, tag) pair is converted to a (tag, group)
472
+ metric name, where group is the suffix of run formed by removing the
473
+ longest prefix which is a session run. If no session run is a prefix of
474
+ 'run', the pair is skipped.
475
+
476
+ Returns:
477
+ A python list containing pairs. Each pair is a (tag, group) pair
478
+ representing a metric name used in some session.
479
+ """
480
+ metric_names_set = set()
481
+ scalars_run_to_tag_to_content = self.scalars_metadata(
482
+ ctx, experiment_id
483
+ )
484
+ for run, tags in scalars_run_to_tag_to_content.items():
485
+ session = _find_longest_parent_path(session_runs, run)
486
+ if session is None:
487
+ continue
488
+ group = os.path.relpath(run, session)
489
+ # relpath() returns "." for the 'session' directory, we use an empty
490
+ # string, unless the run name actually ends with ".".
491
+ if group == "." and not run.endswith("."):
492
+ group = ""
493
+ metric_names_set.update((tag, group) for tag in tags)
494
+ metric_names_list = list(metric_names_set)
495
+ # Sort metrics for determinism.
496
+ metric_names_list.sort()
497
+ return metric_names_list
498
+
499
+
500
+ def generate_data_provider_session_name(session):
501
+ """Generates a name from a HyperparameterSesssionRun.
502
+
503
+ If the HyperparameterSessionRun contains no experiment or run information
504
+ then the name is set to the original experiment_id.
505
+ """
506
+ if not session.experiment_id and not session.run:
507
+ return ""
508
+ elif not session.experiment_id:
509
+ return session.run
510
+ elif not session.run:
511
+ return session.experiment_id
512
+ else:
513
+ return f"{session.experiment_id}/{session.run}"
514
+
515
+
516
+ def _find_longest_parent_path(path_set, path):
517
+ """Finds the longest "parent-path" of 'path' in 'path_set'.
518
+
519
+ This function takes and returns "path-like" strings which are strings
520
+ made of strings separated by os.sep. No file access is performed here, so
521
+ these strings need not correspond to actual files in some file-system..
522
+ This function returns the longest ancestor path
523
+ For example, for path_set=["/foo/bar", "/foo", "/bar/foo"] and
524
+ path="/foo/bar/sub_dir", returns "/foo/bar".
525
+
526
+ Args:
527
+ path_set: set of path-like strings -- e.g. a list of strings separated by
528
+ os.sep. No actual disk-access is performed here, so these need not
529
+ correspond to actual files.
530
+ path: a path-like string.
531
+
532
+ Returns:
533
+ The element in path_set which is the longest parent directory of 'path'.
534
+ """
535
+ # This could likely be more efficiently implemented with a trie
536
+ # data-structure, but we don't want to add an extra dependency for that.
537
+ while path not in path_set:
538
+ if not path:
539
+ return None
540
+ path = os.path.dirname(path)
541
+ return path
542
+
543
+
544
+ def _can_be_converted_to_string(value):
545
+ if not _protobuf_value_type(value):
546
+ return False
547
+ return json_format_compat.is_serializable_value(value)
548
+
549
+
550
+ def _protobuf_value_type(value):
551
+ """Returns the type of the google.protobuf.Value message as an
552
+ api.DataType.
553
+
554
+ Returns None if the type of 'value' is not one of the types supported in
555
+ api_pb2.DataType.
556
+
557
+ Args:
558
+ value: google.protobuf.Value message.
559
+ """
560
+ if value.HasField("number_value"):
561
+ return api_pb2.DATA_TYPE_FLOAT64
562
+ if value.HasField("string_value"):
563
+ return api_pb2.DATA_TYPE_STRING
564
+ if value.HasField("bool_value"):
565
+ return api_pb2.DATA_TYPE_BOOL
566
+ return None
567
+
568
+
569
+ def _protobuf_value_to_string(value):
570
+ """Returns a string representation of given google.protobuf.Value message.
571
+
572
+ Args:
573
+ value: google.protobuf.Value message. Assumed to be of type 'number',
574
+ 'string' or 'bool'.
575
+ """
576
+ value_in_json = json_format.MessageToJson(value)
577
+ if value.HasField("string_value"):
578
+ # Remove the quotations.
579
+ return value_in_json[1:-1]
580
+ return value_in_json
581
+
582
+
583
+ def _sort_and_reduce_to_hparams_limit(experiment, hparams_limit=None):
584
+ """Sorts and applies limit to the hparams in the given experiment proto.
585
+
586
+ Args:
587
+ experiment: An api_pb2.Experiment proto, which will be modified in place.
588
+ hparams_limit: Optional number of hyperparameter metadata to include in the
589
+ result. If unset or zero, no limit will be applied.
590
+
591
+ Returns:
592
+ None. `experiment` proto will be modified in place.
593
+ """
594
+ if not hparams_limit:
595
+ # If limit is unset or zero, returns all hparams.
596
+ hparams_limit = len(experiment.hparam_infos)
597
+
598
+ # Prioritizes returning HParamInfo protos with `differed` values.
599
+ # Sorts by `differs` (True first), then by name.
600
+ limited_hparam_infos = sorted(
601
+ experiment.hparam_infos,
602
+ key=lambda hparam_info: (not hparam_info.differs, hparam_info.name),
603
+ )[:hparams_limit]
604
+
605
+ experiment.ClearField("hparam_infos")
606
+ experiment.hparam_infos.extend(limited_hparam_infos)