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

Function _StopOps

tensorflow/python/ops/gradients_util.py:268–299  ·  view source on GitHub ↗

The set of ops that terminate the gradient computation. This computes the frontier of the forward graph *before* which backprop should stop. Operations in the returned set will not be differentiated. This set is defined as the subset of `from_ops` containing ops that have no predecessor in

(from_ops, stop_gradient_ops, pending_count, xs_set)

Source from the content-addressed store, hash-verified

266
267
268def _StopOps(from_ops, stop_gradient_ops, pending_count, xs_set):
269 """The set of ops that terminate the gradient computation.
270
271 This computes the frontier of the forward graph *before* which backprop
272 should stop. Operations in the returned set will not be differentiated.
273 This set is defined as the subset of `from_ops` containing ops that have
274 no predecessor in `from_ops`. `pending_count` is the result of
275 `_PendingCount(xs, from_ops)`. An 'op' has predecessors in `from_ops`
276 iff pending_count[op] > 0.
277
278 In addition, none of `stop_gradient_ops` will be differentiated.
279
280 Args:
281 from_ops: list of Operations.
282 stop_gradient_ops: list of Operations never to backprop through.
283 pending_count: mapping from operation to number of backprop inputs.
284 xs_set: ObjectIdentitySet of Tensors.
285
286 Returns:
287 The set of operations.
288 """
289 stop_ops = set()
290 for op in from_ops:
291 is_stop_op = True
292 for inp in _NonEagerInputs(op, xs_set):
293 if pending_count[inp.op] > 0:
294 is_stop_op = False
295 break
296 if is_stop_op:
297 stop_ops.add(op)
298 stop_ops.update(op for op in stop_gradient_ops)
299 return stop_ops
300
301
302@contextlib.contextmanager

Callers 1

_GradientsHelperFunction · 0.85

Calls 3

_NonEagerInputsFunction · 0.85
addMethod · 0.45
updateMethod · 0.45

Tested by

no test coverage detected