-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
training working with mllam datastore!
- Loading branch information
Leif Denby
committed
Jul 25, 2024
1 parent
58f5d99
commit 64d43a6
Showing
5 changed files
with
118 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# Standard library | ||
import os | ||
|
||
# Disable weights and biases to avoid unnecessary logging | ||
# and to avoid having to deal with authentication | ||
os.environ["WANDB_DISABLED"] = "true" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Standard library | ||
from pathlib import Path | ||
|
||
# Third-party | ||
import pytest | ||
import pytorch_lightning as pl | ||
import torch | ||
import wandb | ||
from test_datastores import DATASTORES, init_datastore | ||
|
||
# First-party | ||
from neural_lam.create_graph import create_graph_from_datastore | ||
from neural_lam.models.graph_lam import GraphLAM | ||
from neural_lam.weather_dataset import WeatherDataModule | ||
|
||
|
||
@pytest.mark.parametrize("datastore_name", DATASTORES.keys()) | ||
def test_training(datastore_name): | ||
datastore = init_datastore(datastore_name) | ||
|
||
if torch.cuda.is_available(): | ||
device_name = "cuda" | ||
torch.set_float32_matmul_precision( | ||
"high" | ||
) # Allows using Tensor Cores on A100s | ||
else: | ||
device_name = "cpu" | ||
|
||
trainer = pl.Trainer( | ||
max_epochs=3, | ||
deterministic=True, | ||
strategy="ddp", | ||
accelerator=device_name, | ||
log_every_n_steps=1, | ||
) | ||
|
||
graph_name = "1level" | ||
|
||
graph_dir_path = Path(datastore.root_path) / "graph" / graph_name | ||
|
||
if not graph_dir_path.exists(): | ||
create_graph_from_datastore( | ||
datastore=datastore, | ||
output_root_path=str(graph_dir_path), | ||
n_max_levels=1, | ||
) | ||
|
||
data_module = WeatherDataModule( | ||
datastore=datastore, | ||
ar_steps_train=3, | ||
ar_steps_eval=5, | ||
standardize=True, | ||
batch_size=2, | ||
num_workers=1, | ||
forcing_window_size=3, | ||
) | ||
|
||
class ModelArgs: | ||
output_std = False | ||
loss = "mse" | ||
restore_opt = False | ||
n_example_pred = 1 | ||
# XXX: this should be superfluous when we have already defined the | ||
# model object no? | ||
graph = graph_name | ||
hidden_dim = 8 | ||
hidden_layers = 1 | ||
processor_layers = 4 | ||
mesh_aggr = "sum" | ||
lr = 1.0e-3 | ||
val_steps_to_log = [1] | ||
metrics_watch = [] | ||
|
||
model_args = ModelArgs() | ||
|
||
model = GraphLAM( # noqa | ||
args=model_args, | ||
forcing_window_size=data_module.forcing_window_size, | ||
datastore=datastore, | ||
) | ||
wandb.init() | ||
trainer.fit(model=model, datamodule=data_module) |