-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
update tests and fix attention model
- Loading branch information
Showing
8 changed files
with
125 additions
and
38 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
Binary file not shown.
Binary file not shown.
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,41 @@ | ||
import torch | ||
from ocf_datapipes.utils.consts import BatchKey | ||
from torch import nn | ||
|
||
from pvnet.models.multimodal.site_encoders.encoders import ( | ||
SimpleLearnedAggregator, | ||
SingleAttentionNetwork, | ||
) | ||
|
||
import pytest | ||
|
||
|
||
def _test_model_forward(batch, model_class, kwargs): | ||
model = model_class(**kwargs) | ||
y = model(batch) | ||
assert tuple(y.shape) == (2, kwargs["out_features"]), y.shape | ||
|
||
|
||
def _test_model_backward(batch, model_class, kwargs): | ||
model = model_class(**kwargs) | ||
y = model(batch) | ||
# Backwards on sum drives sum to zero | ||
y.sum().backward() | ||
|
||
|
||
# Test model forward on all models | ||
def test_simplelearnedaggregator_forward(sample_batch, site_encoder_model_kwargs): | ||
_test_model_forward(sample_batch, SimpleLearnedAggregator, site_encoder_model_kwargs) | ||
|
||
|
||
def test_singleattentionnetwork_forward(sample_batch, site_encoder_model_kwargs): | ||
_test_model_forward(sample_batch, SingleAttentionNetwork, site_encoder_model_kwargs) | ||
|
||
|
||
# Test model backward on all models | ||
def test_simplelearnedaggregator_backward(sample_batch, site_encoder_model_kwargs): | ||
_test_model_backward(sample_batch, SimpleLearnedAggregator, site_encoder_model_kwargs) | ||
|
||
|
||
def test_singleattentionnetwork_backward(sample_batch, site_encoder_model_kwargs): | ||
_test_model_backward(sample_batch, SingleAttentionNetwork, site_encoder_model_kwargs) |
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