Skip to content

Configuring methods of classes (especially: wrapped by external_configurable) #191

@SlapDrone

Description

@SlapDrone

Hey folks,

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

Foo.bar.x = 10

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

@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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions