请问为什么在jupyter notebook中import jittor会导致内核挂掉?

我的平台是windows10,想在jupyter notebook中使用jittor,但遇到了如下问题:

如果在使用jupyter前运行过import jittor编译过jittor,在jupyter中import jittor会提示

>>> import jittor as jt
[i 1104 04:41:47.087000 76 compiler.py:941] Jittor(1.3.1.16) src: D:\Programs\Python\Python38\lib\site-packages\jittor
[i 1104 04:41:47.163000 76 compiler.py:942] cl at C:\Users\WuTianyi\.cache\jittor\msvc\VC\_\_\_\_\_\bin\cl.exe(19.29.30133)
[i 1104 04:41:47.164000 76 compiler.py:943] cache_path: C:\Users\WuTianyi\.cache\jittor\jt1.3.1\cl\py3.8.8\Windows-10-10.x6a\AMDRyzen74800Hxc9\default
[i 1104 04:41:47.173000 76 install_cuda.py:51] cuda_driver_version: [11, 2, 0]
[i 1104 04:41:47.260000 76 __init__.py:372] Found C:\Users\WuTianyi\.cache\jittor\jtcuda\cuda11.2_cudnn8_win\bin\nvcc.exe(11.2.67) at C:\Users\WuTianyi\.cache\jittor\jtcuda\cuda11.2_cudnn8_win\bin\nvcc.exe.
[i 1104 04:41:47.902000 76 compiler.py:993] cuda key:cu11.2.67_sm_75
[i 1104 04:41:47.905000 76 __init__.py:187] Total mem: 15.37GB, using 5 procs for compiling.
Compiling jit_utils_core(5/5) used: 2.169s eta: 0.000s
[e 1104 04:41:50.863000 76 compiler.py:875] jit_utils updated, please rerun your command.

重点大概是[e 1104 04:41:50.863000 76 compiler.py:875] jit_utils updated, please rerun your command.这句话
而后如果不重启jupyter内核,再次运行import jittor会导致内核挂掉。
此时在命令行中运行import jittor也会提示上述报错信息而后退出,而后重新运行import jittor的话会重新编译。
如果在使用jupyter前并未编译过,则在jupyter中编译jittor也会导致内核挂掉。

请问如何解决这一问题?

(另外这个问题是不是提issue比较合适?)

您好!

关于 jit_utils updated

jittor 是基于即时编译的框架,这就意味着基于 jittor 的运算和框架本身都是在安装之后才开始编译。因此当用户在更新 jittor 版本时,会首先重新编译基础功能(由 jittor_utils 负责),完成后提示

jit_utils updated, please rerun your command.

之后重启python,jittor 就可以编译剩余部分。因此这是正常现象,并且如果jittor版本不变,之后都不需要再重编译 jittor_utils。

关于 Jupyter 下导致内核挂掉

如果在使用jupyter前并未编译过,则在jupyter中编译jittor也会导致内核挂掉。

我在 Mac 环境下的notebook,安装和 import jittor 可以正常编译。我们会进一步测试是不是 Windows 环境下的问题。

您如果在命令行下先import jittor,等待jittor编译完成,再使用 jupyter 也会出现问题吗?

关于提问准则

任何问题都可以在 issue 或者论坛提出,我们都是同样重视。

其实我是没有变过jittor版本的,不清楚为啥要重新编译……

我在命令行下先import jittor编译完成的话,在jupyter中import jittor会报如下信息

[i 1104 19:49:12.768000 16 compiler.py:941] Jittor(1.3.1.16) src: d:\programs\python\python38\lib\site-packages\jittor
[i 1104 19:49:12.862000 16 compiler.py:942] cl at C:\Users\WuTianyi.cache\jittor\msvc\VC_____\bin\cl.exe(19.29.30133)
[i 1104 19:49:12.864000 16 compiler.py:943] cache_path: C:\Users\WuTianyi.cache\jittor\jt1.3.1\cl\py3.8.8\Windows-10-10.x6a\AMDRyzen74800Hxc9\default
[i 1104 19:49:12.870000 16 install_cuda.py:51] cuda_driver_version: [11, 2, 0]
[i 1104 19:49:12.966000 16 __init__.py:372] Found C:\Users\WuTianyi.cache\jittor\jtcuda\cuda11.2_cudnn8_win\bin\nvcc.exe(11.2.67) at C:\Users\WuTianyi.cache\jittor\jtcuda\cuda11.2_cudnn8_win\bin\nvcc.exe.
[i 1104 19:49:13.637000 16 compiler.py:993] cuda key:cu11.2.67_sm_75
[i 1104 19:49:13.640000 16 __init__.py:187] Total mem: 15.37GB, using 5 procs for compiling.
Compiling jit_utils_core(4/5) used: 2.263s eta: 0.566s
[e 1104 19:49:17.339000 16 compiler.py:875] jit_utils updated, please rerun your command.
Compiling jit_utils_core(5/5) used: 2.482s eta: 0.000s
An exception has occurred, use %tb to see the full traceback.
SystemExit: 0
d:\programs\python\python38\lib\site-packages\IPython\core\interactiveshell.py:3445: UserWarning: To exit: use ‘exit’, ‘quit’, or Ctrl-D.
warn(“To exit: use ‘exit’, ‘quit’, or Ctrl-D.”, stacklevel=1)

此时jupyter的python内核还没挂掉,此时如果再次import jittor,会开始重新编译,在提示完如下信息后内核就会挂掉。也就是编译完jittor_core后内核就会挂掉。

[i 1104 19:51:06.379000 16 compiler.py:941] Jittor(1.3.1.16) src: d:\programs\python\python38\lib\site-packages\jittor
[i 1104 19:51:06.468000 16 compiler.py:942] cl at C:\Users\WuTianyi.cache\jittor\msvc\VC_____\bin\cl.exe(19.29.30133)
[i 1104 19:51:06.469000 16 compiler.py:943] cache_path: C:\Users\WuTianyi.cache\jittor\jt1.3.1\cl\py3.8.8\Windows-10-10.x6a\AMDRyzen74800Hxc9\default
[i 1104 19:51:06.471000 16 install_cuda.py:51] cuda_driver_version: [11, 2, 0]
[i 1104 19:51:06.571000 16 __init__.py:372] Found C:\Users\WuTianyi.cache\jittor\jtcuda\cuda11.2_cudnn8_win\bin\nvcc.exe(11.2.67) at C:\Users\WuTianyi.cache\jittor\jtcuda\cuda11.2_cudnn8_win\bin\nvcc.exe.
[i 1104 19:51:07.238000 16 compiler.py:993] cuda key:cu11.2.67_sm_75
Compiling jittor_core(146/146) used: 43.244s eta: 0.000ss

之后重启jupyter内核,再次import jittor,内核会干净利落的挂掉。

以下是在此期间jupyter notebook的日志

[I 19:49:02.990 NotebookApp] Kernel started: a188b047-1021-44d8-ad35-8853ae836e9a, name: python3
[i 1104 19:49:12.378000 16 log.cc:345] Load log_sync: 1
[i 1104 19:49:14.074000 52 log.cc:345] Load log_sync: 1
[i 1104 19:49:14.116000 88 log.cc:345] Load log_sync: 1
[i 1104 19:49:14.147000 48 log.cc:345] Load log_sync: 1
[i 1104 19:49:14.191000 64 log.cc:345] Load log_sync: 1
[i 1104 19:49:14.251000 92 log.cc:345] Load log_sync: 1
[I 19:51:02.842 NotebookApp] Saving file at /计图入门教程 1 — 基本概念.ipynb
[I 19:52:17.998 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
kernel a188b047-1021-44d8-ad35-8853ae836e9a restarted
[I 19:53:02.836 NotebookApp] Saving file at /计图入门教程 1 — 基本概念.ipynb
[I 19:53:25.116 NotebookApp] Starting buffering for a188b047-1021-44d8-ad35-8853ae836e9a:203b6b6ce3f6465a841a81090a532762
[I 19:53:25.366 NotebookApp] Kernel restarted: a188b047-1021-44d8-ad35-8853ae836e9a
[I 19:53:25.379 NotebookApp] Restoring connection for a188b047-1021-44d8-ad35-8853ae836e9a:203b6b6ce3f6465a841a81090a532762
[I 19:53:26.928 NotebookApp] Replaying 3 buffered messages
[i 1104 19:53:28.575000 32 log.cc:345] Load log_sync: 1
[i 1104 19:53:30.182000 84 log.cc:345] Load log_sync: 1
[i 1104 19:53:30.251000 32 log.cc:345] Load log_sync: 1
[i 1104 19:53:30.281000 84 log.cc:345] Load log_sync: 1
[i 1104 19:53:30.333000 72 log.cc:345] Load log_sync: 1
[i 1104 19:53:30.365000 36 log.cc:345] Load log_sync: 1
[I 19:53:34.360 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
kernel a188b047-1021-44d8-ad35-8853ae836e9a restarted
[i 1104 19:54:31.565000 00 log.cc:345] Load log_sync: 1
[i 1104 19:54:33.158000 00 log.cc:345] Load log_sync: 1
[i 1104 19:54:33.200000 00 log.cc:345] Load log_sync: 1
[i 1104 19:54:33.244000 08 log.cc:345] Load log_sync: 1
[i 1104 19:54:33.297000 24 log.cc:345] Load log_sync: 1
[i 1104 19:54:33.326000 28 log.cc:345] Load log_sync: 1
[I 19:54:37.409 NotebookApp] KernelRestarter: restarting kernel (1/5), keep random ports
kernel a188b047-1021-44d8-ad35-8853ae836e9a restarted

您不在jupyter里跑,直接运行python3.7 -m jittor.test.test_core能够运行成功吗?

在命令行中运行python -m jittor.test.test_core可以成功。

我们在jupyter notebook中可以成功复现这个问题,在python里直接运行是不会的,我们会进一步调查并尽快修复该问题,谢谢您的反馈

好的。