-
Notifications
You must be signed in to change notification settings - Fork 276
Fix graph LAM GNN kwarg handling #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 1 commit
4a24927
640b795
718deaf
e705585
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,11 +1,12 @@ | ||
| # Standard library | ||
| from types import SimpleNamespace | ||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| # Third-party | ||
| import pytest | ||
|
|
||
| # First-party | ||
| from neural_lam.train_model import main | ||
| from neural_lam.train_model import load_forecaster_module_from_checkpoint, main | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
|
|
@@ -87,3 +88,57 @@ def capture_init(_self, **kwargs): | |
| "create_gif" in captured_kwargs | ||
| ), "create_gif was not forwarded to ForecasterModule" | ||
| assert captured_kwargs["create_gif"] is True | ||
|
|
||
|
|
||
| def test_checkpoint_loader_restores_gnn_type_kwargs(): | ||
| """Checkpoint reload must preserve custom GNN choices from saved args.""" | ||
| args = SimpleNamespace( | ||
| model="hi_lam", | ||
| graph="hierarchical", | ||
| hidden_dim=4, | ||
| hidden_layers=1, | ||
| processor_layers=1, | ||
| mesh_aggr="sum", | ||
| num_past_forcing_steps=1, | ||
| num_future_forcing_steps=1, | ||
| output_std=False, | ||
| g2m_gnn_type="PropagationNet", | ||
| m2g_gnn_type="PropagationNet", | ||
| mesh_up_gnn_type="PropagationNet", | ||
| mesh_down_gnn_type="InteractionNet", | ||
| ) | ||
| config = SimpleNamespace( | ||
| training=SimpleNamespace( | ||
| output_clamping=SimpleNamespace(lower={}, upper={}) | ||
| ) | ||
| ) | ||
| datastore = MagicMock() | ||
| captured_kwargs = {} | ||
|
|
||
| class DummyPredictor: | ||
| def __init__(self, **kwargs): | ||
| captured_kwargs.update(kwargs) | ||
|
|
||
| loaded_module = MagicMock() | ||
|
|
||
| with ( | ||
| patch( | ||
| "neural_lam.train_model.torch.load", | ||
| return_value={"hyper_parameters": {"args": args}}, | ||
| ), | ||
| patch("neural_lam.train_model.MODELS", {"hi_lam": DummyPredictor}), | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we test this also for graph_lam, as that would have caught the original crash? (now that
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Related to this — neither new test constructs an |
||
| patch("neural_lam.train_model.ARForecaster"), | ||
| patch( | ||
| "neural_lam.train_model.ForecasterModule.load_from_checkpoint", | ||
| return_value=loaded_module, | ||
| ), | ||
| ): | ||
| result = load_forecaster_module_from_checkpoint( | ||
| "model.ckpt", config, datastore | ||
| ) | ||
|
|
||
| assert result is loaded_module | ||
| assert captured_kwargs["g2m_gnn_type"] == "PropagationNet" | ||
| assert captured_kwargs["m2g_gnn_type"] == "PropagationNet" | ||
| assert captured_kwargs["mesh_up_gnn_type"] == "PropagationNet" | ||
| assert captured_kwargs["mesh_down_gnn_type"] == "InteractionNet" | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To be consistent with rest of codebase