-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathwandb_tuning.py
55 lines (45 loc) · 1.76 KB
/
wandb_tuning.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from datetime import datetime
import pytorch_lightning as pl
import pytz
import wandb
from dataloader import ERDataModule
from model import ERNet
from modules.utils import config_parser
from omegaconf import OmegaConf
from pytorch_lightning.callbacks import ModelCheckpoint
from pytorch_lightning.loggers import WandbLogger
from transformers import AutoTokenizer
if __name__ == "__main__":
config = config_parser()
pl.seed_everything(config["seed"], workers=True)
MODEL_NAME = config["model"]["model_name"]
tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)
parameters = OmegaConf.to_container(config["wandb"]["parameters"])
sweep_config = {
"name": config["wandb"]["name"],
"method": config["wandb"]["method"],
"parameters": parameters,
}
now = datetime.now(pytz.timezone("Asia/Seoul"))
sweep_id = wandb.sweep(
sweep_config, project=f"{config['wandb']['project_name']}", entity="Yoonseul"
)
def wandb_tuning():
wandb.init()
dataloader = ERDataModule(
config=config, tokenizer=tokenizer, wandb_batch_size=wandb.config.batch_size
)
model = ERNet(config=config, wandb_config=wandb.config, state="train")
wandb_logger = WandbLogger()
trainer = pl.Trainer(
callbacks=ModelCheckpoint(
dirpath=f"./checkpoint/{MODEL_NAME.replace('/', '_')}/{now.strftime('%Y-%m-%d %H.%M.%S')}/",
filename="{epoch}-{val_micro_f1:.2f}",
monitor="val_micro_f1",
mode="max",
),
max_epochs=wandb.config.epochs,
logger=wandb_logger,
)
trainer.fit(model=model, train_dataloaders=dataloader)
wandb.agent(sweep_id=sweep_id, function=wandb_tuning, count=36)