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,597 @@
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
+ """Experimental public APIs for the HParams plugin.
16
+
17
+ These are porcelain on top of `api_pb2` (`api.proto`) and `summary.py`.
18
+ """
19
+
20
+ import abc
21
+ import hashlib
22
+ import json
23
+ import random
24
+ import time
25
+
26
+ import numpy as np
27
+
28
+ from tensorbored.compat import tf2 as tf
29
+ from tensorbored.compat.proto import summary_pb2
30
+ from tensorbored.plugins.hparams import api_pb2
31
+ from tensorbored.plugins.hparams import metadata
32
+ from tensorbored.plugins.hparams import plugin_data_pb2
33
+
34
+
35
+ def hparams(hparams, trial_id=None, start_time_secs=None):
36
+ # NOTE: Keep docs in sync with `hparams_pb` below.
37
+ """Write hyperparameter values for a single trial.
38
+
39
+ Args:
40
+ hparams: A `dict` mapping hyperparameters to the values used in this
41
+ trial. Keys should be the names of `HParam` objects used in an
42
+ experiment, or the `HParam` objects themselves. Values should be
43
+ Python `bool`, `int`, `float`, or `string` values, depending on
44
+ the type of the hyperparameter. The corresponding numpy types,
45
+ like `np.float32`, are also permitted.
46
+ trial_id: An optional `str` ID for the set of hyperparameter values
47
+ used in this trial. Defaults to a hash of the hyperparameters.
48
+ start_time_secs: The time that this trial started training, as
49
+ seconds since epoch. Defaults to the current time.
50
+
51
+ Returns:
52
+ A tensor whose value is `True` on success, or `False` if no summary
53
+ was written because no default summary writer was available.
54
+ """
55
+ pb = hparams_pb(
56
+ hparams=hparams,
57
+ trial_id=trial_id,
58
+ start_time_secs=start_time_secs,
59
+ )
60
+ return _write_summary("hparams", pb)
61
+
62
+
63
+ def hparams_pb(hparams, trial_id=None, start_time_secs=None):
64
+ # NOTE: Keep docs in sync with `hparams` above.
65
+ """Create a summary encoding hyperparameter values for a single trial.
66
+
67
+ Args:
68
+ hparams: A `dict` mapping hyperparameters to the values used in this
69
+ trial. Keys should be the names of `HParam` objects used in an
70
+ experiment, or the `HParam` objects themselves. Values should be
71
+ Python `bool`, `int`, `float`, or `string` values, depending on
72
+ the type of the hyperparameter.
73
+ trial_id: An optional `str` ID for the set of hyperparameter values
74
+ used in this trial. Defaults to a hash of the hyperparameters.
75
+ start_time_secs: The time that this trial started training, as
76
+ seconds since epoch. Defaults to the current time.
77
+
78
+ Returns:
79
+ A TensorBoard `summary_pb2.Summary` message.
80
+ """
81
+ if start_time_secs is None:
82
+ start_time_secs = time.time()
83
+ hparams = _normalize_hparams(hparams)
84
+ group_name = _derive_session_group_name(trial_id, hparams)
85
+
86
+ session_start_info = plugin_data_pb2.SessionStartInfo(
87
+ group_name=group_name,
88
+ start_time_secs=start_time_secs,
89
+ )
90
+ for hp_name in sorted(hparams):
91
+ hp_value = hparams[hp_name]
92
+ if isinstance(hp_value, bool):
93
+ session_start_info.hparams[hp_name].bool_value = hp_value
94
+ elif isinstance(hp_value, (float, int)):
95
+ session_start_info.hparams[hp_name].number_value = hp_value
96
+ elif isinstance(hp_value, str):
97
+ session_start_info.hparams[hp_name].string_value = hp_value
98
+ else:
99
+ raise TypeError(
100
+ "hparams[%r] = %r, of unsupported type %r"
101
+ % (hp_name, hp_value, type(hp_value))
102
+ )
103
+
104
+ return _summary_pb(
105
+ metadata.SESSION_START_INFO_TAG,
106
+ plugin_data_pb2.HParamsPluginData(
107
+ session_start_info=session_start_info
108
+ ),
109
+ )
110
+
111
+
112
+ def hparams_config(hparams, metrics, time_created_secs=None):
113
+ # NOTE: Keep docs in sync with `hparams_config_pb` below.
114
+ """Write a top-level experiment configuration.
115
+
116
+ This configuration describes the hyperparameters and metrics that will
117
+ be tracked in the experiment, but does not record any actual values of
118
+ those hyperparameters and metrics. It can be created before any models
119
+ are actually trained.
120
+
121
+ Args:
122
+ hparams: A list of `HParam` values.
123
+ metrics: A list of `Metric` values.
124
+ time_created_secs: The time that this experiment was created, as
125
+ seconds since epoch. Defaults to the current time.
126
+
127
+ Returns:
128
+ A tensor whose value is `True` on success, or `False` if no summary
129
+ was written because no default summary writer was available.
130
+ """
131
+ pb = hparams_config_pb(
132
+ hparams=hparams,
133
+ metrics=metrics,
134
+ time_created_secs=time_created_secs,
135
+ )
136
+ return _write_summary("hparams_config", pb)
137
+
138
+
139
+ def hparams_config_pb(hparams, metrics, time_created_secs=None):
140
+ # NOTE: Keep docs in sync with `hparams_config` above.
141
+ """Create a top-level experiment configuration.
142
+
143
+ This configuration describes the hyperparameters and metrics that will
144
+ be tracked in the experiment, but does not record any actual values of
145
+ those hyperparameters and metrics. It can be created before any models
146
+ are actually trained.
147
+
148
+ Args:
149
+ hparams: A list of `HParam` values.
150
+ metrics: A list of `Metric` values.
151
+ time_created_secs: The time that this experiment was created, as
152
+ seconds since epoch. Defaults to the current time.
153
+
154
+ Returns:
155
+ A TensorBoard `summary_pb2.Summary` message.
156
+ """
157
+ hparam_infos = []
158
+ for hparam in hparams:
159
+ info = api_pb2.HParamInfo(
160
+ name=hparam.name,
161
+ description=hparam.description,
162
+ display_name=hparam.display_name,
163
+ )
164
+ domain = hparam.domain
165
+ if domain is not None:
166
+ domain.update_hparam_info(info)
167
+ hparam_infos.append(info)
168
+ metric_infos = [metric.as_proto() for metric in metrics]
169
+ experiment = api_pb2.Experiment(
170
+ hparam_infos=hparam_infos,
171
+ metric_infos=metric_infos,
172
+ time_created_secs=time_created_secs,
173
+ )
174
+ return _summary_pb(
175
+ metadata.EXPERIMENT_TAG,
176
+ plugin_data_pb2.HParamsPluginData(experiment=experiment),
177
+ )
178
+
179
+
180
+ def _normalize_hparams(hparams):
181
+ """Normalize a dict keyed by `HParam`s and/or raw strings.
182
+
183
+ Args:
184
+ hparams: A `dict` whose keys are `HParam` objects and/or strings
185
+ representing hyperparameter names, and whose values are
186
+ hyperparameter values. No two keys may have the same name.
187
+
188
+ Returns:
189
+ A `dict` whose keys are hyperparameter names (as strings) and whose
190
+ values are the corresponding hyperparameter values, after numpy
191
+ normalization (see `_normalize_numpy_value`).
192
+
193
+ Raises:
194
+ ValueError: If two entries in `hparams` share the same
195
+ hyperparameter name.
196
+ """
197
+ result = {}
198
+ for k, v in hparams.items():
199
+ if isinstance(k, HParam):
200
+ k = k.name
201
+ if k in result:
202
+ raise ValueError("multiple values specified for hparam %r" % (k,))
203
+ result[k] = _normalize_numpy_value(v)
204
+ return result
205
+
206
+
207
+ def _normalize_numpy_value(value):
208
+ """Convert a Python or Numpy scalar to a Python scalar.
209
+
210
+ For instance, `3.0`, `np.float32(3.0)`, and `np.float64(3.0)` all
211
+ map to `3.0`.
212
+
213
+ Args:
214
+ value: A Python scalar (`int`, `float`, `str`, or `bool`) or
215
+ rank-0 `numpy` equivalent (e.g., `np.int64`, `np.float32`).
216
+
217
+ Returns:
218
+ A Python scalar equivalent to `value`.
219
+ """
220
+ if isinstance(value, np.generic):
221
+ return value.item()
222
+ else:
223
+ return value
224
+
225
+
226
+ def _derive_session_group_name(trial_id, hparams):
227
+ if trial_id is not None:
228
+ if not isinstance(trial_id, str):
229
+ raise TypeError(
230
+ "`trial_id` should be a `str`, but got: %r" % (trial_id,)
231
+ )
232
+ return trial_id
233
+ # Use `json.dumps` rather than `str` to ensure invariance under string
234
+ # type (incl. across Python versions) and dict iteration order.
235
+ jparams = json.dumps(hparams, sort_keys=True, separators=(",", ":"))
236
+ return hashlib.sha256(jparams.encode("utf-8")).hexdigest()
237
+
238
+
239
+ def _write_summary(name, pb):
240
+ """Write a summary, returning the writing op.
241
+
242
+ Args:
243
+ name: As passed to `summary_scope`.
244
+ pb: A `summary_pb2.Summary` message.
245
+
246
+ Returns:
247
+ A tensor whose value is `True` on success, or `False` if no summary
248
+ was written because no default summary writer was available.
249
+ """
250
+ raw_pb = pb.SerializeToString()
251
+ summary_scope = (
252
+ getattr(tf.summary.experimental, "summary_scope", None)
253
+ or tf.summary.summary_scope
254
+ )
255
+ with summary_scope(name):
256
+ return tf.summary.experimental.write_raw_pb(raw_pb, step=0)
257
+
258
+
259
+ def _summary_pb(tag, hparams_plugin_data):
260
+ """Create a summary holding the given `HParamsPluginData` message.
261
+
262
+ Args:
263
+ tag: The `str` tag to use.
264
+ hparams_plugin_data: The `HParamsPluginData` message to use.
265
+
266
+ Returns:
267
+ A TensorBoard `summary_pb2.Summary` message.
268
+ """
269
+ summary = summary_pb2.Summary()
270
+ summary_metadata = metadata.create_summary_metadata(hparams_plugin_data)
271
+ value = summary.value.add(
272
+ tag=tag, metadata=summary_metadata, tensor=metadata.NULL_TENSOR
273
+ )
274
+ return summary
275
+
276
+
277
+ class HParam:
278
+ """A hyperparameter in an experiment.
279
+
280
+ This class describes a hyperparameter in the abstract. It ranges
281
+ over a domain of values, but is not bound to any particular value.
282
+ """
283
+
284
+ def __init__(self, name, domain=None, display_name=None, description=None):
285
+ """Create a hyperparameter object.
286
+
287
+ Args:
288
+ name: A string ID for this hyperparameter, which should be unique
289
+ within an experiment.
290
+ domain: An optional `Domain` object describing the values that
291
+ this hyperparameter can take on.
292
+ display_name: An optional human-readable display name (`str`).
293
+ description: An optional Markdown string describing this
294
+ hyperparameter.
295
+
296
+ Raises:
297
+ ValueError: If `domain` is not a `Domain`.
298
+ """
299
+ self._name = name
300
+ self._domain = domain
301
+ self._display_name = display_name
302
+ self._description = description
303
+ if not isinstance(self._domain, (Domain, type(None))):
304
+ raise ValueError("not a domain: %r" % (self._domain,))
305
+
306
+ def __str__(self):
307
+ return "<HParam %r: %s>" % (self._name, self._domain)
308
+
309
+ def __repr__(self):
310
+ fields = [
311
+ ("name", self._name),
312
+ ("domain", self._domain),
313
+ ("display_name", self._display_name),
314
+ ("description", self._description),
315
+ ]
316
+ fields_string = ", ".join("%s=%r" % (k, v) for (k, v) in fields)
317
+ return "HParam(%s)" % fields_string
318
+
319
+ @property
320
+ def name(self):
321
+ return self._name
322
+
323
+ @property
324
+ def domain(self):
325
+ return self._domain
326
+
327
+ @property
328
+ def display_name(self):
329
+ return self._display_name
330
+
331
+ @property
332
+ def description(self):
333
+ return self._description
334
+
335
+
336
+ class Domain(metaclass=abc.ABCMeta):
337
+ """The domain of a hyperparameter.
338
+
339
+ Domains are restricted to values of the simple types `float`, `int`,
340
+ `str`, and `bool`.
341
+ """
342
+
343
+ @abc.abstractproperty
344
+ def dtype(self):
345
+ """Data type of this domain: `float`, `int`, `str`, or `bool`."""
346
+ pass
347
+
348
+ @abc.abstractmethod
349
+ def sample_uniform(self, rng=random):
350
+ """Sample a value from this domain uniformly at random.
351
+
352
+ Args:
353
+ rng: A `random.Random` interface; defaults to the `random` module
354
+ itself.
355
+
356
+ Raises:
357
+ IndexError: If the domain is empty.
358
+ """
359
+ pass
360
+
361
+ @abc.abstractmethod
362
+ def update_hparam_info(self, hparam_info):
363
+ """Update an `HParamInfo` proto to include this domain.
364
+
365
+ This should update the `type` field on the proto and exactly one of
366
+ the `domain` variants on the proto.
367
+
368
+ Args:
369
+ hparam_info: An `api_pb2.HParamInfo` proto to modify.
370
+ """
371
+ pass
372
+
373
+
374
+ class IntInterval(Domain):
375
+ """A domain that takes on all integer values in a closed interval."""
376
+
377
+ def __init__(self, min_value=None, max_value=None):
378
+ """Create an `IntInterval`.
379
+
380
+ Args:
381
+ min_value: The lower bound (inclusive) of the interval.
382
+ max_value: The upper bound (inclusive) of the interval.
383
+
384
+ Raises:
385
+ TypeError: If `min_value` or `max_value` is not an `int`.
386
+ ValueError: If `min_value > max_value`.
387
+ """
388
+ if not isinstance(min_value, int):
389
+ raise TypeError("min_value must be an int: %r" % (min_value,))
390
+ if not isinstance(max_value, int):
391
+ raise TypeError("max_value must be an int: %r" % (max_value,))
392
+ if min_value > max_value:
393
+ raise ValueError("%r > %r" % (min_value, max_value))
394
+ self._min_value = min_value
395
+ self._max_value = max_value
396
+
397
+ def __str__(self):
398
+ return "[%s, %s]" % (self._min_value, self._max_value)
399
+
400
+ def __repr__(self):
401
+ return "IntInterval(%r, %r)" % (self._min_value, self._max_value)
402
+
403
+ @property
404
+ def dtype(self):
405
+ return int
406
+
407
+ @property
408
+ def min_value(self):
409
+ return self._min_value
410
+
411
+ @property
412
+ def max_value(self):
413
+ return self._max_value
414
+
415
+ def sample_uniform(self, rng=random):
416
+ return rng.randint(self._min_value, self._max_value)
417
+
418
+ def update_hparam_info(self, hparam_info):
419
+ hparam_info.type = (
420
+ api_pb2.DATA_TYPE_FLOAT64
421
+ ) # TODO(#1998): Add int dtype.
422
+ hparam_info.domain_interval.min_value = self._min_value
423
+ hparam_info.domain_interval.max_value = self._max_value
424
+
425
+
426
+ class RealInterval(Domain):
427
+ """A domain that takes on all real values in a closed interval."""
428
+
429
+ def __init__(self, min_value=None, max_value=None):
430
+ """Create a `RealInterval`.
431
+
432
+ Args:
433
+ min_value: The lower bound (inclusive) of the interval.
434
+ max_value: The upper bound (inclusive) of the interval.
435
+
436
+ Raises:
437
+ TypeError: If `min_value` or `max_value` is not an `float`.
438
+ ValueError: If `min_value > max_value`.
439
+ """
440
+ if not isinstance(min_value, float):
441
+ raise TypeError("min_value must be a float: %r" % (min_value,))
442
+ if not isinstance(max_value, float):
443
+ raise TypeError("max_value must be a float: %r" % (max_value,))
444
+ if min_value > max_value:
445
+ raise ValueError("%r > %r" % (min_value, max_value))
446
+ self._min_value = min_value
447
+ self._max_value = max_value
448
+
449
+ def __str__(self):
450
+ return "[%s, %s]" % (self._min_value, self._max_value)
451
+
452
+ def __repr__(self):
453
+ return "RealInterval(%r, %r)" % (self._min_value, self._max_value)
454
+
455
+ @property
456
+ def dtype(self):
457
+ return float
458
+
459
+ @property
460
+ def min_value(self):
461
+ return self._min_value
462
+
463
+ @property
464
+ def max_value(self):
465
+ return self._max_value
466
+
467
+ def sample_uniform(self, rng=random):
468
+ return rng.uniform(self._min_value, self._max_value)
469
+
470
+ def update_hparam_info(self, hparam_info):
471
+ hparam_info.type = api_pb2.DATA_TYPE_FLOAT64
472
+ hparam_info.domain_interval.min_value = self._min_value
473
+ hparam_info.domain_interval.max_value = self._max_value
474
+
475
+
476
+ class Discrete(Domain):
477
+ """A domain that takes on a fixed set of values.
478
+
479
+ These values may be of any (single) domain type.
480
+ """
481
+
482
+ def __init__(self, values, dtype=None):
483
+ """Construct a discrete domain.
484
+
485
+ Args:
486
+ values: A iterable of the values in this domain.
487
+ dtype: The Python data type of values in this domain: one of
488
+ `int`, `float`, `bool`, or `str`. If `values` is non-empty,
489
+ `dtype` may be `None`, in which case it will be inferred as the
490
+ type of the first element of `values`.
491
+
492
+ Raises:
493
+ ValueError: If `values` is empty but no `dtype` is specified.
494
+ ValueError: If `dtype` or its inferred value is not `int`,
495
+ `float`, `bool`, or `str`.
496
+ TypeError: If an element of `values` is not an instance of
497
+ `dtype`.
498
+ """
499
+ self._values = list(values)
500
+ if dtype is None:
501
+ if self._values:
502
+ dtype = type(self._values[0])
503
+ else:
504
+ raise ValueError("Empty domain with no dtype specified")
505
+ if dtype not in (int, float, bool, str):
506
+ raise ValueError("Unknown dtype: %r" % (dtype,))
507
+ self._dtype = dtype
508
+ for value in self._values:
509
+ if not isinstance(value, self._dtype):
510
+ raise TypeError(
511
+ "dtype mismatch: not isinstance(%r, %s)"
512
+ % (value, self._dtype.__name__)
513
+ )
514
+ self._values.sort()
515
+
516
+ def __str__(self):
517
+ return "{%s}" % (", ".join(repr(x) for x in self._values))
518
+
519
+ def __repr__(self):
520
+ return "Discrete(%r)" % (self._values,)
521
+
522
+ @property
523
+ def dtype(self):
524
+ return self._dtype
525
+
526
+ @property
527
+ def values(self):
528
+ return list(self._values)
529
+
530
+ def sample_uniform(self, rng=random):
531
+ return rng.choice(self._values)
532
+
533
+ def update_hparam_info(self, hparam_info):
534
+ hparam_info.type = {
535
+ int: api_pb2.DATA_TYPE_FLOAT64, # TODO(#1998): Add int dtype.
536
+ float: api_pb2.DATA_TYPE_FLOAT64,
537
+ bool: api_pb2.DATA_TYPE_BOOL,
538
+ str: api_pb2.DATA_TYPE_STRING,
539
+ }[self._dtype]
540
+ hparam_info.ClearField("domain_discrete")
541
+ hparam_info.domain_discrete.extend(self._values)
542
+
543
+
544
+ class Metric:
545
+ """A metric in an experiment.
546
+
547
+ A metric is a real-valued function of a model. Each metric is
548
+ associated with a TensorBoard scalar summary, which logs the
549
+ metric's value as the model trains.
550
+ """
551
+
552
+ TRAINING = api_pb2.DATASET_TRAINING
553
+ VALIDATION = api_pb2.DATASET_VALIDATION
554
+
555
+ def __init__(
556
+ self,
557
+ tag,
558
+ group=None,
559
+ display_name=None,
560
+ description=None,
561
+ dataset_type=None,
562
+ ):
563
+ """
564
+
565
+ Args:
566
+ tag: The tag name of the scalar summary that corresponds to this
567
+ metric (as a `str`).
568
+ group: An optional string listing the subdirectory under the
569
+ session's log directory containing summaries for this metric.
570
+ For instance, if summaries for training runs are written to
571
+ events files in `ROOT_LOGDIR/SESSION_ID/train`, then `group`
572
+ should be `"train"`. Defaults to the empty string: i.e.,
573
+ summaries are expected to be written to the session logdir.
574
+ display_name: An optional human-readable display name.
575
+ description: An optional Markdown string with a human-readable
576
+ description of this metric, to appear in TensorBoard.
577
+ dataset_type: Either `Metric.TRAINING` or `Metric.VALIDATION`, or
578
+ `None`.
579
+ """
580
+ self._tag = tag
581
+ self._group = group
582
+ self._display_name = display_name
583
+ self._description = description
584
+ self._dataset_type = dataset_type
585
+ if self._dataset_type not in (None, Metric.TRAINING, Metric.VALIDATION):
586
+ raise ValueError("invalid dataset type: %r" % (self._dataset_type,))
587
+
588
+ def as_proto(self):
589
+ return api_pb2.MetricInfo(
590
+ name=api_pb2.MetricName(
591
+ group=self._group,
592
+ tag=self._tag,
593
+ ),
594
+ display_name=self._display_name,
595
+ description=self._description,
596
+ dataset_type=self._dataset_type,
597
+ )
File without changes