Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
pystencils_autodiff
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
pycodegen
pystencils_autodiff
Commits
25ebe582
Commit
25ebe582
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Allow use_cuda to be truthy (instead of only True/False)
parent
f3772f74
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Pipeline
#20540
failed
5 years ago
Stage: test
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pystencils_autodiff/backends/_torch_native.py
+3
-1
3 additions, 1 deletion
src/pystencils_autodiff/backends/_torch_native.py
with
3 additions
and
1 deletion
src/pystencils_autodiff/backends/_torch_native.py
+
3
−
1
View file @
25ebe582
...
@@ -74,9 +74,12 @@ def create_autograd_function(autodiff_obj, use_cuda):
...
@@ -74,9 +74,12 @@ def create_autograd_function(autodiff_obj, use_cuda):
return
tuple
(
output_tensors
.
values
())
return
tuple
(
output_tensors
.
values
())
def
backward
(
self
,
*
grad_outputs
):
def
backward
(
self
,
*
grad_outputs
):
nonlocal
use_cuda
if
use_cuda
:
if
use_cuda
:
use_cuda
=
True
grad_outputs
=
[
a
.
contiguous
().
cuda
()
for
a
in
grad_outputs
]
grad_outputs
=
[
a
.
contiguous
().
cuda
()
for
a
in
grad_outputs
]
else
:
else
:
use_cuda
=
False
grad_outputs
=
[
a
.
contiguous
().
cpu
()
for
a
in
grad_outputs
]
grad_outputs
=
[
a
.
contiguous
().
cpu
()
for
a
in
grad_outputs
]
grad_fields
=
[
f
for
f
in
autodiff_obj
.
backward_input_fields
if
f
not
in
autodiff_obj
.
forward_input_fields
]
grad_fields
=
[
f
for
f
in
autodiff_obj
.
backward_input_fields
if
f
not
in
autodiff_obj
.
forward_input_fields
]
...
@@ -84,7 +87,6 @@ def create_autograd_function(autodiff_obj, use_cuda):
...
@@ -84,7 +87,6 @@ def create_autograd_function(autodiff_obj, use_cuda):
assert
all
(
f
.
shape
==
grad_outputs
[
i
].
shape
for
i
,
f
in
enumerate
(
grad_fields
))
assert
all
(
f
.
shape
==
grad_outputs
[
i
].
shape
for
i
,
f
in
enumerate
(
grad_fields
))
assert
all
(
f
.
strides
==
tuple
(
grad_outputs
[
i
].
stride
(
j
)
for
j
in
range
(
grad_outputs
[
i
].
ndim
))
assert
all
(
f
.
strides
==
tuple
(
grad_outputs
[
i
].
stride
(
j
)
for
j
in
range
(
grad_outputs
[
i
].
ndim
))
for
i
,
f
in
enumerate
(
grad_fields
))
for
i
,
f
in
enumerate
(
grad_fields
))
assert
use_cuda
in
(
True
,
False
),
"
use_cuda needs to be True or False
"
assert
all
(
a
.
is_cuda
==
use_cuda
for
a
in
grad_outputs
),
(
assert
all
(
a
.
is_cuda
==
use_cuda
for
a
in
grad_outputs
),
(
"
Some of the tensors where on the wrong device.
"
f
"
Op was compiled for CUDA:
{
str
(
use_cuda
)
}
"
)
"
Some of the tensors where on the wrong device.
"
f
"
Op was compiled for CUDA:
{
str
(
use_cuda
)
}
"
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment