google / google/gin-config

inheriting configs with default parameters

Open
#3 3 comments 0 reactions 1 assignee Claimed by @dhr View on GitHub
Dominant language
Python
Stars
2.2k
Forks
122
Avg merge
5d 10h
Merged PRs (30d)
2

Description

Let's consider a simple two-class hierarchy:

```python
@gin.configurable
class A:
def __init__(self, a=1):
self.a = a

@gin.configurable
class B(A):
def __init__(self, a=1, b=2):
super().__init__(a)
self.b = b
```

Ideally I would like to replicate this structure in my `.gin` config files:

```
A.a = 3
B.b = 4
```

So that when I call `obj = B()` it would contain `obj.a == 3 and obj.b == 4`.
However, right now this does not happen - I get `obj.a == 1 and obj.b == 4`.
This is because gin detects that `A` constructor is manually called with `a` set as `B`'s default.

The current workaround is to define full configuration for each class separately, however that becomes quite cumbersome when configuring many classes that inherit from one base class with majority of the parameters shared.

---

One possible fix would be to reuse existing macro syntax and explicitly replicate the hierarchy in `.gin` config, e.g.:

```
A.a = 3

B = #A
b.b = 4
```

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.