google / google/gin-config

Configuring methods of classes (especially: wrapped by external_configurable)

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

Description

Hey folks,

When I want to configure individual methods of a class, i.e. to write in `config.gin` something like:

```python
Foo.bar.x = 10
```

If i'm not mistaken we need two layers of configurable decorators on our class, like so:

```python
@gin.configurable
@dataclass
class Foo:
x: float = 5.

@gin.configurable(module="Foo")
def bar(self, y: float):
print(y)

@classmethod
@gin.configurable(module="Foo")
def baz(cls, xstr: str):
return cls(float(xstr))
```

This is fine, I guess the interpretation of the top-level decorator is that we only want to configure the __init__, and want to be explicit about which individual methods are configurable.

How do we tackle binding to method arguments on an `external_configurable`? In particular, I want to do something in `config.gin` like:

```
import llama_index
import mymodule.gin # inside I import ServiceContext and run gin.external_configurable on it

# ...
llama_index.ServiceContext.from_defaults.llm = %llm
```

Do I need to monkey patch gin-decorated versions of each method in the class from the external library?

Thanks for any advice or thoughts. Absolutely love this library btw.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.