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
tsoc
superbenchmark
Commits
80f434cb
Unverified
Commit
80f434cb
authored
Mar 15, 2021
by
guoshzhao
Committed by
GitHub
Mar 15, 2021
Browse files
add more checks for PytorchBase module (#19)
Co-authored-by:
Guoshuai Zhao
<
guzhao@microsoft.com
>
parent
5d11579a
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
12 deletions
+20
-12
superbench/benchmarks/model_benchmarks/pytorch_base.py
superbench/benchmarks/model_benchmarks/pytorch_base.py
+20
-12
No files found.
superbench/benchmarks/model_benchmarks/pytorch_base.py
View file @
80f434cb
...
@@ -40,7 +40,7 @@ def _init_distributed_setting(self):
...
@@ -40,7 +40,7 @@ def _init_distributed_setting(self):
if
self
.
_args
.
distributed_impl
:
if
self
.
_args
.
distributed_impl
:
logger
.
info
(
logger
.
info
(
'Distributed training is enabled - model: {}, distributed implementation: {}.'
.
format
(
'Distributed training is enabled - model: {}, distributed implementation: {}.'
.
format
(
self
.
_name
,
self
.
_args
.
distributed_impl
.
value
self
.
_name
,
self
.
_args
.
distributed_impl
)
)
)
)
if
self
.
_args
.
distributed_impl
==
DistributedImpl
.
HOROVOD
:
if
self
.
_args
.
distributed_impl
==
DistributedImpl
.
HOROVOD
:
...
@@ -49,20 +49,20 @@ def _init_distributed_setting(self):
...
@@ -49,20 +49,20 @@ def _init_distributed_setting(self):
self
.
_world_size
=
int
(
hvd
.
size
())
self
.
_world_size
=
int
(
hvd
.
size
())
self
.
_local_rank
=
int
(
hvd
.
local_rank
())
self
.
_local_rank
=
int
(
hvd
.
local_rank
())
elif
self
.
_args
.
distributed_impl
==
DistributedImpl
.
DDP
:
elif
self
.
_args
.
distributed_impl
==
DistributedImpl
.
DDP
:
torch
.
distributed
.
init_process_group
(
backend
=
self
.
_args
.
distributed_backend
.
value
)
if
os
.
environ
.
get
(
'WORLD_SIZE'
)
is
None
or
os
.
environ
.
get
(
'LOCAL_RANK'
)
is
None
:
if
os
.
environ
.
get
(
'WORLD_SIZE'
)
is
False
or
os
.
environ
.
get
(
'LOCAL_RANK'
)
is
False
:
logger
.
error
(
logger
.
error
(
'Can not find WORLD_SIZE or LOCAL_RANK in env variables - model: {},'
'Can not find WORLD_SIZE or LOCAL_RANK in env variables - model: {},'
' distributed implementation: {}.'
.
format
(
self
.
_name
,
self
.
_args
.
distributed_impl
.
value
)
' distributed implementation: {}.'
.
format
(
self
.
_name
,
self
.
_args
.
distributed_impl
)
)
)
return
False
return
False
torch
.
distributed
.
init_process_group
(
backend
=
self
.
_args
.
distributed_backend
.
value
)
self
.
_world_size
=
int
(
os
.
environ
[
'WORLD_SIZE'
])
self
.
_world_size
=
int
(
os
.
environ
[
'WORLD_SIZE'
])
self
.
_local_rank
=
int
(
os
.
environ
[
'LOCAL_RANK'
])
self
.
_local_rank
=
int
(
os
.
environ
[
'LOCAL_RANK'
])
else
:
else
:
logger
.
error
(
logger
.
error
(
'Unsupported distributed implementation - model: {}, distributed implementation: {}.'
.
format
(
'Unsupported distributed implementation - model: {}, distributed implementation: {}.'
.
format
(
self
.
_name
,
self
.
_args
.
distributed_impl
.
value
self
.
_name
,
self
.
_args
.
distributed_impl
)
)
)
)
return
False
return
False
...
@@ -89,14 +89,22 @@ def _init_dataloader(self):
...
@@ -89,14 +89,22 @@ def _init_dataloader(self):
rank
=
hvd
.
rank
()
rank
=
hvd
.
rank
()
)
)
elif
self
.
_args
.
distributed_impl
==
DistributedImpl
.
DDP
:
elif
self
.
_args
.
distributed_impl
==
DistributedImpl
.
DDP
:
train_sampler
=
\
try
:
torch
.
utils
.
data
.
distributed
.
DistributedSampler
(
train_sampler
=
\
self
.
_dataset
torch
.
utils
.
data
.
distributed
.
DistributedSampler
(
self
.
_dataset
)
except
BaseException
as
e
:
logger
.
error
(
'Init dataloader failed - model: {}, distributed implementation: {}, message: {}.'
.
format
(
self
.
_name
,
self
.
_args
.
distributed_impl
,
str
(
e
)
)
)
)
return
False
else
:
else
:
logger
.
error
(
logger
.
error
(
'Unsupported distributed implementation - model: {}, distributed implementation: {}.'
.
format
(
'Unsupported distributed implementation - model: {}, distributed implementation: {}.'
.
format
(
self
.
_name
,
self
.
_args
.
distributed_impl
.
value
self
.
_name
,
self
.
_args
.
distributed_impl
)
)
)
)
return
False
return
False
...
@@ -131,12 +139,12 @@ def _create_optimizer(self):
...
@@ -131,12 +139,12 @@ def _create_optimizer(self):
self
.
_optimizer
=
torch
.
optim
.
Adam
(
self
.
_model
.
parameters
(),
lr
=
1e-5
,
betas
=
(
0.9
,
0.999
),
eps
=
1e-08
)
self
.
_optimizer
=
torch
.
optim
.
Adam
(
self
.
_model
.
parameters
(),
lr
=
1e-5
,
betas
=
(
0.9
,
0.999
),
eps
=
1e-08
)
elif
self
.
_optimizer_type
==
Optimizer
.
ADAMW
:
elif
self
.
_optimizer_type
==
Optimizer
.
ADAMW
:
self
.
_optimizer
=
torch
.
optim
.
AdamW
(
self
.
_model
.
parameters
(),
lr
=
1e-5
,
betas
=
(
0.9
,
0.999
),
eps
=
1e-08
)
self
.
_optimizer
=
torch
.
optim
.
AdamW
(
self
.
_model
.
parameters
(),
lr
=
1e-5
,
betas
=
(
0.9
,
0.999
),
eps
=
1e-08
)
else
:
self
.
_optimizer
=
None
if
not
self
.
_optimizer
:
if
not
self
.
_optimizer
:
logger
.
error
(
logger
.
error
(
'Create optimizer failed - model: {}, optimizer type: {}.'
.
format
(
'Create optimizer failed - model: {}, optimizer type: {}.'
.
format
(
self
.
_name
,
self
.
_optimizer_type
)
self
.
_name
,
self
.
_optimizer_type
.
value
)
)
)
return
False
return
False
...
...
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