TensorFlow accelerates machine learning model training with Metal on Mac GPUs.

tensorflow-metal Documentation

Posts under tensorflow-metal tag

61 results found
Sort by:
Post not yet marked as solved
132 Views

Tensorflow metal keeps killing python

Hi, I've run into some issue with TensorFlow-metal on my Mac M1. After installing TensorFlow-metal following the official steps in my Conda environment (Miniforge), when I try to import TensorFlow, independently from which python version I use, the "import TensorFlow" command keeps killing the process (import tensorflow killed python) any idea why this is happening? I tried different version of tensorflow-deps (both 2.5.0 and 2.6.0) and the outcome is exactly the same. Thank you! I forgot to mention that I tried a fresh installation of everything I could, including the OS too.
Asked
by GG_85.
Last updated
.
Post not yet marked as solved
246 Views

Cannot install Tensorflow on Mac m1

I try to install and fix the tensorflow on my new Mac m1 following a lot the instuctions in the internet but it's not work. The kernel will died when try to import tensorflow. `(tensorflow-metal) ampnapat@Amps-MacBook-Pro ~ % python -m pip install tensorflow-macos ERROR: Could not find a version that satisfies the requirement tensorflow-macos (from versions: none) ERROR: No matching distribution found for tensorflow-macos (tensorflow-metal) ampnapat@Amps-MacBook-Pro ~ % python -m pip install tensorflow-metal ERROR: Could not find a version that satisfies the requirement tensorflow-metal (from versions: none) ERROR: No matching distribution found for tensorflow-metal`
Asked
by ampampamp.
Last updated
.
Post not yet marked as solved
406 Views

Tensorflow-macos cannot stay with PyQt5 and opencv-python

Tensorflow-macos v2.5 does run on my M1 MacBook Pro by downloading the Apple tensorflow deps and conda env. However, when I download the PyQt5 package, the ERROR: PyQt5 has a pyproject.toml file that does not comply with PEP 518: 'build-system.requires' contains an invalid requirement: 'sip >=5.0.1 <6' apears while I can install qt5 directly without the tensorflow deps. Error also comes out when I re-installing numpy whose version is specifically asked by tensorflow-macos (why re-install: opencv automatically unistall the tensorflow's numpy and installs another which tensorflow-macos cannot use), showing Could not build wheels for numpy which use PEP 517 and cannot be installed directly. What should I do? The only way I can fix the problem by myself is to clear the conda env and install deps, tensorflow, metal pkg etc. once again and avoid the using of qt5 and deleting of original numpy. What a bad experience.
Asked
by EricWXZ.
Last updated
.
Post not yet marked as solved
256 Views

Tensorflow_macos performance between python 3.9 and 3.8

Hi team, It's nice that tensorflow can now running on my MacBook Air M1 (macOS 12). Have tried it on python 3.9 and 3.8. Comparing the performance, looks 3.8 version release by apple team is much faster. See below: Code for testing: import tensorflow as tf import time mnist = tf.keras.datasets.mnist (x_train, y_train),(x_test, y_test) = mnist.load_data() x_train, x_test = x_train / 255.0, x_test / 255.0 model = tf.keras.models.Sequential([ tf.keras.layers.Flatten(input_shape=(28, 28)), tf.keras.layers.Dense(128, activation='relu'), tf.keras.layers.Dropout(0.2), tf.keras.layers.Dense(10, activation='softmax') ]) model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy']) start = time.time() model.fit(x_train, y_train, epochs=5) end = time.time() model.evaluate(x_test, y_test) print(end - start) below is result of python 3.9, tensorflow-macos released from google team. using tensorflow-metal. Init Plugin Init Graph Optimizer Init Kernel Metal device set to: Apple M1 systemMemory: 16.00 GB maxCacheSize: 5.33 GB 2021-08-26 23:05:31.742656: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support. 2021-08-26 23:05:31.742796: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] 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: <undefined>) 2021-08-26 23:05:31.982641: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2) 2021-08-26 23:05:31.984696: W tensorflow/core/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz Epoch 1/5 2021-08-26 23:05:32.121772: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:112] Plugin optimizer for device_type GPU is enabled. 1875/1875 [==============================] - 8s 4ms/step - loss: 0.2914 - accuracy: 0.9160 Epoch 2/5 1875/1875 [==============================] - 8s 4ms/step - loss: 0.1454 - accuracy: 0.9569 Epoch 3/5 1875/1875 [==============================] - 8s 4ms/step - loss: 0.1104 - accuracy: 0.9669 Epoch 4/5 1875/1875 [==============================] - 8s 4ms/step - loss: 0.0878 - accuracy: 0.9728 Epoch 5/5 1875/1875 [==============================] - 8s 5ms/step - loss: 0.0756 - accuracy: 0.9764 2021-08-26 23:06:13.969665: I tensorflow/core/grappler/optimizers/custom_graph_optimizer_registry.cc:112] Plugin optimizer for device_type GPU is enabled. 313/313 [==============================] - 1s 4ms/step - loss: 0.0814 - accuracy: 0.9752 42.12474703788757 below is result of python 3.8. tensorflow-macos released from apple team. 2021-08-26 23:06:40.105911: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:116] None of the MLIR optimization passes are enabled (registered 2) 2021-08-26 23:06:40.106407: W tensorflow/core/platform/profile_utils/cpu_utils.cc:126] Failed to get CPU frequency: 0 Hz Epoch 1/5 1875/1875 [==============================] - 1s 382us/step - loss: 0.5059 - accuracy: 0.8497 Epoch 2/5 1875/1875 [==============================] - 1s 380us/step - loss: 0.1957 - accuracy: 0.9406 Epoch 3/5 1875/1875 [==============================] - 1s 375us/step - loss: 0.1563 - accuracy: 0.9522 Epoch 4/5 1875/1875 [==============================] - 1s 375us/step - loss: 0.1336 - accuracy: 0.9596 Epoch 5/5 1875/1875 [==============================] - 1s 418us/step - loss: 0.1213 - accuracy: 0.9633 313/313 [==============================] - 0s 255us/step - loss: 0.0831 - accuracy: 0.9741 3.882438898086548 As you can see the result is quite different. Almost 14 times... python 3.9 version: 42.12s python 3.8 version: 3.88s Understand python 3.8 version is used "ML compute", is trained very faster. Is it possible to make it on python 3.9 ? or anyway I can find some reference to do it ? On the other hand, the reason needs to use python 3.9 is error occur when using "class_weight" on tensorflow classification mode. can refer to this GitHub issue 275 can you pls maybe give me a guide ? Thanks in advance.
Asked
by cb0207.
Last updated
.
Post not yet marked as solved
70 Views

Not able to import tensorflow

Not able to import tensorflow, Even after following all the steps mentioned in https://developer.apple.com/metal/tensorflow-plugin/. All packages were installed correctly wheel-0.37.0     | 33 KB   | ##################################### | 100%  requests-2.26.0   | 59 KB   | ##################################### | 100%  charset-normalizer-2 | 35 KB   | ##################################### | 100%  tzdata-2021a     | 111 KB  | ##################################### | 100%  sqlite-3.36.0    | 1.1 MB  | ##################################### | 100%  setuptools-52.0.0  | 713 KB  | ##################################### | 100%  libiconv-1.16    | 700 KB  | ##################################### | 100%  xz-5.2.5       | 238 KB  | ##################################### | 100%  pycparser-2.20    | 94 KB   | ##################################### | 100%  brotlipy-0.7.0    | 308 KB  | ##################################### | 100%  openssl-1.1.1j    | 2.2 MB  | ##################################### | 100%  expat-2.4.1     | 123 KB  | ##################################### | 100%  cryptography-3.4.7  | 717 KB  | ##################################### | 100%  pysocks-1.7.1    | 28 KB   | ##################################### | 100%  ncurses-6.2     | 711 KB  | ##################################### | 100%  libcxx-12.0.0    | 793 KB  | ##################################### | 100%  cffi-1.14.5     | 214 KB  | ##################################### | 100%  pycosat-0.6.3    | 80 KB   | ##################################### | 100%  yaml-0.2.5      | 71 KB   | ##################################### | 100%  readline-8.1     | 356 KB  | ##################################### | 100%  python-3.9.7     | 9.6 MB  | ##################################### | 100%  ruamel_yaml-0.15.100 | 238 KB  | ##################################### | 100%  zlib-1.2.11     | 83 KB   | ##################################### | 100%  conda-package-handli | 1.4 MB  | ##################################### | 100%  urllib3-1.26.6    | 112 KB  | ##################################### | 100%  libffi-3.3      | 103 KB  | ##################################### | 100%  idna-3.2       | 48 KB   | ##################################### | 100%  tqdm-4.62.2     | 96 KB   | ##################################### | 100%  tk-8.6.10      | 2.9 MB  | ##################################### | 100%  pyopenssl-20.0.1   | 49 KB   | ##################################### | 100%  six-1.16.0
Asked
by rahul_m01.
Last updated
.
Post not yet marked as solved
99 Views

Weird behavior of tensorflow-metal on M1 Mac with Object Detection API

Recently days, I installed tensorflow-metal in my M1 MacBook Pro (macOS 12 beta 12.0) following this tutorial. And then, I run TF2's Object Detection API script from this repository karaage0703/object_detection_tools. It did great work with apple/tensorflow_macos. But with tensorflow-metal, the accuracies of objects are over 100%. How can I solve this problem? Thank you.
Asked Last updated
.
Post not yet marked as solved
147 Views

error:fail of building wheel for grpcio

I follow the step of installing tensorflow on MacBook Pro M1. https://developer.apple.com/metal/tensorflow-plugin/ When i install the base tensorflow, it keep on showing the error: fail of building wheel for grpcio. I has updated my setuptools, pip, and grpcio to the latest version but it still not work. My python version is 3.9.6. How can i install tensorflow successfully?
Asked
by frankiexe.
Last updated
.
Post marked as solved
102 Views

Using multiple GPUs in Tensorflow-mac for M1

It's clearly stated at https://developer.apple.com/metal/tensorflow-plugin/ that multiple GPUs are still not supported by Tensorflow-mac, but I've toying around with some examples and benchmarking it's performance against Colab and Intel/NVIDIA setups and got this testing a NLP classification task (time per epoch while training, smaller is better): My question is: can we expect, once multi-GPU is available for the M1, an increase in performance - maybe close to 8x if the 8 GPU cores become available, and would the GPU cores will be seen as a single GPU as the NVIDIA cards or we will need to use a distribution strategy to be able to use them in parallel? Thanks!
Asked
by eduardofv.
Last updated
.
Post not yet marked as solved
414 Views

Is it possible to use HuggingFace via TF-macOS and TF-Metal?

Dear All Developers, It is so great that we finally have TF-macOS and TF-Metal for GPU/NPU accelerating. After some tests, it looks like everything works well. So, I am wondering that if it is possible to solve NLP tasks with HuggingFace via TF-Metal for GPU accelerating. To figure it out, I installed all packages we need and ran the testing code. What I got is showing here. So far so good, right? However, it pops out an error while I attempt to fine-tune a BERT model. 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_=[] RealDiv: GPU CPU Sqrt: GPU CPU UnsortedSegmentSum: CPU AssignVariableOp: GPU CPU AssignSubVariableOp: GPU CPU ReadVariableOp: GPU CPU StridedSlice: GPU CPU NoOp: GPU CPU Mul: GPU CPU Shape: GPU CPU _Arg: GPU CPU ResourceScatterAdd: GPU CPU Unique: CPU AddV2: GPU CPU ResourceGather: GPU CPU Const: GPU CPU It looks like that GPU is not assigned correctly, therefore, I checked if GPU is detected by TensorFlow. And here is the GPU info. from TensorFlow. WARNING:tensorflow:From <ipython-input-2-17bb7203622b>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version. Instructions for updating: Use `tf.config.list_physical_devices('GPU')` instead. WARNING:tensorflow:From <ipython-input-2-17bb7203622b>:1: is_gpu_available (from tensorflow.python.framework.test_util) is deprecated and will be removed in a future version. Instructions for updating: Use `tf.config.list_physical_devices('GPU')` instead. 2021-06-29 01:56:25.862829: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support. 2021-06-29 01:56:25.862893: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] Created TensorFlow device (/device:GPU:0 with 0 MB memory) -> physical PluggableDevice (device: 0, name: METAL, pci bus id: <undefined>) Out[2]: True Obviously, the problem resulted from HuggingFace. I do know that it is not Apple's responsibility to packages other than TF-macOS and TF-Metal, I am just curious that if anyone has a solution about it here. Sincerely, hawkiyc
Asked
by hawkiyc.
Last updated
.
Post not yet marked as solved
402 Views

🤔 GitHub tensorflow macOS alpha had better performance on M1?

Hello, I noticed a substantial decrease in performance compared to previous releases of tensorflow for M1 Macs. I previously installed the alpha release of tensorflow for M1 from GitHub, found here: https://github.com/apple/tensorflow_macos and was very impressed by the performance. I used the following script to benchmark my M1 Mac and other systems: https://gist.github.com/tampapath/662aca8cd0ef6790ade1bf3c23fe611a#file-fashin_mnist-py Running the alpha release from GitHub, my M1 Mac handsomely outperformed both google colab's random GPU offerings and an RTX 2070 windows computer. Recently, I went back to the GitHub repository, looking for new updates on tensorflow support for the M1 and was redirected here to the tensorflow-metal PluggableDevices installation guide: https://developer.apple.com/metal/tensorflow-plugin/ After installing the conda environment and running the same benchmark script, I realized my M1 systems's was running much slower. Additionally, the following error messages printed to the console while running the benchmark: 2021-08-12 21:48:16.306946: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:305] Could not identify NUMA node of platform GPU ID 0, defaulting to 0. Your kernel may not have been built with NUMA support. 2021-08-12 21:48:16.307209: I tensorflow/core/common_runtime/pluggable_device/pluggable_device_factory.cc:271] 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: <undefined>) 2021-08-12 21:48:16.437942: I tensorflow/compiler/mlir/mlir_graph_optimization_pass.cc:176] None of the MLIR Optimization Passes are enabled (registered 2) 2021-08-12 21:48:16.441196: W tensorflow/core/platform/profile_utils/cpu_utils.cc:128] Failed to get CPU frequency: 0 Hz Has anyone else noticed this loss in performance? The results I got are as follow: benchmark script duration tf GitHub alpha 🟢 9.62s new tf-metal 🔴 76.52s google colab 🔴 57.53s RTX 2070 PC 🔴 23.18s both tf GitHub alpha and new tf-metal were ran on the same 13" M1 MacBook Pro. I wrote an installation guide for the GitHub alpha release if anyone wants to compare results, or run a faster version of tensorflow compatible with their M1 Mac: https://github.com/apple/tensorflow_macos/issues/215
Asked Last updated
.
Post not yet marked as solved
143 Views

Tensorflow

Is Tensorflow metal supported on Apple Silicon Macs?
Asked
by SULTAN_95.
Last updated
.
Post not yet marked as solved
421 Views

Memory leak with tensorflow-metal

I am trying the new tensorflow-metal release. The good news is that I see a boost in speed when executing my models. The bad news is that whenever it I run it, it leaks memory. So if I run the prediction 1000x I end up with 50GB of memory usage and eventually run out. The same code works when using stock tensorflow, albeit slower. I tried using pympler to find a leak, but the output didn't really look different between tensorflow-metal and normal tensorflow. I suspect the leak is in native code, so that wouldn't really help. Known issue? Ideas on how to debug? Open to anything really.
Asked
by dandiep.
Last updated
.
Post marked as solved
2.6k Views

I can't install TensorFlow-macos and TensorFlow-metal

Dear All, I am a Data Scientist and waiting for GPU accelerating for years, and I am thrilled while Apple announced it will come at MacOS 12. linkText And so, I updated my OS to Monterey Beta and tried to install TensorFlow-Metal a few days ago. However, all installing instruction commands not work at all. After that, I looked into pypi.org and found out there are whl files for TensorFlow-macos and TensorFlow-metal. So, I tried to pip install both whl files. Yet, noting work again. Here is the screenshot for installing. I would very much appreciate if you can help me to solve this issue. Sincerely,
Asked
by hawkiyc.
Last updated
.
Post not yet marked as solved
535 Views

tensorflow-metal and other Conda packages

Hi there, I installed tensorflow-metal as per this tutorial.. That installation process seems to have worked fine. However, I'm now having trouble creating new Conda envs. The problem seems to be with the version of Conda -- Miniforge -- which Apple's tutorial instructed me to install. So, this command: conda create --name my_env python=3.7 -c defaults -c conda-forge --file requirements/conda.txt Results in this error: PackagesNotFoundError: The following packages are not available from current channels: - keras==2.3.1 - python=3.7 - scikit-geometry[version='>=0.1.2'] - tesserocr[version='>=2.5.1'] Current channels: - https://repo.anaconda.com/pkgs/main/osx-arm64 - https://repo.anaconda.com/pkgs/main/noarch - https://repo.anaconda.com/pkgs/r/osx-arm64 - https://repo.anaconda.com/pkgs/r/noarch - https://conda.anaconda.org/conda-forge/osx-arm64 - https://conda.anaconda.org/conda-forge/noarch When I was using Miniconda, I had no problems installing these packages. It's only a problem now that I'm using Miniforge (as per Apple's tutorial). (My best guess at what's going wrong: this Miniforge installation is only looking for ARM packages, whereas my previous Miniconda installation was looking for x86-64 packages as well. If I'm correct, does that mean I can't use TensorFlow-Metal alongside these x86-64 packages?) Thanks! Jack
Asked
by JSR694.
Last updated
.
Post not yet marked as solved
166 Views

Cannot assign a device for operation ReadVariableOp

Hello, I cannot predict with my model on Apple M1. I get a error: Traceback (most recent call last):   File "/Users/martin/Documents/Projects/rl-toolkit/rl_toolkit/__main__.py", line 154, in <module>     agent.run()   File "/Users/martin/Documents/Projects/rl-toolkit/rl_toolkit/training.py", line 213, in run     losses = self._train(sample)   File "/Users/martin/miniforge3/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py", line 889, in __call__     result = self._call(*args, **kwds)   File "/Users/martin/miniforge3/lib/python3.9/site-packages/tensorflow/python/eager/def_function.py", line 950, in _call     return self._stateless_fn(*args, **kwds)   File "/Users/martin/miniforge3/lib/python3.9/site-packages/tensorflow/python/eager/function.py", line 3023, in __call__     return graph_function._call_flat(   File "/Users/martin/miniforge3/lib/python3.9/site-packages/tensorflow/python/eager/function.py", line 1960, in _call_flat     return self._build_call_outputs(self._inference_function.call(   File "/Users/martin/miniforge3/lib/python3.9/site-packages/tensorflow/python/eager/function.py", line 591, in call     outputs = execute.execute(   File "/Users/martin/miniforge3/lib/python3.9/site-packages/tensorflow/python/eager/execute.py", line 59, in quick_execute     tensors = pywrap_tfe.TFE_Py_Execute(ctx._handle, device_name, op_name, tensorflow.python.framework.errors_impl.InvalidArgumentError: Cannot assign a device for operation ReadVariableOp: Could not satisfy explicit device specification '' because the node {{colocation_node ReadVariableOp}} 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_=[] ResourceApplyAdamWithAmsgrad: CPU  ReadVariableOp: GPU CPU  _Arg: GPU CPU  Colocation members, user-requested devices, and framework assigned devices, if any:   readvariableop_resource (_Arg)  framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0   adam_2_adam_update_6_resourceapplyadamwithamsgrad_m (_Arg)  framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0   adam_2_adam_update_6_resourceapplyadamwithamsgrad_v (_Arg)  framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0   adam_2_adam_update_6_resourceapplyadamwithamsgrad_vhat (_Arg)  framework assigned device=/job:localhost/replica:0/task:0/device:GPU:0   ReadVariableOp (ReadVariableOp)    Exp/ReadVariableOp (ReadVariableOp)    ReadVariableOp_1 (ReadVariableOp)    actor/ReadVariableOp (ReadVariableOp)    actor/Exp/ReadVariableOp (ReadVariableOp)    actor/ReadVariableOp_1 (ReadVariableOp)    actor_critic/actor/ReadVariableOp (ReadVariableOp)    actor_critic/actor/Exp/ReadVariableOp (ReadVariableOp)    actor_critic/actor/ReadVariableOp_1 (ReadVariableOp)    Adam_2/Adam/update_6/ResourceApplyAdamWithAmsgrad (ResourceApplyAdamWithAmsgrad) /job:localhost/replica:0/task:0/device:GPU:0 [[{{node ReadVariableOp}}]] [Op:__inference__train_4206]
Asked Last updated
.