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

[Feature Requests] Support configuration aliases / names that persist through code refactoring #27

Closed
yzhuang opened this issue Sep 1, 2019 · 4 comments

Comments

@yzhuang
Copy link

yzhuang commented Sep 1, 2019

Hello project maintainers,

We started evaluating gin-config for wider use in some of our projects. One thing I noticed is that gin config files are tied to symbol names in code (i.e. class names and function names).

In repositories with high change velocity, refactoring class and function names tend to break their associated config files. Could you provide a functionality to specify stable aliases for configuration names? For example, like this:

@gin.configurable(alias=model_training_config)
def train_model(learning_rate):
  pass
model_training_config.learning_rate=0.001

The goal is that when we refactor and change the function name, it's associated configuration should not break. This functionality is usually available in dependency injection frameworks in general.

Thank you very much for your time.

-Yi

@jackd
Copy link

jackd commented Sep 2, 2019

I'm not a project maintainer, but if I understand your request correctly it's already supported:

import gin


@gin.configurable('model_training_config')
def train_model(learning_rate):
  print('learning_rate = {}'.format(learning_rate))


config = 'model_training_config.learning_rate=0.001'

gin.parse_config(config)
train_model()

@yzhuang
Copy link
Author

yzhuang commented Sep 2, 2019

Somehow we failed to discover this. Thank you very much for spending time to reply.
Closing the request since the question is answered.

@yzhuang yzhuang closed this as completed Sep 2, 2019
@sguada
Copy link
Collaborator

sguada commented Sep 2, 2019

Thanks @jackd for providing the answer. Yeah you can name configurables and also specify their module, so you can even group configurables across files. Example

@gin.configurable('model_training', module='config')
def train_model(learning_rate):
  print('learning_rate = {}'.format(learning_rate))

@gin.configurable('model_testing', module='config')
def test_model(epochs=1):
  ...

config = '''
    config.model_training.learning_rate=0.001
    config.model_testing.epochs=2
'''

@yzhuang
Copy link
Author

yzhuang commented Sep 2, 2019

Thanks for the above example @sguada , it was very helpful.

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

3 participants