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
180c9197
Commit
180c9197
authored
Sep 24, 2021
by
Anjali Sridhar
Browse files
simplify condiiton for readability
parent
b09ddb2d
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
4 additions
and
3 deletions
+4
-3
fairscale/nn/data_parallel/fully_sharded_data_parallel.py
fairscale/nn/data_parallel/fully_sharded_data_parallel.py
+4
-3
No files found.
fairscale/nn/data_parallel/fully_sharded_data_parallel.py
View file @
180c9197
...
@@ -587,19 +587,20 @@ class FullyShardedDataParallel(nn.Module):
...
@@ -587,19 +587,20 @@ class FullyShardedDataParallel(nn.Module):
assert
p
.
dtype
==
torch
.
float32
assert
p
.
dtype
==
torch
.
float32
# If world_size is 1, then we all-reduce grads instead of sharding.
# If world_size is 1, then we all-reduce grads instead of sharding.
p
.
_is_sharded
=
self
.
world_size
>
1
p
.
_orig_size
=
p
.
data
.
size
()
p
.
_orig_size
=
p
.
data
.
size
()
if
not
p
.
_is_sharded
:
if
self
.
world_size
==
1
:
p
.
_is_sharded
=
False
self
.
numel_padded_per_param
.
append
(
0
)
self
.
numel_padded_per_param
.
append
(
0
)
continue
continue
p
.
_is_sharded
=
True
# Replace p.data with the relevant shard.
# Replace p.data with the relevant shard.
orig_data
=
p
.
data
orig_data
=
p
.
data
p
.
data
,
num_padded
=
self
.
_get_shard
(
p
.
data
)
p
.
data
,
num_padded
=
self
.
_get_shard
(
p
.
data
)
self
.
numel_padded_per_param
.
append
(
num_padded
)
self
.
numel_padded_per_param
.
append
(
num_padded
)
free_storage_
(
orig_data
)
free_storage_
(
orig_data
)
p
.
_is_sharded
=
True
assert
len
(
self
.
numel_padded_per_param
)
==
len
(
self
.
params
)
assert
len
(
self
.
numel_padded_per_param
)
==
len
(
self
.
params
)
def
_get_shard
(
self
,
tensor
:
torch
.
Tensor
)
->
Tuple
[
torch
.
Tensor
,
int
]:
def
_get_shard
(
self
,
tensor
:
torch
.
Tensor
)
->
Tuple
[
torch
.
Tensor
,
int
]:
...
...
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