0

I'm trying to run the following code block in my jupyter locally:

import tensorflow as tf
import numpy as np
from tensorflow import keras

Unfortunately, this leads to the problem The kernel appears to have died. It will restart automatically.
I found a lot of questions with the same problem, but no one could help me to solve my issue.
I tried to reinstall all the packages and the anaconda-navigator but it didn't change anything.
Configuration:
Mac M1 with 32GB Ram.

UPDATE:
I tried to run the code from a .pyfile and I got the following error zsh: illegal hardware instruction python fileName.py.

Gothiquo
  • 841
  • 1
  • 8
  • 31
  • Did you install anaconda for silicon macs? Or using a Jupyter kernel in a simple Python instalation? And did you install the tensorflow-macos pip package? – kithuto Mar 10 '23 at 14:13
  • yes I installed anaconda-navigator for MacOS. For tensorflow I installed the package in the first using `pip` and after as in other questions mentioned using ´conda`. – Gothiquo Mar 10 '23 at 14:20

2 Answers2

1

I run some issues with tensorflow and M1 Mac too. I think this will help:

  1. Install anaconda for silicon macs (you already have this)

  2. Download this yml file yml file You can change the python verson in the yml file to your specific python version.

  3. Run this command to create a new enviroment for tensorflow in the path where you installed the yml file:

conda env create -f tensorflow-apple-metal.yml -n tensorflow
  1. Connect to the new enviroment:
conda activate tensorflow
  1. Add this enviroment to the jupyter list:
python -m ipykernel install --user --name tensorflow --display-name "Python 3.10 (tensorflow)"

If you get an error here just install the ipykernel first

conda install ipykernel
  1. Finnaly test it in Jupyter. Run:
jupyter notebook

Now uou can chek if the GPU is working using this lines of code:

import sys

import tensorflow.keras
import pandas as pd
import sklearn as sk
import tensorflow as tf
import platform

print(f"Python Platform: {platform.platform()}")
print(f"Tensor Flow Version: {tf.__version__}")
print(f"Keras Version: {tensorflow.keras.__version__}")
print()
print(f"Python {sys.version}")
print(f"Pandas {pd.__version__}")
print(f"Scikit-Learn {sk.__version__}")
gpu = len(tf.config.list_physical_devices('GPU'))>0
print("GPU is", "available" if gpu else "NOT AVAILABLE")

You can check and follow all this steps in this repository: tensorflow-metal repo

Hope it works for you.

kithuto
  • 455
  • 2
  • 11
  • Unfortunately I received the following error `I tensorflow/core/platform/cpu_feature_guard.cc:193] This TensorFlow binary is optimized with oneAPI Deep Neural Network Library (oneDNN) to use the following CPU instructions in performance-critical operations: SSE4.1 SSE4.2 To enable them in other operations, rebuild TensorFlow with the appropriate compiler flags.` – Gothiquo Mar 10 '23 at 17:16
  • 1
    This is not an error, it’s just telling you that it can and will take advantage of your CPU to get that extra speed. For more details please refer here: https://stackoverflow.com/questions/65298241/what-does-this-tensorflow-message-mean-any-side-effect-was-the-installation-su – kithuto Mar 14 '23 at 12:30
0

Finally I could solve the problem, I hope it could help someone in the future.

So the first thing, the first shown in the first (in jupyter notebook) was unclear and it is just a standard saying that something went wrong, so as I mentioned in my update section, I tried to run the code from a .py file to see the original problem.

So installing anaconda and tensorflow package and then running jupyter will work without any problem for windows maybe but not for MacOSX, so to install it for Mac M1 it could be challenging somehow, I followed this link and I could successfully install it and everything works fine now !

Gothiquo
  • 841
  • 1
  • 8
  • 31