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
lietorch
Commits
82b02233
Unverified
Commit
82b02233
authored
Aug 28, 2021
by
Zach Teed
Committed by
GitHub
Aug 28, 2021
Browse files
Merge pull request #7 from mli0603/master
fixed grad check for pytorch 1.9
parents
91887c3b
9d8130be
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
2 deletions
+16
-2
lietorch/gradcheck.py
lietorch/gradcheck.py
+16
-2
No files found.
lietorch/gradcheck.py
View file @
82b02233
import
torch
import
torch
TORCH_MAJOR
=
int
(
torch
.
__version__
.
split
(
'.'
)[
0
])
TORCH_MINOR
=
int
(
torch
.
__version__
.
split
(
'.'
)[
1
])
from
torch.types
import
_TensorOrTensors
from
torch.types
import
_TensorOrTensors
from
torch._six
import
container_abcs
,
istuple
if
TORCH_MAJOR
==
1
and
TORCH_MINOR
<
8
:
from
torch._six
import
container_abcs
,
istuple
else
:
import
collections.abc
as
container_abcs
import
torch.testing
import
torch.testing
from
torch.overrides
import
is_tensor_like
from
torch.overrides
import
is_tensor_like
from
itertools
import
product
from
itertools
import
product
...
@@ -203,7 +211,12 @@ def get_analytical_jacobian(input, output, nondet_tol=0.0, grad_out=1.0):
...
@@ -203,7 +211,12 @@ def get_analytical_jacobian(input, output, nondet_tol=0.0, grad_out=1.0):
def
_as_tuple
(
x
):
def
_as_tuple
(
x
):
if
istuple
(
x
):
if
TORCH_MAJOR
==
1
and
TORCH_MINOR
<
8
:
b_tuple
=
istuple
(
x
)
else
:
b_tuple
=
isinstance
(
x
,
tuple
)
if
b_tuple
:
return
x
return
x
elif
isinstance
(
x
,
list
):
elif
isinstance
(
x
,
list
):
return
tuple
(
x
)
return
tuple
(
x
)
...
@@ -211,6 +224,7 @@ def _as_tuple(x):
...
@@ -211,6 +224,7 @@ def _as_tuple(x):
return
x
,
return
x
,
def
_differentiable_outputs
(
x
):
def
_differentiable_outputs
(
x
):
return
tuple
(
o
for
o
in
_as_tuple
(
x
)
if
o
.
requires_grad
)
return
tuple
(
o
for
o
in
_as_tuple
(
x
)
if
o
.
requires_grad
)
...
...
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