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 suggestion: defining arbitrary functions only using gin #179

Open
OhadRubin opened this issue Dec 17, 2022 · 0 comments
Open

Feature suggestion: defining arbitrary functions only using gin #179

OhadRubin opened this issue Dec 17, 2022 · 0 comments

Comments

@OhadRubin
Copy link

This may be kinda hacky, but what if I wanted to use some function and only define it via gin file,
so this is the solution I came up with:
Function:

#utils.py
@gin.configurable
def arbitrary_func(module_name, func_name, kwargs):
  """Returns a function from a module."""
  module = importlib.import_module(module_name)
  func = getattr(module, func_name)
  return func(**kwargs)

Gin file:

import utils
lr_schedule/utils.arbitrary_func:
    module_name = "optax"
    func_name = "linear_schedule"
    kwargs = { "init_value":0.005, "end_value":0.1, "transition_steps": 10000 }

optimizer_config.AdamConfig:
    lr_schedule = @lr_schedule/utils.arbitrary_func()

let me know what you think.

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

1 participant