Pretends to be a tf.Operation for the gradient functions.
| 88 | |
| 89 | |
| 90 | class _MockOp(object): |
| 91 | """Pretends to be a tf.Operation for the gradient functions.""" |
| 92 | |
| 93 | def __init__(self, attrs, inputs, outputs, typ, skip_input_indices): |
| 94 | self.attrs = attrs |
| 95 | self.inputs = inputs |
| 96 | self.outputs = outputs |
| 97 | self.type = typ |
| 98 | self.skip_input_indices = skip_input_indices |
| 99 | |
| 100 | def get_attr(self, attr): |
| 101 | typ = op_attr_type(self.type, attr) |
| 102 | for i in range(0, len(self.attrs), 2): |
| 103 | if self.attrs[i] == attr: |
| 104 | return make_attr(typ, self.attrs[i + 1]) |
| 105 | raise KeyError(attr) |
| 106 | |
| 107 | def _get_control_flow_context(self): |
| 108 | raise NotImplementedError( |
| 109 | "tf.GradientTape.gradients() does not support graph control flow " |
| 110 | "operations like tf.cond or tf.while at this time. Use tf.gradients() " |
| 111 | "instead. If you need this feature, please file a feature request at " |
| 112 | "https://github.com/tensorflow/tensorflow/issues/new" |
| 113 | ) |
| 114 | |
| 115 | |
| 116 | def _gradient_function(op_name, attr_tuple, num_inputs, inputs, outputs, |
no outgoing calls