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)
| 266 | |
| 267 | |
| 268 | def _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 |
no test coverage detected