google / google/gin-config

Feature suggestion: defining arbitrary functions only using gin

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

Description

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
#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:
```lr_schedule.gin
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.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the proposed utils.py helper and lr_schedule.gin example, then trace gin's configurable and reference-resolution entry points and related tests. Define the supported arbitrary-function behavior and its configuration syntax before determining what tests should demonstrate that the feature is complete.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.