JupyterLab 中计时代码的意外行为

问题描述 投票:0回答:0

我在 JupyterLab 中有一个项目涉及使用执行大量矩阵乘法的 SciPy 最小化目标。我使用

%%time
来计时,它同时打印 CPU 时间和墙上时间,这通常是相似的,但最近(即两周前)我注意到,在不同的优化参数设置中,墙上时间大约是 CPU 时间的一半。特定小区的计时结果如下

CPU times: total: 6min 4s Wall time: 3min 18s

但是这种 2 倍的加速在多次运行中是一致的(以及更长的运行时间,例如 1.5 小时的 CPU 时间对应 ~45 分钟的挂钟时间,所以这不是随机运行时波动造成的)。我没有在我的代码中使用(甚至导入)

multiprocessing
,我也不知道 Jupyter 中有任何内置的多处理功能。如果我确实明确使用多处理,我的代码应该得到 2 倍的加速,因为我的笔记本电脑有一个它 可以 使用的额外核心,但我不知道这是如何自动发生的。今天早些时候,我重新运行这段代码,加速消失了

CPU times: total: 8min 11s Wall time: 7min 11s

即使我没有更新我的环境中的任何东西或编辑代码本身。我的问题很笼统:什么可能导致计时行为发生变化? JupyterLab 和/或 NumPy 中是否内置了某种多处理功能?

版本详情,运行

!jupyter --version
给出

Selected Jupyter core packages...
IPython          : 8.12.0
ipykernel        : 6.19.2
ipywidgets       : not installed
jupyter_client   : 8.1.0
jupyter_core     : 5.3.0
jupyter_server   : 1.23.4
jupyterlab       : 3.5.3
nbclient         : 0.5.13
nbconvert        : 6.5.4
nbformat         : 5.7.0
notebook         : 6.5.4
qtconsole        : not installed
traitlets        : 5.7.1

我也在使用 NumPy 版本

1.23.5
和 SciPy
1.10.0
.

numpy performance jupyter python-multiprocessing jupyter-lab
© www.soinside.com 2019 - 2024. All rights reserved.