add sweep support
This commit is contained in:
1 parent
f53794cf89
commit
d013e22742
4 files changed
+32
-17
No files matched your search
+9
-9
@@ -1,14 +1,14 @@
|
|||||||
|
num_of_gpus: -1
|
||||||
|
|
||||||
hparams:
|
hparams:
|
||||||
max_epochs: 30
|
max_epochs: 20
|
||||||
batch_size: 128
|
batch_size: 64
|
||||||
learning_rate: 0.001
|
lr: 0.001
|
||||||
accumulate_grad_batches: 1
|
accumulate_grad_batches: 1
|
||||||
gradient_clip_val: 0.5
|
gradient_clip_val: 0.5
|
||||||
num_of_gpus: 1
|
lin1_size: 128
|
||||||
model:
|
lin2_size: 256
|
||||||
lin1_size: 128
|
lin3_size: 128
|
||||||
lin2_size: 256
|
|
||||||
lin3_size: 128
|
|
||||||
|
|
||||||
resume:
|
resume:
|
||||||
resume_from_ckpt: False
|
resume_from_ckpt: False
|
||||||
@@ -30,7 +30,7 @@ callbacks:
|
|||||||
mode: "min"
|
mode: "min"
|
||||||
early_stop:
|
early_stop:
|
||||||
monitor: "val_loss"
|
monitor: "val_loss"
|
||||||
patience: 10
|
patience: 100
|
||||||
mode: "min"
|
mode: "min"
|
||||||
|
|
||||||
printing:
|
printing:
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import wandb
|
||||||
|
import main
|
||||||
|
|
||||||
|
|
||||||
|
# Load project config
|
||||||
|
config = main.load_config()
|
||||||
|
|
||||||
|
# Initialize wandb
|
||||||
|
wandb.init()
|
||||||
|
|
||||||
|
# Replace project config hyperparameters with the ones loaded from wandb sweep server
|
||||||
|
sweep_hparams = wandb.Config._as_dict(wandb.config)
|
||||||
|
for key, value in sweep_hparams.items():
|
||||||
|
if key != "_wandb":
|
||||||
|
config["hparams"][key] = value
|
||||||
|
|
||||||
|
# Execute run
|
||||||
|
main.main(config)
|
||||||
@@ -71,7 +71,7 @@ def main(config):
|
|||||||
trainer = pl.Trainer(
|
trainer = pl.Trainer(
|
||||||
logger=wandb_logger,
|
logger=wandb_logger,
|
||||||
callbacks=callbacks,
|
callbacks=callbacks,
|
||||||
gpus=config["hparams"]["num_of_gpus"],
|
gpus=config["num_of_gpus"],
|
||||||
max_epochs=config["hparams"]["max_epochs"],
|
max_epochs=config["hparams"]["max_epochs"],
|
||||||
resume_from_checkpoint=config["resume"]["ckpt_path"] if config["resume"]["resume_from_ckpt"] else None,
|
resume_from_checkpoint=config["resume"]["ckpt_path"] if config["resume"]["resume_from_ckpt"] else None,
|
||||||
accumulate_grad_batches=config["hparams"]["accumulate_grad_batches"],
|
accumulate_grad_batches=config["hparams"]["accumulate_grad_batches"],
|
||||||
@@ -95,9 +95,6 @@ def main(config):
|
|||||||
# Evaluate model on test set
|
# Evaluate model on test set
|
||||||
trainer.test()
|
trainer.test()
|
||||||
|
|
||||||
# Close wandb run
|
|
||||||
wandb.finish()
|
|
||||||
|
|
||||||
|
|
||||||
def load_config():
|
def load_config():
|
||||||
with open("config.yaml", "r") as ymlfile:
|
with open("config.yaml", "r") as ymlfile:
|
||||||
|
|||||||
@@ -16,10 +16,10 @@ class LitModel(pl.LightningModule):
|
|||||||
super().__init__()
|
super().__init__()
|
||||||
|
|
||||||
self.save_hyperparameters(config["hparams"])
|
self.save_hyperparameters(config["hparams"])
|
||||||
self.model = ModelMNISTv1(config=self.hparams.model)
|
self.model = ModelMNISTv2(config=self.hparams)
|
||||||
|
|
||||||
def forward(self, data):
|
def forward(self, x):
|
||||||
return self.model(data)
|
return self.model(x)
|
||||||
|
|
||||||
# logic for a single training step
|
# logic for a single training step
|
||||||
def training_step(self, batch, batch_idx):
|
def training_step(self, batch, batch_idx):
|
||||||
@@ -64,4 +64,4 @@ class LitModel(pl.LightningModule):
|
|||||||
return loss
|
return loss
|
||||||
|
|
||||||
def configure_optimizers(self):
|
def configure_optimizers(self):
|
||||||
return torch.optim.Adam(self.parameters(), lr=self.hparams.learning_rate)
|
return torch.optim.Adam(self.parameters(), lr=self.hparams.lr)
|
||||||
Reference in new issue
Block a user