From cc6e294183d61e937bb44dde148808a6b91d8a00 Mon Sep 17 00:00:00 2001 From: Yating Date: Mon, 18 Sep 2023 13:00:48 -0400 Subject: [PATCH] Hparams: fix the bug where the last hparam was discarded when there is no limit (#6584) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bug fixed by this PR: Currently when there is no limit, `_sort_and_reduce_to_hparams_limit()` truncates the last value. Corresponding unit test is wrong as well. 🤦 Googlers, see internal test at: cl/563163418 #hparams --- tensorboard/plugins/hparams/backend_context.py | 3 ++- tensorboard/plugins/hparams/backend_context_test.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/tensorboard/plugins/hparams/backend_context.py b/tensorboard/plugins/hparams/backend_context.py index f3e147f529..ff248d4c5d 100644 --- a/tensorboard/plugins/hparams/backend_context.py +++ b/tensorboard/plugins/hparams/backend_context.py @@ -599,7 +599,8 @@ def _sort_and_reduce_to_hparams_limit(experiment, hparams_limit=None): None. `experiment` proto will be modified in place. """ if not hparams_limit: - hparams_limit = -1 + # If limit is unset or zero, returns all hparams. + hparams_limit = len(experiment.hparam_infos) # Prioritizes returning HParamInfo protos with `differed` values. limited_hparam_infos = sorted( diff --git a/tensorboard/plugins/hparams/backend_context_test.py b/tensorboard/plugins/hparams/backend_context_test.py index eb82bd8d24..2f36c4a6d9 100644 --- a/tensorboard/plugins/hparams/backend_context_test.py +++ b/tensorboard/plugins/hparams/backend_context_test.py @@ -1174,6 +1174,11 @@ def test_experiment_from_tags_sorts_differed_hparams_first(self): type: DATA_TYPE_FLOAT64 differs: false } + hparam_infos: { + name: 'use_batch_norm' + type: DATA_TYPE_BOOL + differs: false + } """ actual_exp = self._experiment_from_metadata( include_metrics=False, hparams_limit=None