aboutsummaryrefslogtreecommitdiffhomepage
path: root/tensorflow/core
diff options
context:
space:
mode:
authorGravatar Asim Shankar <ashankar@google.com>2018-10-04 09:21:05 -0700
committerGravatar TensorFlower Gardener <gardener@tensorflow.org>2018-10-04 09:30:41 -0700
commitac22e1583aed390d78d2e87a4bf8a6ec39400ec4 (patch)
tree4fcbb4a8078b50c31862c38c7b8c48e01d0b3a28 /tensorflow/core
parenta7e8ad18a61b251ef42c0260dd80a12cea8f268c (diff)
Gracefully disallow updating resource variables with invalid shapes.
During graph construction, the shape function for AssignAddVariableOp etc. would raise an error when the value being "assign add"ed to the variable has an incompatible shape. With eager execution, no such validation was being made which triggerred an assertion failure in eigen: https://github.com/eigenteam/eigen-git-mirror/blob/7d97e1cbbe4424fda39e31c88def7c0863897640/unsupported/Eigen/CXX11/src/Tensor/TensorEvaluator.h#L479 This change prevents that assertion failure. PiperOrigin-RevId: 215749071
Diffstat (limited to 'tensorflow/core')
-rw-r--r--tensorflow/core/kernels/resource_variable_ops.cc6
1 files changed, 6 insertions, 0 deletions
diff --git a/tensorflow/core/kernels/resource_variable_ops.cc b/tensorflow/core/kernels/resource_variable_ops.cc
index 23d76986bf..678d675c4a 100644
--- a/tensorflow/core/kernels/resource_variable_ops.cc
+++ b/tensorflow/core/kernels/resource_variable_ops.cc
@@ -426,6 +426,12 @@ class AssignUpdateVariableOp : public OpKernel {
// ADD if value's refcount was 1.
mutex_lock ml(*variable->mu());
Tensor* var_tensor = variable->tensor();
+ OP_REQUIRES(context, var_tensor->shape().IsSameSize(value.shape()),
+ errors::InvalidArgument("Cannot update variable with shape ",
+ var_tensor->shape().DebugString(),
+ " using a Tensor with shape ",
+ value.shape().DebugString(),
+ ", shapes must be equal."));
OP_REQUIRES_OK(context,
PrepareToUpdateVariable<Device, T>(context, var_tensor));
functor::DenseUpdate<Device, T, Op> update_functor;