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
cd642eb1
Commit
cd642eb1
authored
5 years ago
by
Stephan Seitz
Browse files
Options
Downloads
Patches
Plain Diff
Remove deprecation warning (again
)
parent
ca171f5b
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/pystencils_autodiff/backends/_tensorflow.py
+14
-6
14 additions, 6 deletions
src/pystencils_autodiff/backends/_tensorflow.py
with
14 additions
and
6 deletions
src/pystencils_autodiff/backends/_tensorflow.py
+
14
−
6
View file @
cd642eb1
import
tensorflow
as
tf
import
pystencils_autodiff
import
numpy
as
np
from
pystencils.utils
import
DotDict
from
tf.compat.v1
import
get_default_graph
_num_generated_ops
=
0
def
_py_func
(
func
,
inp
,
Tout
,
stateful
=
False
,
name
=
None
,
grad
=
None
):
"""
Copied from random internet forum. It seems to be important to give
Copied from random internet forum. It seems to be important to give
PyFunc to give an random name in override map to properly register gradients
PyFunc defined as given by Tensorflow
...
...
@@ -29,14 +29,17 @@ def _py_func(func, inp, Tout, stateful=False, name=None, grad=None):
tf
.
RegisterGradient
(
rnd_name
)(
grad
)
# Get current graph
g
=
tf
.
get_default_graph
()
g
=
get_default_graph
()
# Add gradient override map
with
g
.
gradient_override_map
({
"
PyFunc
"
:
rnd_name
,
"
PyFuncStateless
"
:
rnd_name
}):
return
tf
.
py_func
(
func
,
inp
,
Tout
,
stateful
=
stateful
,
name
=
name
)
def
tensorflowop_from_autodiffop
(
autodiffop
:
pystencils_autodiff
.
AutoDiffOp
,
inputfield_tensor_dict
,
forward_function
,
backward_function
):
def
tensorflowop_from_autodiffop
(
autodiffop
:
pystencils_autodiff
.
AutoDiffOp
,
inputfield_tensor_dict
,
forward_function
,
backward_function
):
def
helper_forward
(
*
args
):
kwargs
=
dict
()
...
...
@@ -59,7 +62,12 @@ def tensorflowop_from_autodiffop(autodiffop: pystencils_autodiff.AutoDiffOp, inp
return
[
rtn_dict
[
o
.
name
]
for
o
in
autodiffop
.
_backward_output_fields
]
def
backward
(
op
,
*
grad
):
return
tf
.
py_func
(
helper_backward
,
[
*
op
.
inputs
,
*
grad
],
[
f
.
dtype
.
numpy_dtype
for
f
in
autodiffop
.
_backward_output_fields
],
name
=
autodiffop
.
op_name
+
'
_backward
'
,
stateful
=
False
)
return
tf
.
py_func
(
helper_backward
,
[
*
op
.
inputs
,
*
grad
],
[
f
.
dtype
.
numpy_dtype
for
f
in
autodiffop
.
_backward_output_fields
],
name
=
autodiffop
.
op_name
+
'
_backward
'
,
stateful
=
False
)
output_tensors
=
_py_func
(
helper_forward
,
[
inputfield_tensor_dict
[
f
]
...
...
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