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

Function _TensorArrayReadGrad

tensorflow/python/ops/tensor_array_grad.py:86–111  ·  view source on GitHub ↗

Gradient for TensorArrayRead. Args: op: Forward TensorArrayRead op. grad: Gradient `Tensor` to TensorArrayRead. Returns: A flow `Tensor`, which can be used in control dependencies to force the write of `grad` to the gradient `TensorArray`.

(op, grad)

Source from the content-addressed store, hash-verified

84@ops.RegisterGradient("TensorArrayReadV2")
85@ops.RegisterGradient("TensorArrayReadV3")
86def _TensorArrayReadGrad(op, grad):
87 """Gradient for TensorArrayRead.
88
89 Args:
90 op: Forward TensorArrayRead op.
91 grad: Gradient `Tensor` to TensorArrayRead.
92
93 Returns:
94 A flow `Tensor`, which can be used in control dependencies to
95 force the write of `grad` to the gradient `TensorArray`.
96 """
97 # Note: the forward flow dependency in the call to grad() is necessary for
98 # the case of dynamic sized TensorArrays. When creating the gradient
99 # TensorArray, the final size of the forward array must be known.
100 # For this we need to wait until it has been created by depending on
101 # the input flow of the original op.
102 handle = op.inputs[0]
103 index = op.inputs[1]
104 flow = op.inputs[2]
105 dtype = op.get_attr("dtype")
106 grad_source = _GetGradSource(grad)
107 g = (tensor_array_ops.TensorArray(dtype=dtype, handle=handle, flow=flow,
108 colocate_with_first_write_call=False)
109 .grad(source=grad_source, flow=flow))
110 w_g = g.write(index, grad)
111 return [None, None, w_g.flow]
112
113
114@ops.RegisterGradient("TensorArrayWrite")

Callers

nothing calls this directly

Calls 5

_GetGradSourceFunction · 0.85
TensorArrayMethod · 0.80
get_attrMethod · 0.45
gradMethod · 0.45
writeMethod · 0.45

Tested by

no test coverage detected