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
apex
Commits
3ccdd63d
Unverified
Commit
3ccdd63d
authored
May 07, 2020
by
Chaitanya Sri Krishna Lolla
Committed by
GitHub
May 07, 2020
Browse files
enable python only base sparse tensor support for loss scaling (#2)
parent
e85a1d4b
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
3 deletions
+12
-3
apex/amp/scaler.py
apex/amp/scaler.py
+12
-3
No files found.
apex/amp/scaler.py
View file @
3ccdd63d
...
...
@@ -6,11 +6,17 @@ from itertools import product
def
scale_check_overflow_python
(
model_grad
,
master_grad
,
scale
,
check_overflow
=
False
):
# Exception handling for 18.04 compatibility
if
check_overflow
:
if
model_grad
.
is_sparse
:
cpu_sum
=
float
(
model_grad
.
float
().
_values
().
sum
())
else
:
cpu_sum
=
float
(
model_grad
.
float
().
sum
())
if
cpu_sum
==
float
(
'inf'
)
or
cpu_sum
==
-
float
(
'inf'
)
or
cpu_sum
!=
cpu_sum
:
return
True
if
master_grad
is
not
model_grad
:
# copy_ probably internally short-circuits this
if
model_grad
.
is_sparse
:
master_grad
.
copy_
(
model_grad
.
to_dense
())
else
:
master_grad
.
copy_
(
model_grad
)
if
scale
!=
1.0
:
master_grad
.
mul_
(
scale
)
...
...
@@ -19,6 +25,9 @@ def scale_check_overflow_python(model_grad, master_grad, scale, check_overflow=F
def
axpby_check_overflow_python
(
model_grad
,
stashed_grad
,
master_grad
,
a
,
b
,
check_overflow
=
False
):
# Exception handling for 18.04 compatibility
if
check_overflow
:
if
model_grad
.
is_sparse
:
cpu_sum
=
float
(
model_grad
.
float
().
_values
().
sum
())
else
:
cpu_sum
=
float
(
model_grad
.
float
().
sum
())
if
cpu_sum
==
float
(
'inf'
)
or
cpu_sum
==
-
float
(
'inf'
)
or
cpu_sum
!=
cpu_sum
:
return
True
...
...
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