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
c619fe6e
Commit
c619fe6e
authored
Jan 24, 2019
by
Michael Carilli
Browse files
Updating comments
parent
646fc0d0
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
6 additions
and
1 deletion
+6
-1
apex/amp/utils.py
apex/amp/utils.py
+6
-1
No files found.
apex/amp/utils.py
View file @
c619fe6e
...
@@ -88,10 +88,15 @@ def cached_cast(cast_fn, x, cache):
...
@@ -88,10 +88,15 @@ def cached_cast(cast_fn, x, cache):
if
x
in
cache
:
if
x
in
cache
:
cached_x
=
cache
[
x
]
cached_x
=
cache
[
x
]
if
x
.
requires_grad
and
cached_x
.
requires_grad
:
if
x
.
requires_grad
and
cached_x
.
requires_grad
:
#
Check to m
ake sure x is actually cached_x's autograd parent.
#
M
ake sure x is actually cached_x's autograd parent.
if
cached_x
.
grad_fn
.
next_functions
[
1
][
0
].
variable
is
not
x
:
if
cached_x
.
grad_fn
.
next_functions
[
1
][
0
].
variable
is
not
x
:
raise
RuntimeError
(
"x and cache[x] both require grad, but x is not "
raise
RuntimeError
(
"x and cache[x] both require grad, but x is not "
"cache[x]'s parent. This is likely an error."
)
"cache[x]'s parent. This is likely an error."
)
# During eval, it's possible to end up caching casted weights with
# requires_grad=False. On the next training iter, if cached_x is found
# and reused from the cache, it will not actually have x as its parent.
# Therefore, we choose to invalidate the cache (and force refreshing the cast)
# if x.requires_grad and cached_x.requires_grad do not match.
if
x
.
requires_grad
!=
cached_x
.
requires_grad
:
if
x
.
requires_grad
!=
cached_x
.
requires_grad
:
del
cache
[
x
]
del
cache
[
x
]
else
:
else
:
...
...
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