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

配置文件问题 #87

Open
Waterkin opened this issue Oct 12, 2023 · 2 comments
Open

配置文件问题 #87

Waterkin opened this issue Oct 12, 2023 · 2 comments

Comments

@Waterkin
Copy link

Waterkin commented Oct 12, 2023

在调参的过程中,经常会需要对多个数据集的多个模型调参,需要写多个模型多个数据集的 config 文件。

我的想法是,能否复用一套config 文件,在调参grid search时,动态修改 config 的配置,从而省去写 config 的麻烦。

感谢答疑~

@Waterkin
Copy link
Author

Waterkin commented Oct 12, 2023

在我的尝试中,我试图将 easytorch 结合 wandb 实现调参的自动化实验记录,然而,在代码中动态修改 config失败了,模型依然会依照原有的 config 运行,这让我很费解,如下代码:
即使我修改了DATASET为wandb.config.DATASET,在实际运行时仍然会读取args 文件内的DATASET..

def train():
    wandb.init()
    model_type = get_key(model_dict, wandb.config.MODEL_NAME)
    model_name = wandb.config.MODEL_NAME
    dataset = wandb.config.DATASET
    args = f"examples/{model_type}/{model_name}_OTHERS.py"

    # 使用wandb.config来覆盖配置值
    CFG = import_config(args)
    CFG.DATASET_NAME = wandb.config.DATASET
    CFG.TRAIN.OPTIM.PARAM.lr = wandb.config.lr
    CFG.TRAIN.OPTIM.PARAM["weight_decay"] = wandb.config.weight_decay
    CFG.TRAIN.LR_SCHEDULER.PARAM["gamma"] = wandb.config.gamma
    CFG.TRAIN.LR_SCHEDULER.PARAM["milestones"] = wandb.config.milestones
    CFG.TRAIN.DATA.BATCH_SIZE = wandb.config.batch_size
    launch_training(CFG, "0")

def main():
    for dataset in dataset_list:
        for model_name in model_list:
            try:
                # 第一步: 调整学习率
                for lr in lr_values:
                    config_filter_lr = {
                        "config.lr": lr,
                        "config.batch_size": 4096,
                        "config.weight_decay": 0.0001,
                        "config.gamma": 0.5,
                        "config.milestones": [1, 50, 80],
                    }
                    if not check_existing_run(
                        "your-project-name", model_name, dataset, config_filter_lr
                    ):
                        sweep_config_lr = {
                            "name": "sweep_lr",
                            "method": "grid",
                            "parameters": {
                                "MODEL_NAME": {"value": model_name},
                                "DATASET": {"value": dataset},
                                "lr": {"values": [0.1, 0.01, 0.001, 0.0001]},
                                "batch_size": {"value": 4096},
                                "weight_decay": {"value": 0.0001},
                                "gamma": {"value": 0.5},
                                "milestones": {"value": [1, 50, 80]},
                            },
                        }
                        sweep_id = wandb.sweep(
                            sweep=sweep_config_lr, project="your-project-name"
                        )
                        wandb.agent(
                            sweep_id, function=train
                        )  # Grid search will try all combinations

@wang486
Copy link

wang486 commented Oct 17, 2024

兄弟你解决问题了吗

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