Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can a Config be wrapped with Variable? #16

Closed
dc3ea9f opened this issue Jul 28, 2023 · 3 comments
Closed

Can a Config be wrapped with Variable? #16

dc3ea9f opened this issue Jul 28, 2023 · 3 comments

Comments

@dc3ea9f
Copy link

dc3ea9f commented Jul 28, 2023

For now, I am using this code to get train_args.

from chanfig import Config, Variable
from . import data as data_cfg


class BaseConfig(Config):
    def __init__(self) -> None:
        super().__init__()
        self.train_data: Config = data_cfg.ImageNet

    def get_train_args(self) -> Config:
        train_args: Config = Config({
            'data': self.train_data,
        })
        return train_args

Can the Config be wrapped with Variable such that we could do so?

from chanfig import Config, Variable
from . import data as data_cfg


class BaseConfig(Config):
    def __init__(self) -> None:
        super().__init__()
        self.train_data: Config = data_cfg.ImageNet
        self.train_args: Config = Config({
            'data': self.train_data,
        })

and when run with --train_data.name, the train_args.data.name also changed?

@ZhiyuanChen
Copy link
Owner

ZhiyuanChen commented Jul 28, 2023

This is actually a bug, or more precisely, two bugs.

  1. If value is a NestedDict object, chanfig shouldn't make another copy. This is to ensure the consistency with python dict.
  2. The following code should have worked
from chanfig import Config, Variable
from . import data as data_cfg


class BaseConfig(Config):
    def __init__(self) -> None:
        super().__init__()
        self.train_data: Config = Variable(data_cfg.ImageNet)
        self.train_args: Config = Config({
            'data': self.train_data,
        })

Somehow merge did not recognised it correctly.

@ZhiyuanChen
Copy link
Owner

  1. If value is a FlatDict object, chanfig shouldn't make another copy. This is to ensure the consistency with python dict.

Fixed now, will work on it next week.

@ZhiyuanChen
Copy link
Owner

Fixed in e62919a
Please let me know if it works as expected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants