-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathcli.py
More file actions
62 lines (45 loc) · 1.47 KB
/
cli.py
File metadata and controls
62 lines (45 loc) · 1.47 KB
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
56
57
58
59
60
61
62
import click
import pytorch_lightning as pl
import wandb
from pytorch_lightning import seed_everything
from utils.config import Config
seed_everything(42, workers=True)
@click.group()
def cli():
pass
@cli.command()
@click.option('--config', type=click.Path(exists=True, dir_okay=False))
def train(config):
"""
Train a PyTorch Lightning model using the provided config file.
"""
config = Config(config)
wandb.login(key=config.get_wandb_key())
# Create DataModule instance
datamodule = config.get_datamodule()
# Create Model instance
model = config.get_modelmodule()
# Get trainer config
trainer_config = config.get_trainer_config()
trainer = pl.Trainer(**trainer_config)
# Train the model
trainer.fit(model, datamodule, ckpt_path=config.get_last_checkpoint())
# Define the test command (unchanged)
@cli.command()
@click.option('--config', type=click.Path(exists=True, dir_okay=False))
def test(config):
"""
Test a PyTorch Lightning model using the provided config file.
"""
config = Config(config)
# Create DataModule instance
datamodule = config.get_datamodule()
# Create Model instance
model = config.get_modelmodule()
# Get trainer config
trainer_config = config.get_test_trainer_config()
trainer = pl.Trainer(**trainer_config)
# Test the model
trainer.test(model, datamodule, ckpt_path=config.get_best_checkpoint())
if __name__ == '__main__':
cli()