Skip to content

Commit d335d17

Browse files
nfeltcaisq
authored andcommitted
Migrate _parse_samples_per_plugin() into flag definition itself (#3637)
* migrate _parse_samples_per_plugin() into flag definition itself * CR: rename _parse_dict to _parse_samples_per_plugin
1 parent 84eb921 commit d335d17

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

tensorboard/backend/application.py

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,16 +96,6 @@
9696
logger = tb_logging.get_logger()
9797

9898

99-
def _parse_samples_per_plugin(flags):
100-
result = {}
101-
if not flags or not flags.samples_per_plugin:
102-
return result
103-
for token in flags.samples_per_plugin.split(","):
104-
k, v = token.strip().split("=")
105-
result[k] = int(v)
106-
return result
107-
108-
10999
def _apply_tensor_size_guidance(sampling_hints):
110100
"""Apply user per-summary size guidance overrides."""
111101
tensor_size_guidance = dict(DEFAULT_TENSOR_SIZE_GUIDANCE)
@@ -131,7 +121,7 @@ def standard_tensorboard_wsgi(flags, plugin_loaders, assets_zip_provider):
131121
multiplexer = None
132122
reload_interval = flags.reload_interval
133123
# Regular logdir loading mode.
134-
sampling_hints = _parse_samples_per_plugin(flags)
124+
sampling_hints = flags.samples_per_plugin
135125
multiplexer = event_multiplexer.EventMultiplexer(
136126
size_guidance=DEFAULT_SIZE_GUIDANCE,
137127
tensor_size_guidance=_apply_tensor_size_guidance(sampling_hints),
@@ -208,7 +198,7 @@ def TensorBoardWSGIApp(
208198
multiplexer=deprecated_multiplexer,
209199
assets_zip_provider=assets_zip_provider,
210200
plugin_name_to_instance=plugin_name_to_instance,
211-
sampling_hints=_parse_samples_per_plugin(flags),
201+
sampling_hints=flags.samples_per_plugin,
212202
window_title=flags.window_title,
213203
)
214204
tbplugins = []

tensorboard/backend/application_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def __init__(
5858
logdir_spec="",
5959
purge_orphaned_data=True,
6060
reload_interval=60,
61-
samples_per_plugin="",
61+
samples_per_plugin=None,
6262
max_reload_threads=1,
6363
reload_task="auto",
6464
window_title="",
@@ -71,7 +71,7 @@ def __init__(
7171
self.logdir_spec = logdir_spec
7272
self.purge_orphaned_data = purge_orphaned_data
7373
self.reload_interval = reload_interval
74-
self.samples_per_plugin = samples_per_plugin
74+
self.samples_per_plugin = samples_per_plugin or {}
7575
self.max_reload_threads = max_reload_threads
7676
self.reload_task = reload_task
7777
self.window_title = window_title

tensorboard/plugins/core/core_plugin.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ def define_flags(self, parser):
514514

515515
parser.add_argument(
516516
"--samples_per_plugin",
517-
type=str,
517+
type=_parse_samples_per_plugin,
518518
default="",
519519
help="""\
520520
An optional comma separated list of plugin_name=num_samples pairs to
@@ -576,3 +576,13 @@ def _gzip(bytestring):
576576
with gzip.GzipFile(fileobj=out, mode="wb", compresslevel=3, mtime=0) as f:
577577
f.write(bytestring)
578578
return out.getvalue()
579+
580+
581+
def _parse_samples_per_plugin(value):
582+
"""Parses `value` as a string-to-int dict in the form `foo=12,bar=34`."""
583+
result = {}
584+
for token in value.split(","):
585+
if token:
586+
k, v = token.strip().split("=")
587+
result[k] = int(v)
588+
return result

0 commit comments

Comments
 (0)