MCPcopy Create free account
hub / github.com/DeepRec-AI/DeepRec / _compute_dx_and_dy

Function _compute_dx_and_dy

tensorflow/python/ops/gradient_checker.py:196–208  ·  view source on GitHub ↗

Returns a node to compute gradient of y wrt x.

(x, y, y_shape)

Source from the content-addressed store, hash-verified

194
195
196def _compute_dx_and_dy(x, y, y_shape):
197 """Returns a node to compute gradient of y wrt x."""
198 # We make up a dy so that we can compute the gradients. We don't really use
199 # the value of dy -- we will always feed it. We need to add an identity node
200 # so that we can always feed it properly. Otherwise, for the Add operation,
201 # dx is the same as dy and we cannot fetch the tensor that we are feeding.
202 with x.graph.as_default():
203 dy_orig = constant_op.constant(1.0, shape=y_shape, dtype=y.dtype)
204 dy = array_ops.identity(dy_orig)
205 # We compute the gradients for y wrt. x
206 grads = gradients.gradients(y, x, dy)
207 assert len(grads) == 1
208 return grads[0], dy_orig
209
210
211def _compute_gradient(x,

Callers 2

_compute_gradient_listFunction · 0.85
compute_gradientFunction · 0.85

Calls 3

as_defaultMethod · 0.45
constantMethod · 0.45
identityMethod · 0.45

Tested by

no test coverage detected