Skip to content

Commit

Permalink
[minor] test split_non_tensor(<Tensor>) case (#1000)
Browse files Browse the repository at this point in the history
  • Loading branch information
crutcher committed May 30, 2022
1 parent 2bd85c0 commit e7602a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions fairscale/utils/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ def split_non_tensors(
Split a tuple into a list of tensors and the rest with information
for later reconstruction.
When called with a tensor X, will return: (x,), None
Usage::
x = torch.Tensor([1])
Expand Down
5 changes: 5 additions & 0 deletions tests/utils/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,11 @@ def test_split_unpack():
x = torch.Tensor([1])
y = torch.Tensor([2])

# degenerate case, args is a single tensor.
tensors, packed_non_tensors = split_non_tensors(x)
assert tensors == (x,)
assert packed_non_tensors is None

tensors, packed_non_tensors = split_non_tensors((x, y, None, 3))
assert tensors == (x, y)
assert packed_non_tensors == {
Expand Down

0 comments on commit e7602a4

Please sign in to comment.