google / google/gin-config

Option to print gin dictionary (for, e.g., logging)

Open
#154 2 comments 5 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
2.2k
Forks
122
Avg merge
5d 10h
Merged PRs (30d)
2

Description

We can use the `gin.operative_config_str()`, which prints a useful overview. However, for logging the saved parameters, some people (me included) like to query the internal dictionary. We can access it with `gin.config._OPERATIVE_CONFIG` (recommended) or `gin.config._CONFIG` (not recommended, also includes unused parameters). However, this requires additional parsing.

For this, I came up with the following code:
```
def gin_config_to_readable_dictionary(gin_config: dict):
"""
Parses the gin configuration to a dictionary. Useful for logging to e.g. W&B
:param gin_config: the gin's config dictionary. Can be obtained by gin.config._OPERATIVE_CONFIG
:return: the parsed (mainly: cleaned) dictionary
"""
data = {}
for key in gin_config.keys():
name = key[1].split(".")[1]
values = gin_config[key]
for k, v in values.items():
data[".".join([name, k])] = v

return data
```
An example output is given below:

```
{'create_argument_parser.epochs': 10,
'create_argument_parser.batch_size': 128,
'create_argument_parser.model_number': -1}
```

The naming follows the way parameter values are stored in a `config.gin` file: the decorated class/function name, followed by the parameter's name.

This is not a critical thing, but it might be useful as an enhancement.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.