Hi, I 'm using a 2016 Intel based MBP with an AMD Radeon Pro 460 running OS X Monterey 12.1.
When I ran the code here:
https://d2l.ai/chapter_preliminaries/ndarray.html#indexing-and-slicing
X_var = tf.Variable(X)
X_var[1, 2].assign(9)
I got the error output:
---------------------------------------------------------------------------
NotFoundError Traceback (most recent call last)
/Volumes/WD 1T/Repos/Dive into Deep Learning/tensorflow/chapter_4_preliminaries/ndarray.ipynb Cell 38' in <module>
3 X_var[1, 2].assign(9)
4 X_var = tf.Variable(X)
----> 5 X_var[1, 2].assign(9)
6 X_var
File ~/.conda/envs/tensorflow-metal/lib/python3.8/site-packages/tensorflow/python/ops/array_ops.py:1236, in strided_slice.<locals>.assign(val, name)
1233 if name is None:
1234 name = parent_name + "_assign"
-> 1236 return var._strided_slice_assign(
1237 begin=begin,
1238 end=end,
1239 strides=strides,
1240 value=val,
1241 name=name,
1242 begin_mask=begin_mask,
1243 end_mask=end_mask,
1244 ellipsis_mask=ellipsis_mask,
1245 new_axis_mask=new_axis_mask,
1246 shrink_axis_mask=shrink_axis_mask)
File ~/.conda/envs/tensorflow-metal/lib/python3.8/site-packages/tensorflow/python/ops/resource_variable_ops.py:1407, in BaseResourceVariable._strided_slice_assign(self, begin, end, strides, value, name, begin_mask, end_mask, ellipsis_mask, new_axis_mask, shrink_axis_mask)
1402 def _strided_slice_assign(self, begin, end, strides, value, name, begin_mask,
1403 end_mask, ellipsis_mask, new_axis_mask,
1404 shrink_axis_mask):
1405 with _handle_graph(self.handle), self._assign_dependencies():
1406 return self._lazy_read(
-> 1407 gen_array_ops.resource_strided_slice_assign(
1408 ref=self.handle,
1409 begin=begin,
1410 end=end,
1411 strides=strides,
1412 value=ops.convert_to_tensor(value, dtype=self.dtype),
1413 name=name,
1414 begin_mask=begin_mask,
1415 end_mask=end_mask,
1416 ellipsis_mask=ellipsis_mask,
1417 new_axis_mask=new_axis_mask,
1418 shrink_axis_mask=shrink_axis_mask))
File ~/.conda/envs/tensorflow-metal/lib/python3.8/site-packages/tensorflow/python/ops/gen_array_ops.py:8612, in resource_strided_slice_assign(ref, begin, end, strides, value, begin_mask, end_mask, ellipsis_mask, new_axis_mask, shrink_axis_mask, name)
8610 return _result
8611 except _core._NotOkStatusException as e:
-> 8612 _ops.raise_from_not_ok_status(e, name)
8613 except _core._FallbackException:
8614 pass
File ~/.conda/envs/tensorflow-metal/lib/python3.8/site-packages/tensorflow/python/framework/ops.py:7107, in raise_from_not_ok_status(e, name)
7105 def raise_from_not_ok_status(e, name):
7106 e.message += (" name: " + name if name is not None else "")
-> 7107 raise core._status_to_exception(e) from None
NotFoundError: No registered 'ResourceStridedSliceAssign' OpKernel for 'GPU' devices compatible with node {{node ResourceStridedSliceAssign}}
(OpKernel was found, but attributes didn't match) Requested Attributes: Index=DT_INT32, T=DT_FLOAT, begin_mask=0, ellipsis_mask=0, end_mask=0, new_axis_mask=0, shrink_axis_mask=3
. Registered: device='XLA_CPU_JIT'; Index in [DT_INT32, DT_INT64]; T in [DT_FLOAT, DT_DOUBLE, DT_INT32, DT_UINT8, DT_INT16, DT_INT8, DT_COMPLEX64, DT_INT64, DT_BOOL, DT_QINT8, DT_QUINT8, DT_QINT32, DT_BFLOAT16, DT_UINT16, DT_COMPLEX128, DT_HALF, DT_UINT32, DT_UINT64]
device='DEFAULT'; T in [DT_INT32]
device='CPU'; T in [DT_UINT64]
device='CPU'; T in [DT_INT64]
device='CPU'; T in [DT_UINT32]
device='CPU'; T in [DT_UINT16]
device='CPU'; T in [DT_INT16]
device='CPU'; T in [DT_UINT8]
device='CPU'; T in [DT_INT8]
device='CPU'; T in [DT_INT32]
device='CPU'; T in [DT_HALF]
device='CPU'; T in [DT_BFLOAT16]
device='CPU'; T in [DT_FLOAT]
device='CPU'; T in [DT_DOUBLE]
device='CPU'; T in [DT_COMPLEX64]
device='CPU'; T in [DT_COMPLEX128]
device='CPU'; T in [DT_BOOL]
device='CPU'; T in [DT_STRING]
device='CPU'; T in [DT_RESOURCE]
device='CPU'; T in [DT_VARIANT]
[Op:ResourceStridedSliceAssign] name: strided_slice/_assign
It seems that the operation is somehow not supported on GPU, I have to specify CPU as the device of the operation and it works.
with tf.device('/CPU:0'):
X_var = tf.Variable(X)
X_var[1, 2].assign(9)
Hi @wow2333,
Thanks for reporting this issue! Your diagnosis of the issue is correct, the ResourceStridedSliceAssignOp is has not been registered on the GPU leading to this colocation issue when using assign. We will update here once this issue has been addressed and a fix is out. Until then running the part of the code relying on ResourceStridedSliceAssign on the CPU is the workaround for the issue.