Giter Site home page Giter Site logo

Comments (3)

ZhiyuanChen avatar ZhiyuanChen commented on September 27, 2024

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.

ZhiyuanChen avatar ZhiyuanChen commented on September 27, 2024

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.

ZhiyuanChen avatar ZhiyuanChen commented on September 27, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.