Comments (3)
Thank you for your recognition~
Config has puzzled me for years and I didn't come up with the idea behind CHANfiG
until very recently.
This is also a really tricky question and will possibly take months and even years before I can find the best practice.
I intentionally let items()
or **
only return value in current level, so one solution is to put common attributes at another level / higher level.
For example, your model
has an encoder
and a decoder
, you would like to let them shares the same droupout setting but different model size.
class ModelConfig(Config):
def __init__(self):
self.encoder.num_layers = 4
self.decoder.num_layers = 2
self.dropout = 0.1
class Model(nn.Module):
def __init__(config):
self.encoder = (**config.model.encoder, **config.model)
If there is only a few common attributes, something like Optimizer(abc=config.b.x, **config.optimizer)
should work just fine.
from chanfig.
Today we released the v0.0.34, which added a Variable
class that wraps a immutable object, e.g. int, float, str to a mutable object.
With this new feature, the same variable that is used in different position will have alternation together.
from chanfig.
With the recent release of v0.0.36
, we implemented get
and set
method of Variable
and make OrderedDict
calls set
for Variable
object. By doing so, we can have the following outputs:
class Config(chanfig.Config):
def init(self):
emb = chanfig.Variable(384)
self.model.emb = emb
self.data.emb = emb
c = Config()
print(c)
Config(
(model): Config(
(emb): 384
)
(data): Config(
(emb): 384
)
)
c.model.emb = 256
print(d)
DC(
(model): Config(
(emb): 256
)
(data): Config(
(emb): 256
)
)
So, in your case, you could create a variable and use it everywhere.
CHANfiG will sync them automatically.
from chanfig.
Related Issues (12)
- Feature Request: variable interpolation in yaml file HOT 26
- load config from command arguments HOT 6
- Can a Config be wrapped with Variable? HOT 3
- error: argument --name: invalid NoneType value: 'value' HOT 1
- Support to read multiple config file and combine them HOT 3
- Strange error when dict key is a list HOT 1
- from_yamls() is broken with chanfig[include] HOT 1
- wrong output when use with rich.print HOT 9
- Feature Request: help message, type checker and input restrictions HOT 24
- `--help` only shows arguments defined by `add_argument`
- jsonc support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chanfig.