-
Notifications
You must be signed in to change notification settings - Fork 92
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
Showing
2 changed files
with
35 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import torch | ||
import torch_struct | ||
import warnings | ||
|
||
|
||
def test_alignment_crf_shapes(): | ||
batch, N, M = 2, 4, 5 | ||
log_potentials = torch.rand(batch, N, M, 3) | ||
|
||
if torch.cuda.is_available(): | ||
log_potentials = log_potentials.cuda() | ||
else: | ||
warnings.warn('Could not move log potentials to CUDA device. ' | ||
'Will not test marginals.') | ||
|
||
dist = torch_struct.AlignmentCRF(log_potentials) | ||
assert (batch, N, M, 3) == dist.argmax.shape | ||
if torch.cuda.is_available(): | ||
assert (batch, N, M, 3) == dist.marginals.shape | ||
assert (batch,) == dist.partition.shape | ||
|
||
# Fail due to AttributeError: 'BandedMatrix' object has no attribute | ||
# 'unsqueeze' | ||
# assert (batch,) == dist.entropy.shape | ||
# assert (9, batch, N, M, 3) == dist.sample([9]).shape | ||
|
||
# Fails due to: RuntimeError: Expected condition, x and y to be on | ||
# the same device, but condition is on cpu and x and y are on | ||
# cuda:0 and cuda:0 respectively | ||
# assert (8, batch,) == dist.topk(8).shape |
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