Tensorflow 2.6.0 keras image preprocessing doesn't work with metal

Setting up a model with

inputs = tf.keras.Input(shape=imageShape)
x = inputs
x = layers.RandomFlip('horizontal')(x)
x = layers.RandomRotation(0.2)(x)
x = layers.Dropout(0.2)(x)
outputs = layers.Dense(1)(x)

Produces this output

2021-12-06 18:19:57.709106: W tensorflow/core/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz
2021-12-06 18:19:57.709239: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:112] Plugin optimizer for device_type GPU is enabled.
4/4 [==============================] - 1s 99ms/step - loss: 0.6075 - accuracy: 0.6613
Initial loss: 0.61
Initial accuracy: 0.66
Epoch 1/2
Traceback (most recent call last):
  <... etc ...>
tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation model/random_flip_1/stateful_uniform_full_int/RngReadAndSkip: Could not satisfy explicit device specification '' because the node {{colocation_node model/random_flip_1/stateful_uniform_full_int/RngReadAndSkip}} was colocated with a group of nodes that required incompatible device '/job:localhost/replica:0/task:0/device:GPU:0'. All available devices [/job:localhost/replica:0/task:0/device:CPU:0, /job:localhost/replica:0/task:0/device:GPU:0].
Colocation Debug Info:
Colocation group had the following types and supported devices:
Root Member(assigned_device_name_index_=2 requested_device_name_='/job:localhost/replica:0/task:0/device:GPU:0' assigned_device_name_='/job:localhost/replica:0/task:0/device:GPU:0' resource_device_name_='/job:localhost/replica:0/task:0/device:GPU:0' supported_device_types_=[CPU] possible_devices_=[]
RngReadAndSkip: CPU
_Arg: GPU CPU

Colocation members, user-requested devices, and framework assigned devices, if any:
  model_random_flip_1_stateful_uniform_full_int_rngreadandskip_resource (_Arg)  framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0
  model/random_flip_1/stateful_uniform_full_int/RngReadAndSkip (RngReadAndSkip)

   [[{{node model/random_flip_1/stateful_uniform_full_int/RngReadAndSkip}}]] [Op:__inference_train_function_11281]

But, running the model without the following layers:

x = layers.RandomFlip('horizontal')(x)
x = layers.RandomRotation(0.2)(x)

works without any issues. I don't quite understand all the details here in the error message. But looks like it's complaining about GPU problems. Any ideas?

Hi, @josiahsrc

Thanks for reporting the issue. The error complains about the RngReadAndSkip op implementation missing from the Tensorflow-metal plugin which prevents the graph from being run on the GPU. We are currently looking into this issue and will update here once we have a solution available.

Unfortunately before that, one has to fall back to running the graph on the CPU when utilizing these layers that are calling on RngReadAndSkip.

RngReadAndSkip is registered on the GPU in tensorflow-metal==0.5.1 which should prevent this error.

Tensorflow 2.6.0 keras image preprocessing doesn't work with metal
 
 
Q