Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
phrasenmaeher opened this issue Oct 13, 2021 · 1 comment
Open

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

phrasenmaeher opened this issue Oct 13, 2021 · 1 comment

Comments

@phrasenmaeher
Copy link

phrasenmaeher commented Oct 13, 2021

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.

@autolisis
Copy link

Thanks, I was looking for exactly this, and I believe that this should be part of gin.utils or something. Especially for keeping track of different experiment runs, it's much more useful to have a dict as opposed to a pre-generated string with newlines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants