Technical problem

Hello, I installed Tensorflow on my macbook m1 following this method:

However, when I create a machine learning algorithm with tensorflow and keras, I get this message:

2022-12-26 11:16:53.762852: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:306] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support. 2022-12-26 11:16:53.762897: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:272] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 0 MB memory) → physical PluggableDevice (device: 0, name: METAL, pci bus id: )

Metal device set to: Apple M1

What can I do to fix this?

Thanks

@benjsce,

Welcome to the Tensorflow Forum!

Usually, NUMA is a harmless warning. You can safely ignore the above messages. Here I is an information not a warning.

Is there any issue when running the model?

Thank you!

Thanks for your answer.
Yes, I have an error :

when I run this line :

network.fit(train_images, train_labels, epochs=5, batch_size=128)

Jupyter return to me :

Epoch 1/5
2022-12-26 11:17:05.930347: W tensorflow/tsl/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz

ValueError Traceback (most recent call last)
Cell In[6], line 1
----> 1 network.fit(train_images, train_labels, epochs=5, batch_size=128)

File ~/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback..error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.traceback)
68 # To get the full stack trace, call:
69 # tf.debugging.disable_traceback_filtering()
—> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb

File /var/folders/cd/vqmmmfw1095495p3sfn6zgsh0000gn/T/autograph_generated_fileqjyvjr_7.py:15, in outer_factory..inner_factory..tf__train_function(iterator)
13 try:
14 do_return = True
—> 15 retval
= ag
_.converted_call(ag__.ld(step_function), (ag__.ld(self), ag__.ld(iterator)), None, fscope)
16 except:
17 do_return = False

ValueError: in user code:

File "/Users/benjaminscemama/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/engine/training.py", line 1249, in train_function  *
    return step_function(self, iterator)
File "/Users/benjaminscemama/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/engine/training.py", line 1233, in step_function  **
    outputs = model.distribute_strategy.run(run_step, args=(data,))
File "/Users/benjaminscemama/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/engine/training.py", line 1222, in run_step  **
    outputs = model.train_step(data)
File "/Users/benjaminscemama/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/engine/training.py", line 1024, in train_step
    loss = self.compute_loss(x, y, y_pred, sample_weight)
File "/Users/benjaminscemama/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/engine/training.py", line 1082, in compute_loss
    return self.compiled_loss(
File "/Users/benjaminscemama/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/engine/compile_utils.py", line 265, in __call__
    loss_value = loss_obj(y_t, y_p, sample_weight=sw)
File "/Users/benjaminscemama/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/losses.py", line 152, in __call__
    losses = call_fn(y_true, y_pred)
File "/Users/benjaminscemama/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/losses.py", line 284, in call  **
    return ag_fn(y_true, y_pred, **self._fn_kwargs)
File "/Users/benjaminscemama/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/losses.py", line 2004, in categorical_crossentropy
    return backend.categorical_crossentropy(
File "/Users/benjaminscemama/miniconda3/envs/tensorflow/lib/python3.9/site-packages/keras/backend.py", line 5532, in categorical_crossentropy
    target.shape.assert_is_compatible_with(output.shape)

ValueError: Shapes (None, 1) and (None, 10) are incompatible

I don’t understand…

@benjsce,

In order to expedite the trouble-shooting process, please provide a code snippet to reproduce the issue reported here. Thank you!

Here’s the code :

from keras.datasets import mnist
import numpy as np
import tensorflow as tf
from tensorflow.keras import models
from tensorflow.keras import layers

(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

train_images = train_images.reshape((60000, 28*28))
train_images = train_images.astype(‘float32’) / 255

test_images = test_images.reshape((10000,28*28))
test_images = test_images.astype(‘float32’) /255

network = models.Sequential()
network.add(layers.Dense(512, activation=‘relu’, input_shape=(28*28,)))
network.add(layers.Dense(10, activation=‘softmax’))

network.compile(optimizer=‘rmsprop’,
loss = ‘categorical_crossentropy’,
metrics=[‘accurancy’])

network.fit(train_images, train_labels, epochs=5, batch_size=128)

Thank you!

Here the problem is that train_labels has only one column and the model expects output to have 10 , so it is throwing ValueError: Shapes (None, 1) and (None, 10) are incompatible.

You can convert the data labels (i.e.train_labels and test_labels) to categorical values by performing one-hot encoding using tf.keras.utils.to_categorical as shown below

train_labels = tf.keras.utils.to_categorical(train_labels)
test_labels = tf.keras.utils.to_categorical(test_labels)

Second problem was typo in accuracy

Please refer to the working code below

import numpy as np
import tensorflow as tf
print(tf.__version__)
from tensorflow.keras.datasets import mnist
from tensorflow.keras import models
from tensorflow.keras import layers

(train_images, train_labels), (test_images, test_labels) = mnist.load_data()

train_images = train_images.reshape((60000, 28*28))
train_images = train_images.astype("float32") / 255

test_images = test_images.reshape((10000,28*28,1))
test_images = test_images.astype("float32") /255

# Convert the data labels to categorical values by performing one-hot encoding
train_labels = tf.keras.utils.to_categorical(train_labels)
test_labels = tf.keras.utils.to_categorical(test_labels)

network = models.Sequential()
network.add(layers.Dense(512, activation="relu", input_shape=(28*28,)))
network.add(layers.Dense(10, activation="softmax"))

network.compile(optimizer="adam",loss="categorical_crossentropy" ,metrics=["accuracy"])
network.fit(train_images, train_labels, epochs=5, batch_size=128)

Output:

2.11.0 
Downloading data from https://storage.googleapis.com/tensorflow/tf-keras-datasets/mnist.npz 
11490434/11490434 [==============================] - 0s 0us/step 
Epoch 1/5 
469/469 [==============================] - 4s 8ms/step - loss: 0.2630 - accuracy: 0.9253 
Epoch 2/5 
469/469 [==============================] - 4s 8ms/step - loss: 0.1084 - accuracy: 0.9681
Epoch 3/5 
469/469 [==============================] - 4s 9ms/step - loss: 0.0706 - accuracy: 0.9795
Epoch 4/5
469/469 [==============================] - 4s 8ms/step - loss: 0.0514 - accuracy: 0.9849
Epoch 5/5 
469/469 [==============================] - 3s 7ms/step - loss: 0.0377 - accuracy: 0.9887

<keras.callbacks.History at 0x7fb5fa45fa60>

Thank you!

Here is what jupyter returns to me

2.11.0
Epoch 1/5
2022-12-27 20:21:11.583648: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:114] Plugin optimizer for device_type GPU is enabled.
2022-12-27 20:21:11.639007: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at xla_ops.cc:418 : NOT_FOUND: could not find registered platform with id: 0x16790f830
2022-12-27 20:21:11.639030: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at xla_ops.cc:418 : NOT_FOUND: could not find registered platform with id: 0x16790f830
2022-12-27 20:21:11.640562: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at xla_ops.cc:418 : NOT_FOUND: could not find registered platform with id: 0x16790f830
2022-12-27 20:21:11.640575: W tensorflow/core/framework/op_kernel.cc:1830] OP_REQUIRES failed at xla_ops.cc:418 : NOT_FOUND: could not find registered platform with id: 0x16790f830

NotFoundError Traceback (most recent call last)
Cell In[2], line 25
22 network.add(layers.Dense(10, activation=“softmax”))
24 network.compile(optimizer=“adam”,loss=“categorical_crossentropy” ,metrics=[“accuracy”])
—> 25 network.fit(train_images, train_labels, epochs=5, batch_size=128)

File ~/miniforge3/lib/python3.10/site-packages/keras/utils/traceback_utils.py:70, in filter_traceback..error_handler(*args, **kwargs)
67 filtered_tb = _process_traceback_frames(e.traceback)
68 # To get the full stack trace, call:
69 # tf.debugging.disable_traceback_filtering()
—> 70 raise e.with_traceback(filtered_tb) from None
71 finally:
72 del filtered_tb

File ~/miniforge3/lib/python3.10/site-packages/tensorflow/python/eager/execute.py:52, in quick_execute(op_name, num_outputs, inputs, attrs, ctx, name)
50 try:
51 ctx.ensure_initialized()
—> 52 tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name,
53 inputs, attrs, num_outputs)
54 except core._NotOkStatusException as e:
55 if name is not None:

NotFoundError: Graph execution error:

Detected at node ‘StatefulPartitionedCall_2’ defined at (most recent call last):
File “/Users/benjaminscemama/miniforge3/lib/python3.10/runpy.py”, line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File “/Users/benjaminscemama/miniforge3/lib/python3.10/runpy.py”, line 86, in _run_code
exec(code, run_globals)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/ipykernel_launcher.py”, line 17, in
app.launch_new_instance()
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/traitlets/config/application.py”, line 992, in launch_instance
app.start()
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/ipykernel/kernelapp.py”, line 712, in start
self.io_loop.start()
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/tornado/platform/asyncio.py”, line 215, in start
self.asyncio_loop.run_forever()
File “/Users/benjaminscemama/miniforge3/lib/python3.10/asyncio/base_events.py”, line 600, in run_forever
self._run_once()
File “/Users/benjaminscemama/miniforge3/lib/python3.10/asyncio/base_events.py”, line 1896, in _run_once
handle._run()
File “/Users/benjaminscemama/miniforge3/lib/python3.10/asyncio/events.py”, line 80, in _run
self._context.run(self._callback, *self._args)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 510, in dispatch_queue
await self.process_one()
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 499, in process_one
await dispatch(*args)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 406, in dispatch_shell
await result
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/ipykernel/kernelbase.py”, line 730, in execute_request
reply_content = await reply_content
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/ipykernel/ipkernel.py”, line 383, in do_execute
res = shell.run_cell(
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/ipykernel/zmqshell.py”, line 528, in run_cell
return super().run_cell(*args, **kwargs)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 2940, in run_cell
result = self._run_cell(
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 2995, in _run_cell
return runner(coro)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/IPython/core/async_helpers.py”, line 129, in pseudo_sync_runner
coro.send(None)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3194, in run_cell_async
has_raised = await self.run_ast_nodes(code_ast.body, cell_name,
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3373, in run_ast_nodes
if await self.run_code(code, result, async
=asy):
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/IPython/core/interactiveshell.py”, line 3433, in run_code
exec(code_obj, self.user_global_ns, self.user_ns)
File “/var/folders/cd/vqmmmfw1095495p3sfn6zgsh0000gn/T/ipykernel_8524/3824040930.py”, line 25, in
network.fit(train_images, train_labels, epochs=5, batch_size=128)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/utils/traceback_utils.py”, line 65, in error_handler
return fn(*args, **kwargs)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/engine/training.py”, line 1650, in fit
tmp_logs = self.train_function(iterator)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/engine/training.py”, line 1249, in train_function
return step_function(self, iterator)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/engine/training.py”, line 1233, in step_function
outputs = model.distribute_strategy.run(run_step, args=(data,))
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/engine/training.py”, line 1222, in run_step
outputs = model.train_step(data)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/engine/training.py”, line 1027, in train_step
self.optimizer.minimize(loss, self.trainable_variables, tape=tape)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py”, line 527, in minimize
self.apply_gradients(grads_and_vars)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py”, line 1140, in apply_gradients
return super().apply_gradients(grads_and_vars, name=name)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py”, line 634, in apply_gradients
iteration = self._internal_apply_gradients(grads_and_vars)
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py”, line 1166, in _internal_apply_gradients
return tf.internal.distribute.interim.maybe_merge_call(
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py”, line 1216, in _distributed_apply_gradients_fn
distribution.extended.update(
File “/Users/benjaminscemama/miniforge3/lib/python3.10/site-packages/keras/optimizers/optimizer_experimental/optimizer.py”, line 1211, in apply_grad_to_update_var
return self._update_step_xla(grad, var, id(self._var_key(var)))
Node: ‘StatefulPartitionedCall_2’
could not find registered platform with id: 0x16790f830
[[{{node StatefulPartitionedCall_2}}]] [Op:__inference_train_function_1503]

Thank you!

@benjsce,

It seems to be an issue with your tensorflow installation.

Can you install it as suggested Get started with tensorflow-metal ?

Thank you!

I have already downloaded Tensorflow by this way. I uninstall and install again and I have the same results. I did same for python and I checked Python and Tensorflow version. All it right but Tensorflow doesn’t work.

Thank you

@benjsce,

Here the issue with Apple M1 and not with Tensorflow.

Could you please post this issue in the Apple developer forum Apple Developer Forums for quick assistance.

Thank you!