tensorflow
tensorflow copied to clipboard
tf.raw_ops.ResourceScatterUpdate crash with abortion
Click to expand!
Issue Type
Bug
Have you reproduced the bug with TF nightly?
Yes
Source
source
Tensorflow Version
2.13.0-dev20230208
Custom Code
Yes
OS Platform and Distribution
No response
Mobile device
No response
Python version
No response
Bazel version
No response
GCC/Compiler version
No response
CUDA/cuDNN version
No response
GPU model and memory
No response
Current Behaviour?
tf.raw_ops.ResourceScatterUpdate crash with abortion
Standalone code to reproduce the issue
import tensorflow as tf
import numpy as np
init = np.random.rand(20)
update = np.random.rand(20)
resource = tf.Variable(init, dtype=tf.float32)
resource_var = resource.handle
indices = np.array([1, 3, 5], dtype=np.int32)
tf.raw_ops.ResourceScatterUpdate(resource=resource_var, indices=indices, updates=update)
Relevant log output
2023-03-28 11:39:22.735062: F tensorflow/core/framework/tensor.cc:770] Check failed: dtype() == expected_dtype (1 vs. 2) double expected, got float
Aborted (core dumped)
Try this below
import tensorflow as tf import numpy as np
init = np.random.rand(20).astype(np.float32) # Convert to float32
resource = tf.Variable(init, dtype=tf.float32) resource_var = resource.handle indices = np.array([1, 3, 5], dtype=np.int32)
Make sure the updates tensor has the correct shape: (len(indices),)
update = np.random.rand(len(indices)).astype(np.float32) # Convert to float32
tf.raw_ops.ResourceScatterUpdate(resource=resource_var, indices=indices, updates=update) Now, the 'updates' tensor has a shape that matches the size of the 'indices' tensor, and the error should be resolved.
@trickiwoo Could you please let us know if the above workaround worked for you? Thank you!
This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.
Thanks for providing the workaround. However, in my understanding, crashes like this seem to be a vulnerability according to https://github.com/tensorflow/tensorflow/issues/60121#issuecomment-1485230826
I was able to reproduce the issue in Tensorflow 2.12, please find the attached Gist here. Thanks!
@trickiwoo, I tried to execute the mentioned code on tf-nightly and the code was executed with the error and also observed that the crash did not happen. And the same has been in the respective files. Kindly find the gist for the reference.
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/quantize_and_dequantize_op.cc#L22
https://github.com/tensorflow/tensorflow/blob/master/tensorflow/core/kernels/resource_variable_ops.cc#L1120
// Check data type of update and resource to scatter. const DataType update_dtype = c->input(2).dtype(); OP_REQUIRES(c, v->tensor()->dtype() == update_dtype, errors::InvalidArgument( "DType of scatter resource and updates does not match."));
Thank you!
This issue is stale because it has been open for 7 days with no activity. It will be closed if no further activity occurs. Thank you.
This issue was closed because it has been inactive for 7 days since being marked as stale. Please reopen if you'd like to work on this further.