wandb
wandb主要用于两个部分:
其实主要分为四步:配置参数,初始化,记录,退出
from argparse import Namespace
# ---------- wandb config -------------#
#1.配置config,其实等于argparse.add_argement()
config = Namespace(
project_name="first_paper",
dataset="cora",
node_drop_rate=0.1,
cluster_num=7,
gnnlayers=3
)
#2.init
#project 是项目名,name是单次实验名称
train(config=config):
wandb.init(config=config, project=config.project_name + "_" + config.dataset + name,
name=config.project_name + "_" + str(config.cluster_num) + "_" + nowtime)
#3.记录(train中)
wandb.log({"epoch": epoch, "loss": loss, "WSS": WSS, "nmi": nmi})
#4.wandb退出(train中)
wandb.finish()
#5.主程序运行:
train(config)
其实际上与wandb_log混用
#1.配置config,其中sweep是字典格式
config = Namespace(
project_name="first_paper",
dataset="cora",
node_drop_rate=0.1,
cluster_num=7,
gnnlayers=3
)
sweep_config = {
"method": "grid",
"metric": {"name": "best_nmi", "goal": "maximize"},#根据metric的best_nmi自适应参数,方案为最大化(maximize)
"parameters": {
"node_drop_rate": {
"values": [0.0, 0.05, 0.1, 0.15, 0.2, 0.25]
},
"gnnlayers": {
"values": [0, 1, 2, 3, 4, 5, 6]
}
}
}
#2.init
train(config=config):
wandb.init(config=config, project=config.project_name + "_" + config.dataset + name,
name=config.project_name + "_" + str(config.cluster_num) + "_" + nowtime)
#下面这个很关键,网上的教程是错的,这句话的意思是:如果运行sweep,那么用sweep的config替换默认的config.如果没有运行sweep,那么仍然用原来的config
config = wandb.config
#3.记录(train中)
wandb.log({"best_nmi":best_nmi})
#4.退出(train中)
wandb.finish
#5.运行
#初始化sweep
sweep_id = wandb.sweep(sweep=sweep_config, project=config.project_name + "_" + config.dataset + "_sweep") #将sweep的配置赋给train,count为
wandb.agent(sweep_id, train, count=48)
run = wandb.init(mode="dryrun")
wandb sync /path/to/dryrun/directory