-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6acfca7
commit 8fbf8f7
Showing
2 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
File renamed without changes.
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,70 @@ | ||
"""Tests for time Tensor t.""" | ||
|
||
# Author: Kilian Fatras <[email protected]> | ||
|
||
import pytest | ||
import torch | ||
|
||
from torchcfm.conditional_flow_matching import ( | ||
ConditionalFlowMatcher, | ||
ExactOptimalTransportConditionalFlowMatcher, | ||
SchrodingerBridgeConditionalFlowMatcher, | ||
TargetConditionalFlowMatcher, | ||
VariancePreservingConditionalFlowMatcher, | ||
) | ||
|
||
seed = 1994 | ||
batch_size = 128 | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"FM", | ||
[ | ||
ConditionalFlowMatcher(sigma=0.0), | ||
ExactOptimalTransportConditionalFlowMatcher(sigma=0.0), | ||
TargetConditionalFlowMatcher(sigma=0.0), | ||
SchrodingerBridgeConditionalFlowMatcher(sigma=0.0), | ||
VariancePreservingConditionalFlowMatcher(sigma=0.0), | ||
], | ||
) | ||
def test_random_Tensor_t(FM): | ||
# Test sample_location_and_conditional_flow functions | ||
x0 = torch.randn(batch_size, 2) | ||
x1 = torch.randn(batch_size, 2) | ||
|
||
torch.manual_seed(seed) | ||
t_given = torch.rand(batch_size) | ||
t_given, xt, ut = FM.sample_location_and_conditional_flow(x0, x1, t=t_given) | ||
|
||
torch.manual_seed(seed) | ||
t_random, xt, ut = FM.sample_location_and_conditional_flow(x0, x1, t=None) | ||
|
||
assert any(t_given == t_random) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"FM", | ||
[ | ||
ExactOptimalTransportConditionalFlowMatcher(sigma=0.0), | ||
SchrodingerBridgeConditionalFlowMatcher(sigma=0.0), | ||
], | ||
) | ||
def test_guided_random_Tensor_t(FM): | ||
# Test guided_sample_location_and_conditional_flow functions | ||
x0 = torch.randn(batch_size, 2) | ||
y0 = torch.randint(high=10, size=(batch_size, 1)) | ||
x1 = torch.randn(batch_size, 2) | ||
y1 = torch.randint(high=10, size=(batch_size, 1)) | ||
|
||
torch.manual_seed(seed) | ||
t_given = torch.rand(batch_size) | ||
t_given, xt, ut, y0, y1 = FM.guided_sample_location_and_conditional_flow( | ||
x0, x1, y0=y0, y1=y1, t=t_given | ||
) | ||
|
||
torch.manual_seed(seed) | ||
t_random, xt, ut, y0, y1 = FM.guided_sample_location_and_conditional_flow( | ||
x0, x1, y0=y0, y1=y1, t=None | ||
) | ||
|
||
assert any(t_given == t_random) |