tensorflow icon indicating copy to clipboard operation
tensorflow copied to clipboard

tf.raw_ops.ResourceScatterUpdate crash with abortion

Open trickiwoo opened this issue 2 years ago • 7 comments
trafficstars

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)

trickiwoo avatar Mar 28 '23 16:03 trickiwoo

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.

Adesoji1 avatar Mar 31 '23 20:03 Adesoji1

@trickiwoo Could you please let us know if the above workaround worked for you? Thank you!

sushreebarsa avatar Apr 04 '23 11:04 sushreebarsa

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.

github-actions[bot] avatar Apr 12 '23 01:04 github-actions[bot]

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

trickiwoo avatar Apr 15 '23 20:04 trickiwoo

I was able to reproduce the issue in Tensorflow 2.12, please find the attached Gist here. Thanks!

sachinprasadhs avatar Apr 18 '23 20:04 sachinprasadhs

@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!

tilakrayal avatar Jan 25 '24 12:01 tilakrayal

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.

github-actions[bot] avatar Feb 02 '24 01:02 github-actions[bot]

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.

github-actions[bot] avatar Feb 10 '24 01:02 github-actions[bot]

Are you satisfied with the resolution of your issue? Yes No

google-ml-butler[bot] avatar Feb 10 '24 01:02 google-ml-butler[bot]