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

Method __init__

tensorflow/python/ops/control_flow_state.py:120–204  ·  view source on GitHub ↗
(self, forward_ctxt, outer_grad_state)

Source from the content-addressed store, hash-verified

118 """
119
120 def __init__(self, forward_ctxt, outer_grad_state):
121 # The grad loop state for the outer while loop.
122 self._outer_grad_state = None
123
124 # The while loop context for forward.
125 self._forward_context = None
126
127 # The loop counter added by AddForwardLoopCounter. It is the value
128 # of the loop counter for the next iteration.
129 self._forward_index = None
130
131 # A sync op for forward.
132 self._forward_sync = None
133
134 # The while loop context for backprop.
135 self._grad_context = None
136
137 # The loop counter added by AddBackpropLoopCounter. It is the value
138 # of the loop counter for the current iteration.
139 self._grad_index = None
140
141 # A sync op for backprop.
142 self._grad_sync = None
143
144 # Information needed by backprop.
145 self._history_map = {}
146 self._switch_map = {}
147 self._unused_exits = []
148 self._deferred_exits = []
149 self._forward_loop_exits = list(forward_ctxt.loop_exits)
150 self._pending_exits_count = len(forward_ctxt.loop_exits)
151
152 self._outer_grad_state = outer_grad_state
153 if outer_grad_state:
154 outer_forward_ctxt = outer_grad_state.forward_context
155 else:
156 if not hasattr(forward_ctxt, "outer_context"):
157 raise ValueError("Failed to call gradients on a while loop without"
158 "properly serializing graph via MetaGraphDef")
159 outer_forward_ctxt = forward_ctxt.outer_context
160
161 # Add the forward loop counter.
162 with forward_ctxt._graph.as_default(): # pylint: disable=protected-access
163 if outer_forward_ctxt:
164 outer_forward_ctxt.Enter()
165 cnt, forward_index = forward_ctxt.AddForwardLoopCounter(outer_grad_state)
166 if outer_forward_ctxt:
167 outer_forward_ctxt.Exit()
168 self._forward_context = forward_ctxt
169 self._forward_index = forward_index
170
171 # Add the backprop WhileContext, and the backprop loop counter.
172 if outer_grad_state:
173 # This is a nested loop. Remember the iteration counts for each
174 # execution of this inner loop.
175 outer_forward_ctxt.AddName(cnt.name)
176 history_cnt = outer_grad_state.AddForwardAccumulator(cnt)
177

Callers

nothing calls this directly

Calls 9

AddForwardLoopCounterMethod · 0.80
AddNameMethod · 0.80
AddForwardAccumulatorMethod · 0.80
WhileContextMethod · 0.80
as_defaultMethod · 0.45
EnterMethod · 0.45
ExitMethod · 0.45

Tested by

no test coverage detected