kernel dead in using pytorch - python

The kernel crashes when I run a simple code using pytorch (even though it's not used here).
import numpy as np
import matplotlib.pyplot as plt
import torch
x=np.arange(0,10,0.1)
plt.plot(x,np.sin(x))
plt.show()
When I run this code on Jupyter, it shows the kernel is dead. When I run it on Visual Code, it shows:
Canceled future for execute_request message before replies were done
The Kernel crashed while executing code in the the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click here for more info. View Jupyter log for further details.
How to resolve this issue. The torch package is supposed to be used later.

This problem has been solved by updating the numpy and matplotlib packages. These packages were installed just one year ago, though.

Related

Jupyter Notebook matplotlib causes "kernel appears to have died"

I am new to Python and Jupyter Notebook. I have Anaconda installed on my Windows 11 computer. I am running Jupyter Notebook in a virtual environent. The problem I'm encountering happens when I attempt to run the following...
import torch
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
import torch.nn as nn
X = torch.linspace(1,50,50).reshape(-1,1)
torch.manual_seed(71)
e = torch.randint(-8,9,(50,1),dtype=torch.float)
y = 2*X + 1 + e
plt.scatter(X.numpy(),y.numpy())
The error I get is
"The kernel appears to have died. It will restart automatically."
I think I have narrowed the issue down to matplotlib, as it is the only new element I have imported, and only the cell referencing "plt.scatter" causes the kernel to die.
I have tried the following solutions
Run Anaconda Prompt as administrator
conda install --yes freetype=2.10.4
which results in
"# All requested packages already installed."
I also tried
conda update mkl
printing 'Hello World' works fine, as does using numpy and torch from what I can tell.
It's worth mentioning that when the kernel dies, my command window shows the following:
[I 16:30:08.979 NotebookApp] Kernel started: 503c71ae-ced0-4147-8f23-7cdad416d503, name: python3
OMP: Error #15: Initializing libiomp5md.dll, but found libiomp5md.dll already initialized.
OMP: Hint This means that multiple copies of the OpenMP runtime have been linked into the program. That is dangerous, since it can degrade performance or cause incorrect results. The best thing to do is to ensure that only a single OpenMP runtime is linked into the process, e.g. by avoiding static linking of the OpenMP runtime in any library. As an unsafe, unsupported, undocumented workaround you can set the environment variable KMP_DUPLICATE_LIB_OK=TRUE to allow the program to continue to execute, but that may cause crashes or silently produce incorrect results. For more information, please see http://www.intel.com/software/products/support/.
[I 16:30:23.983 NotebookApp] KernelRestarter: restarting kernel (1/5), new random ports
WARNING:root:kernel 503c71ae-ced0-4147-8f23-7cdad416d503 restarted
Any help would be greatly appreciated.

Why do I need to import tensorflow before import spaCy?

I am using python 3.8, spaCy 3.2.4, tensorflow 2.8.0, cuda 11.2, tensorflow-gpu 2.8.0. I want to import spacy, but it shows this error
import spacy
Process finished with exit code -1073740791 (0xC0000409)
Then, to fix this issue, I have to use this code
import tensorflow
import spacy
Now, it works. Although I already fixed the issue, I still want to know the reason behind the solution.
Furthermore, another question is when typing
import spacy
It shows:
Backend QtAgg is interactive backend. Turning interactive mode on.
How to always choose Qt5Agg or TkAgg instead of QtAgg? How to always turn on the interactive mode? I am using PyCharm IDE Community Edition 2020.3.5.

How to get rid of "Using TensorFlow backend." in Jupyter Notebook

When I run this code, this "Using TensorFlow backend" always pops up.
Even after I tried
import warnings
warnings.filterwarnings('ignore')
warnings.simplefilter('ignore)
I wonder whether I can get rid of it to make my notebook look cleaner.
Starting with tf-2.0 Keras is now the official high-level API of TensorFlow packaged within it. Not sure if it is a possibility in your case, but using tf-2.0 should remove this error. Here's a Quick Start guide if needed.
For most of the simple cases, just changing the import statement to import tensorflow.keras as keras gets it going.

jupyter could not remember I have imported tensorflow in the last block

When I was using jupyter in vscode, I found that it could not remember remember I had import tensorflow in the last block. like:
block1: import tensorflow as tf (success)
block2: print(tf.__version) (false -->"name 'tf' is not defined")
This problem is only for tensorflow. Vscode works well with other modules.
I am using Apple M1 max
Restart Jupyter kernel will lose all variables. After I restart it then only run print(tf.__version__) i get the same error as yours:
After restarting, you should run the previous code cell again to make the following code run successfully.

When using tensorflow and numpy in one notebook: The kernel appears to have died. It will restart automatically

When I try to run code using keras and numpy or keras and Matplotlib in one Jupyter notebook I always get the message: The kernel appears to have died. It will restart automatically.
When I run the code in two different notebooks it works perfectly fine. I have installed it using anaconda and I am using macOS. I would really appreciate an answer, everything else I've found and tried so far did not work. Thank you!

Categories

Resources