Lifts `old_variable` out of the `FuncGraph` `graph`.
(old_variable, graph, variable_holder)
| 120 | |
| 121 | |
| 122 | def _lift_single_variable(old_variable, graph, variable_holder): |
| 123 | """Lifts `old_variable` out of the `FuncGraph` `graph`.""" |
| 124 | new_variable = resource_variable_ops.UninitializedVariable( |
| 125 | shape=old_variable.shape, |
| 126 | dtype=old_variable.dtype, |
| 127 | name=old_variable.op.name, |
| 128 | trainable=old_variable.trainable, |
| 129 | extra_handle_data=old_variable.handle) |
| 130 | new_variable._initializer_op = old_variable._initializer_op # pylint: disable=protected-access |
| 131 | graph.add_capture(new_variable.handle, old_variable.handle) |
| 132 | # Now that we've added the new variable to graph.captures, |
| 133 | # graph.capture will use that cached value and do some post-processing |
| 134 | # on the capture like recording it on the tape. |
| 135 | graph.capture(new_variable.handle) |
| 136 | # pylint: disable=protected-access |
| 137 | variable_name = new_variable.name.split(":")[0] |
| 138 | variable_holder._variables_by_name[variable_name] = new_variable |
| 139 | graph._weak_variables.append(weakref.ref(new_variable)) |
| 140 | # pylint: enable=protected-access |
| 141 | graph.watch_variable(new_variable) |
| 142 | return new_variable |
| 143 | |
| 144 | |
| 145 | def _lift_unlifted_variables(graph, variable_holder): |
no test coverage detected