aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core/ops/resource_variable_ops.cc
diff options
context:
space:
mode:
authorGravatar A. Unique TensorFlower <gardener@tensorflow.org>2016-11-23 11:40:55 -0800
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2016-11-23 11:47:13 -0800
commitaa4aadef0492005f60c03aa40789efad719752f0 (patch)
tree2e09b1c91ac3b05a699be4138d59988b2ae50478 /tensorflow/core/ops/resource_variable_ops.cc
parent18af08feafad32b44fd9f1a20e143b716c82f21b (diff)
Makes resource variables saveable/restorable.
Change: 140055398
Diffstat (limited to 'tensorflow/core/ops/resource_variable_ops.cc')
-rw-r--r--tensorflow/core/ops/resource_variable_ops.cc64
1 files changed, 18 insertions, 46 deletions
diff --git a/tensorflow/core/ops/resource_variable_ops.cc b/tensorflow/core/ops/resource_variable_ops.cc
index 205f888f6f..4b02790f7a 100644
--- a/tensorflow/core/ops/resource_variable_ops.cc
+++ b/tensorflow/core/ops/resource_variable_ops.cc
@@ -52,36 +52,6 @@ dtype: the type of this variable. Must agree with the dtypes
shape: The (possibly partially specified) shape of this variable.
)");
-Status CreateAssignShapeFn(InferenceContext* c) {
- DataType handle_dtype = c->input_handle_dtype(0);
- DataType value_dtype;
- c->GetAttr("dtype", &value_dtype);
- if (handle_dtype != value_dtype) {
- return errors::InvalidArgument(
- "Trying to initialize handle for variable with wrong dtype. "
- "Expected ",
- handle_dtype, " got ", value_dtype);
- }
- ShapeHandle s = c->input_handle_shape(0);
- ShapeHandle value_shape = c->input(1);
- ShapeHandle unused;
- TF_RETURN_IF_ERROR(c->Merge(s, value_shape, &unused));
- return Status::OK();
-}
-
-REGISTER_OP("CreateVariableOp")
- .Input("resource: resource")
- .Input("value: dtype")
- .Attr("dtype: type")
- .SetShapeFn(CreateAssignShapeFn)
- .Doc(R"(
-Creates a variable resource.
-
-resource: handle to the resource in which to store the variable.
-value: the value to set the new tensor to use.
-dtype: the dtype of the value.
-)");
-
REGISTER_OP("ReadVariableOp")
.Input("resource: resource")
.Output("value: dtype")
@@ -113,6 +83,23 @@ resource: handle to the resource in which to store the variable.
dtype: the dtype of the value.
)");
+Status CreateAssignShapeFn(InferenceContext* c) {
+ DataType handle_dtype = c->input_handle_dtype(0);
+ DataType value_dtype;
+ c->GetAttr("dtype", &value_dtype);
+ if (handle_dtype != value_dtype) {
+ return errors::InvalidArgument(
+ "Trying to initialize handle for variable with wrong dtype. "
+ "Expected ",
+ handle_dtype, " got ", value_dtype);
+ }
+ ShapeHandle s = c->input_handle_shape(0);
+ ShapeHandle value_shape = c->input(1);
+ ShapeHandle unused;
+ TF_RETURN_IF_ERROR(c->Merge(s, value_shape, &unused));
+ return Status::OK();
+}
+
REGISTER_OP("AssignVariableOp")
.Input("resource: resource")
.Input("value: dtype")
@@ -133,22 +120,7 @@ REGISTER_OP("AssignAddVariableOp")
.Input("resource: resource")
.Input("value: dtype")
.Attr("dtype: type")
- .SetShapeFn([](InferenceContext* c) {
- DataType handle_dtype = c->input_handle_dtype(0);
- DataType value_dtype;
- c->GetAttr("dtype", &value_dtype);
- if (handle_dtype != value_dtype) {
- return errors::InvalidArgument(
- "Trying to initialize handle for variable with wrong dtype. "
- "Expected ",
- handle_dtype, " got ", value_dtype);
- }
- ShapeHandle s = c->input_handle_shape(0);
- ShapeHandle value_shape = c->input(1);
- ShapeHandle unused;
- TF_RETURN_IF_ERROR(c->Merge(s, value_shape, &unused));
- return Status::OK();
- })
+ .SetShapeFn(CreateAssignShapeFn)
.Doc(R"(
Adds a value to the current value of a variable.