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

Class _RefVariableProcessor

tensorflow/python/training/optimizer.py:129–156  ·  view source on GitHub ↗

Processor for Variable.

Source from the content-addressed store, hash-verified

127
128
129class _RefVariableProcessor(_OptimizableVariable):
130 """Processor for Variable."""
131
132 def __init__(self, v):
133 self._v = v
134
135 def __str__(self):
136 return "<_RefVariableProcessor(%s)>" % self._v
137
138 def target(self):
139 return self._v._ref() # pylint: disable=protected-access
140
141 def update_op(self, optimizer, g):
142 if isinstance(g, ops.Tensor):
143 update_op = optimizer._apply_dense(g, self._v) # pylint: disable=protected-access
144 if self._v.constraint is not None:
145 with ops.control_dependencies([update_op]):
146 return self._v.assign(self._v.constraint(self._v))
147 else:
148 return update_op
149 else:
150 assert isinstance(g, ops.IndexedSlices), ("Gradient ", g, " is neither a "
151 "tensor nor IndexedSlices.")
152 if self._v.constraint is not None:
153 raise RuntimeError(
154 "Cannot use a constraint function on a sparse variable.")
155 # pylint: disable=protected-access
156 return optimizer._apply_sparse_duplicate_indices(g, self._v)
157
158
159class _DenseReadResourceVariableProcessor(_OptimizableVariable):

Callers 1

_get_processorFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected