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

Function verify_captures

tensorflow/python/ops/cond_v2.py:752–768  ·  view source on GitHub ↗

Verify that a branch's tensor is not accessed in another branch fn.

(op_type, branch_graphs)

Source from the content-addressed store, hash-verified

750
751
752def verify_captures(op_type, branch_graphs):
753 """Verify that a branch's tensor is not accessed in another branch fn."""
754 # Note: It is technically not possible for lower-branch_index branches to
755 # capture tensors from higher-branch_index branches, because of the order of
756 # branch graph construction, but we check all for completeness and to
757 # guard against potential future changes.
758 other_branch_graphs = {g: i for i, g in enumerate(branch_graphs)}
759 for i, branch_graph in enumerate(branch_graphs):
760 for t in branch_graph.external_captures:
761 if not isinstance(t, ops.EagerTensor) and t.graph in other_branch_graphs:
762 branch_names = ["true_fn", "false_fn"] if op_type == _COND else [
763 "branch {}".format(bi) for bi in range(len(branch_graphs))]
764 raise ValueError(
765 "Tensor {tname} in {b0name} is accessed from {b1name}.".format(
766 tname=t.name,
767 b0name=branch_names[other_branch_graphs[t.graph]],
768 b1name=branch_names[i]))
769
770
771class _CondGradFuncGraph(util.CondBranchFuncGraph):

Callers 2

cond_v2Function · 0.85
indexed_caseFunction · 0.85

Calls 2

rangeFunction · 0.70
formatMethod · 0.45

Tested by

no test coverage detected