Error in Tensorflow on M1

Hi. I work on M1 pro Mac (macOS 12.0.1) and try to use tensorflow-metal. I followed the guide in https://developer.apple.com/metal/tensorflow-plugin/ but I received the following errors when I imported tensorflow: RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf

RuntimeError: module compiled against API version 0x10 but this version of numpy is 0xf

ImportError: numpy.core._multiarray_umath failed to import

ImportError: numpy.core.umath failed to import

Traceback (most recent call last):

  File "", line 1, in

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/init.py", line 37, in

    from tensorflow.python.tools import module_util as _module_util

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/init.py", line 42, in

    from tensorflow.python import data

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/data/init.py", line 21, in

    from tensorflow.python.data import experimental

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/data/experimental/init.py", line 96, in

    from tensorflow.python.data.experimental import service

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/data/experimental/service/init.py", line 419, in

    from tensorflow.python.data.experimental.ops.data_service_ops import distribute

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/data/experimental/ops/data_service_ops.py", line 22, in

    from tensorflow.python.data.experimental.ops import compression_ops

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/data/experimental/ops/compression_ops.py", line 16, in

    from tensorflow.python.data.util import structure

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/data/util/structure.py", line 22, in

    from tensorflow.python.data.util import nest

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/data/util/nest.py", line 34, in

    from tensorflow.python.framework import sparse_tensor as _sparse_tensor

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/framework/sparse_tensor.py", line 24, in

    from tensorflow.python.framework import constant_op

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/framework/constant_op.py", line 25, in

    from tensorflow.python.eager import execute

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/eager/execute.py", line 21, in

    from tensorflow.python.framework import dtypes

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/framework/dtypes.py", line 34, in

    _np_bfloat16 = _pywrap_bfloat16.TF_bfloat16_type()

TypeError: Unable to convert function return value to a Python type! The signature was

() -> handle

After upgrade numpy by "pip install numpy --upgrade", I received the following error: Traceback (most recent call last):

  File "", line 1, in

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/init.py", line 440, in

    _ll.load_library(_plugin_dir)

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/framework/load_library.py", line 151, in load_library

    py_tf.TF_LoadLibrary(lib)

tensorflow.python.framework.errors_impl.NotFoundError: dlopen(/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow-plugins/libmetal_plugin.dylib, 0x0006): Symbol not found: OBJC_CLASS$_MPSGraphRandomOpDescriptor

  Referenced from: /Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow-plugins/libmetal_plugin.dylib

  Expected in: /System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Versions/A/MetalPerformanceShadersGraph

I also tried the solution in https://developer.apple.com/forums/thread/706219, but I still received the following error:

Traceback (most recent call last):

  File "", line 1, in

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/init.py", line 440, in

    _ll.load_library(_plugin_dir)

  File "/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow/python/framework/load_library.py", line 151, in load_library

    py_tf.TF_LoadLibrary(lib)

tensorflow.python.framework.errors_impl.NotFoundError: dlopen(/Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow-plugins/libmetal_plugin.dylib, 0x0006): Symbol not found: OBJC_CLASS$_MPSGraphRandomOpDescriptor

  Referenced from: /Users/bseo/miniconda/lib/python3.9/site-packages/tensorflow-plugins/libmetal_plugin.dylib

  Expected in: /System/Library/Frameworks/MetalPerformanceShadersGraph.framework/Versions/A/MetalPerformanceShadersGraph

How can I fix this error? Many thanks in advance!

The problem is with the tensorflow-deps version. If I'm not wrong, you have tensorflow-deps==2.9.0 and tensorflow-macos==2.10.0 or tensorflow-macos==2.11.0. The problem is conda install -c apple tensorflow-deps installs 2.9.0. You can download the 2.10.0 from https://anaconda.org/apple/tensorflow-deps/files to get dependencies for tensorflow-macos 2.10.0. As of now, there are no dependencies available for 2.11.0.

Hi @bseo

Thanks for reporting this issue and thanks to @Imperfect8747 for providing the solution. There seems to be an issue downloading the up-to-date version of tensorflow-deps using miniconda (miniforge seems to work fine for me). We are investigating the reason for this but in the meanwhile downloading and installing manually from the link they provided in their answer should fix the issue. Let us know if the issue still persists.

Hi. I have resolved issue by updating my macOS from 12.0.1 to 13.0.1 Ventura. I referred to https://stackoverflow.com/questions/73448137/why-i-have-import-error-mac-m1-when-i-use-tensorflow. After updating my macOS, it works just fine. By the way, I think this issue has to be inspected thoroughly because the apple's guide (https://developer.apple.com/metal/tensorflow-plugin/) request 12.0 or higher but mine was 12.0.1 already.

Error in Tensorflow on M1
 
 
Q