Skip to content

Commit

Permalink
Fix handling of empty parameters in parameter_overview.
Browse files Browse the repository at this point in the history
The test should not be on whether it is an empty dict, but whether after flattening it is empty.
Without this fix the added test fails with:

```
  File "../py/clu/parameter_overview.py", line 156, in _get_parameter_rows
    names, values = map(list, tuple(zip(*sorted(params.items()))))
    ^^^^^^^^^^^^^
ValueError: not enough values to unpack (expected 2, got 0)
```
PiperOrigin-RevId: 715237667
  • Loading branch information
andresusanopinto authored and copybara-github committed Jan 14, 2025
1 parent 307b0bc commit c139e6a
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clu/parameter_overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ def _get_parameter_rows(
f"Expected `params` to be a dictionary but got {type(params)}"
)

params = flatten_dict(params)
if params:
params = flatten_dict(params)
names, values = map(list, tuple(zip(*sorted(params.items()))))
else:
names, values = [], []
Expand Down
2 changes: 2 additions & 0 deletions clu/parameter_overview_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def test_count_parameters(self):
def test_get_parameter_overview_empty(self):
self.assertEqual(EMPTY_PARAMETER_OVERVIEW,
parameter_overview.get_parameter_overview({}))
self.assertEqual(EMPTY_PARAMETER_OVERVIEW,
parameter_overview.get_parameter_overview({"a": {}}))

def test_get_parameter_overview(self):
rng = jax.random.PRNGKey(42)
Expand Down

0 comments on commit c139e6a

Please sign in to comment.