google / gin-config

Gin provides a lightweight configuration framework for Python
Apache License 2.0
2.05k stars 120 forks source link

Instead of files, programmatically create gin config #20

Open bayerj opened 5 years ago

bayerj commented 5 years ago

In my use cases, I rarely set hyper parameters by hand. Instead I have an external logic that generates them (e.g. random search). Now, using gin it seems I would have to create config files programmatically, e.g. through templates.

That feels "wrong", even though I could go that route: have a process that creates config files from templates (which would be programmatically generated by inspecting the respective module using gin), then start the processes in a second go.

Nevertheless, I was wondering if I am missing an obvious path to get the same out of it. Soemthing like setting the configuration through pure python, instead of going through gin's own format, would do the job.

sguada commented 5 years ago

Currently, you can assign values to parameters in code using gin.bind_parameter

value = ...
gin.bind_parameter('my_function.parameter', value)

We are thinking in being able to create configurations as Python objects, but not ETA at the moment.

bionicles commented 5 years ago

@bayerj @sguada bump, I'd love to use gin to configure Optuna or Keras-Tuner searches; i have a bunch of bricks each with parameters pulled to the top of the file (MIN_STACKS = 2 ) for example ... i guess i could make these into kwargs, configure those with gin, then add an AI.pull method to the Agent class which asks Optuna for a parameter value given a range. Then instead of hunting through 50 little files for config, i can configure search spaces in one big file (hopefully not TOO big)

one issue is, some of the config stuff ought to really be itself pulled from the search, as justin rightly points out. might be possible to make the main file for a program generate a gin config just by writing lines.

For example, Dense blocks concat their outputs, which impacts the size of the code, which would be good to put in other parts of the config ... D_CODE = 3 + DenseBlock.layers * DenseBlock.units