Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
fairscale
Commits
e7602a4c
Unverified
Commit
e7602a4c
authored
May 30, 2022
by
Crutcher Dunnavant
Committed by
GitHub
May 30, 2022
Browse files
[minor] test split_non_tensor(<Tensor>) case (#1000)
parent
2bd85c05
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
7 additions
and
0 deletions
+7
-0
fairscale/utils/containers.py
fairscale/utils/containers.py
+2
-0
tests/utils/test_containers.py
tests/utils/test_containers.py
+5
-0
No files found.
fairscale/utils/containers.py
View file @
e7602a4c
...
@@ -78,6 +78,8 @@ def split_non_tensors(
...
@@ -78,6 +78,8 @@ def split_non_tensors(
Split a tuple into a list of tensors and the rest with information
Split a tuple into a list of tensors and the rest with information
for later reconstruction.
for later reconstruction.
When called with a tensor X, will return: (x,), None
Usage::
Usage::
x = torch.Tensor([1])
x = torch.Tensor([1])
...
...
tests/utils/test_containers.py
View file @
e7602a4c
...
@@ -99,6 +99,11 @@ def test_split_unpack():
...
@@ -99,6 +99,11 @@ def test_split_unpack():
x
=
torch
.
Tensor
([
1
])
x
=
torch
.
Tensor
([
1
])
y
=
torch
.
Tensor
([
2
])
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
))
tensors
,
packed_non_tensors
=
split_non_tensors
((
x
,
y
,
None
,
3
))
assert
tensors
==
(
x
,
y
)
assert
tensors
==
(
x
,
y
)
assert
packed_non_tensors
==
{
assert
packed_non_tensors
==
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment