Post

Replies

Boosts

Views

Activity

M1 GPU is extremely slow, how can I enable CPU to train my NNs?
Hi everyone, I found that the performance of GPU is not good as I expected (as slow as a turtle), I wanna switch from GPU to CPU. but mlcompute module cannot be found, so wired. The same code ran on colab and my computer (jupyter lab) take 156s vs 40 minutes per epoch, respectively. I only used a small dataset (a few thousands of data points), and each epoch only have 20 baches. I am so disappointing and it seems like the "powerful" GPU is a joke. I am using 12.0.1 macOS and the version of tensorflow-macos is 2.6.0 Can anyone tell me why this happens?
9
2
13k
Nov ’23
Sklearn is unstable on Apple Silicon
Hi, I installed skearn successfully and ran the MINIST toy example successfully. then I started to run my project. The finning thing everything seems good at the start point (at least no ImportError occurs). but when I made some changes of my code and try to run all cells (I use jupyter lab) again, ImportError occurs..... ImportError: dlopen(/Users/a/miniforge3/lib/python3.9/site-packages/scipy/spatial/qhull.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/liblapack.3.dylib   Referenced from: /Users/a/miniforge3/lib/python3.9/site-packages/scipy/spatial/qhull.cpython-39-darwin.so   Reason: tried: '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/python3.9/site-packages/scipy/spatial/../../../../liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/python3.9/site-packages/scipy/spatial/../../../../liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/bin/../lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/bin/../lib/liblapack.3.dylib' (no such file), '/usr/local/lib/liblapack.3.dylib' (no such file), '/usr/lib/liblapack.3.dylib' (no such file) then I have to uninstall scipy, sklearn, etc and reinstall all of them. and my code can be ran again..... Magically I hate to say, anyone knows how to permanently solve this problem? make skearn more stable?
6
1
9.1k
Oct ’23
Help! Cannot train any NNs with tensorflow on M1 Chip
here is the example code: import sys import time import tensorflow as tf import tensorflow.keras import pandas as pd import sklearn as sk try: import tensorflow_datasets as tfds except: !pip install -q tensorflow_datasets import tensorflow_datasets as tfds import tensorflow.compat.v2 as tf tf.enable_v2_behavior() from tensorflow.python.framework.ops import disable_eager_execution disable_eager_execution() # from tensorflow.python.compiler.mlcompute import mlcompute # mlcompute.set_mlc_device(device_name='gpu') # (mlcompute cannot be found) (ds_train, ds_test), ds_info = tfds.load( 'mnist', split=['train', 'test'], shuffle_files=True, as_supervised=True, with_info=True, ) def normalize_img(image, label): """Normalizes images: `uint8` -> `float32`.""" return tf.cast(image, tf.float32) / 255., label batch_size = 128 ds_train = ds_train.map( normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE) ds_train = ds_train.cache() ds_train = ds_train.shuffle(ds_info.splits['train'].num_examples) ds_train = ds_train.batch(batch_size) ds_train = ds_train.prefetch(tf.data.experimental.AUTOTUNE) ds_test = ds_test.map( normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE) ds_test = ds_test.batch(batch_size) ds_test = ds_test.cache() ds_test = ds_test.prefetch(tf.data.experimental.AUTOTUNE) model = tf.keras.models.Sequential([ tf.keras.layers.Conv2D(32, kernel_size=(3, 3), activation='relu'), tf.keras.layers.Conv2D(64, kernel_size=(3, 3), activation='relu'), tf.keras.layers.MaxPooling2D(pool_size=(2, 2)), # tf.keras.layers.Dropout(0.25), tf.keras.layers.Flatten(), tf.keras.layers.Dense(128, activation='relu'), # tf.keras.layers.Dropout(0.5), tf.keras.layers.Dense(10, activation='softmax') ]) model.compile( loss='sparse_categorical_crossentropy', optimizer=tf.keras.optimizers.Adam(0.001), metrics=['accuracy'], ) start_time = time.time() model.fit( ds_train, epochs=10, validation_data=ds_test, ) print("--- %s minutes with GPU ---" % ((time.time() - start_time)/60)) here are the outputs: commenting from tensorflow.python.framework.ops import disable_eager_execution disable_eager_execution() kernel died: Metal device set to: Apple M1 Pro systemMemory: 16.00 GB maxCacheSize: 5.33 GB Epoch 1/10 2021-10-31 19:10:20.277599: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE4.2 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2021-10-31 19:10:20.278606: 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-10-31 19:10:20.279185: 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>) with from tensorflow.python.framework.ops import disable_eager_execution disable_eager_execution() RuntimeError: Caught an unknown exception!: I installed tensorflow-macos and tensorflow-metal by following https://developer.apple.com/metal/tensorflow-plugin/ I am struggling of using tensorflow on new MBP for many days and it just totally a nightmare. I met tons of issues, searched ways to solved them and tried tons of methods and none of them can really help me to train a NN. Honestly, I am out of patience right now. I brought MBP as I suppose it can facilitate my work and it turns out I even can use tensorflow! so ridiculous! Tensorflow: 2.6.0 Keras Version: 2.6.0 Python 3.8.12 macOS: 12.0.1 Anaconda: 2.0.3 tensorflow-macos: 2.6.0 tensorflow-metal: 0.2.0
2
0
1.7k
Apr ’23
tensorflow-macos cannot be installed on Python 3.8 virtual environment
I followed this guideline to install TensorFlow: https://developer.apple.com/metal/tensorflow-plugin/ and run example code on miniforge3 base environment, but importing the numpy C-extensions failed. because  * The Python version is: Python3.9 The NumPy version is: "1.19.5" then I tried to create a new conda environment with python 3.8, and then tried to install tensorflow-macos, but it failed because of grpcio cannot be installed. so in this case, how can I solve this problem?
2
0
2k
Dec ’21
M1 GPU is extremely slow, how can I enable CPU to train my NNs?
Hi everyone, I found that the performance of GPU is not good as I expected (as slow as a turtle), I wanna switch from GPU to CPU. but mlcompute module cannot be found, so wired. The same code ran on colab and my computer (jupyter lab) take 156s vs 40 minutes per epoch, respectively. I only used a small dataset (a few thousands of data points), and each epoch only have 20 baches. I am so disappointing and it seems like the "powerful" GPU is a joke. I am using 12.0.1 macOS and the version of tensorflow-macos is 2.6.0 Can anyone tell me why this happens?
Replies
9
Boosts
2
Views
13k
Activity
Nov ’23
Sklearn is unstable on Apple Silicon
Hi, I installed skearn successfully and ran the MINIST toy example successfully. then I started to run my project. The finning thing everything seems good at the start point (at least no ImportError occurs). but when I made some changes of my code and try to run all cells (I use jupyter lab) again, ImportError occurs..... ImportError: dlopen(/Users/a/miniforge3/lib/python3.9/site-packages/scipy/spatial/qhull.cpython-39-darwin.so, 0x0002): Library not loaded: @rpath/liblapack.3.dylib   Referenced from: /Users/a/miniforge3/lib/python3.9/site-packages/scipy/spatial/qhull.cpython-39-darwin.so   Reason: tried: '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/python3.9/site-packages/scipy/spatial/../../../../liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/python3.9/site-packages/scipy/spatial/../../../../liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/bin/../lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/lib/liblapack.3.dylib' (no such file), '/Users/a/miniforge3/bin/../lib/liblapack.3.dylib' (no such file), '/usr/local/lib/liblapack.3.dylib' (no such file), '/usr/lib/liblapack.3.dylib' (no such file) then I have to uninstall scipy, sklearn, etc and reinstall all of them. and my code can be ran again..... Magically I hate to say, anyone knows how to permanently solve this problem? make skearn more stable?
Replies
6
Boosts
1
Views
9.1k
Activity
Oct ’23
Help! Cannot train any NNs with tensorflow on M1 Chip
here is the example code: import sys import time import tensorflow as tf import tensorflow.keras import pandas as pd import sklearn as sk try: import tensorflow_datasets as tfds except: !pip install -q tensorflow_datasets import tensorflow_datasets as tfds import tensorflow.compat.v2 as tf tf.enable_v2_behavior() from tensorflow.python.framework.ops import disable_eager_execution disable_eager_execution() # from tensorflow.python.compiler.mlcompute import mlcompute # mlcompute.set_mlc_device(device_name='gpu') # (mlcompute cannot be found) (ds_train, ds_test), ds_info = tfds.load( 'mnist', split=['train', 'test'], shuffle_files=True, as_supervised=True, with_info=True, ) def normalize_img(image, label): """Normalizes images: `uint8` -> `float32`.""" return tf.cast(image, tf.float32) / 255., label batch_size = 128 ds_train = ds_train.map( normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE) ds_train = ds_train.cache() ds_train = ds_train.shuffle(ds_info.splits['train'].num_examples) ds_train = ds_train.batch(batch_size) ds_train = ds_train.prefetch(tf.data.experimental.AUTOTUNE) ds_test = ds_test.map( normalize_img, num_parallel_calls=tf.data.experimental.AUTOTUNE) ds_test = ds_test.batch(batch_size) ds_test = ds_test.cache() ds_test = ds_test.prefetch(tf.data.experimental.AUTOTUNE) model = tf.keras.models.Sequential([ tf.keras.layers.Conv2D(32, kernel_size=(3, 3), activation='relu'), tf.keras.layers.Conv2D(64, kernel_size=(3, 3), activation='relu'), tf.keras.layers.MaxPooling2D(pool_size=(2, 2)), # tf.keras.layers.Dropout(0.25), tf.keras.layers.Flatten(), tf.keras.layers.Dense(128, activation='relu'), # tf.keras.layers.Dropout(0.5), tf.keras.layers.Dense(10, activation='softmax') ]) model.compile( loss='sparse_categorical_crossentropy', optimizer=tf.keras.optimizers.Adam(0.001), metrics=['accuracy'], ) start_time = time.time() model.fit( ds_train, epochs=10, validation_data=ds_test, ) print("--- %s minutes with GPU ---" % ((time.time() - start_time)/60)) here are the outputs: commenting from tensorflow.python.framework.ops import disable_eager_execution disable_eager_execution() kernel died: Metal device set to: Apple M1 Pro systemMemory: 16.00 GB maxCacheSize: 5.33 GB Epoch 1/10 2021-10-31 19:10:20.277599: I tensorflow/core/platform/cpu_feature_guard.cc:142] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE4.2 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags. 2021-10-31 19:10:20.278606: 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-10-31 19:10:20.279185: 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>) with from tensorflow.python.framework.ops import disable_eager_execution disable_eager_execution() RuntimeError: Caught an unknown exception!: I installed tensorflow-macos and tensorflow-metal by following https://developer.apple.com/metal/tensorflow-plugin/ I am struggling of using tensorflow on new MBP for many days and it just totally a nightmare. I met tons of issues, searched ways to solved them and tried tons of methods and none of them can really help me to train a NN. Honestly, I am out of patience right now. I brought MBP as I suppose it can facilitate my work and it turns out I even can use tensorflow! so ridiculous! Tensorflow: 2.6.0 Keras Version: 2.6.0 Python 3.8.12 macOS: 12.0.1 Anaconda: 2.0.3 tensorflow-macos: 2.6.0 tensorflow-metal: 0.2.0
Replies
2
Boosts
0
Views
1.7k
Activity
Apr ’23
tensorflow-macos cannot be installed on Python 3.8 virtual environment
I followed this guideline to install TensorFlow: https://developer.apple.com/metal/tensorflow-plugin/ and run example code on miniforge3 base environment, but importing the numpy C-extensions failed. because  * The Python version is: Python3.9 The NumPy version is: "1.19.5" then I tried to create a new conda environment with python 3.8, and then tried to install tensorflow-macos, but it failed because of grpcio cannot be installed. so in this case, how can I solve this problem?
Replies
2
Boosts
0
Views
2k
Activity
Dec ’21