为什么” NumExpr 默认为 8 个线程。 ” python 中显示警告消息?

发布于 2025-01-09 18:18:09 字数 593 浏览 0 评论 0原文

我正在尝试使用 python 中的 lux 库来获取可视化建议。它显示诸如 NumExpr defaulting to 8threading. 之类的警告。

import pandas as pd
import numpy as np
import opendatasets as od
pip install lux-api
import lux
import matplotlib

然后:

link = "https://www.kaggle.com/noordeen/insurance-premium-prediction"
od.download(link) 
df = pd.read_csv("./insurance-premium-prediction/insurance.csv")

但是,一切都很好。有什么问题或者我应该忽略它吗? 警告显示如下: 输入图像描述这里

I am trying to use the lux library in python to get visualization recommendations. It shows warnings like NumExpr defaulting to 8 threads..

import pandas as pd
import numpy as np
import opendatasets as od
pip install lux-api
import lux
import matplotlib

And then:

link = "https://www.kaggle.com/noordeen/insurance-premium-prediction"
od.download(link) 
df = pd.read_csv("./insurance-premium-prediction/insurance.csv")

But, everything is working fine. Is there any problem or should I ignore it?
Warning shows like this:
enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

半世蒼涼 2025-01-16 18:18:09

在大多数情况下,这并不是真正值得担心的事情。该警告来自此函数,此处为最重要的部分:

...
    env_configured = False
    n_cores = detect_number_of_cores()
    if 'NUMEXPR_MAX_THREADS' in os.environ:
        # The user has configured NumExpr in the expected way, so suppress logs.
        env_configured = True
        n_cores = MAX_THREADS
...
    if 'NUMEXPR_NUM_THREADS' in os.environ:
        requested_threads = int(os.environ['NUMEXPR_NUM_THREADS'])
    elif 'OMP_NUM_THREADS' in os.environ:
        requested_threads = int(os.environ['OMP_NUM_THREADS'])
    else:
        requested_threads = n_cores
        if not env_configured:
            log.info('NumExpr defaulting to %d threads.'%n_cores)

所以如果两者都不是设置 NUMEXPR_MAX_THREADSNUMEXPR_NUM_THREADSOMP_NUM_THREADS 时,NumExpr 使用的线程数与内核数相同(即使 文档说“最多 8”,但这不是我看到的 在代码中)。

您可能想要使用另一数量的线程,例如,当计算真正巨大的矩阵时,人们可以从中受益,或者使用更少的线程,因为没有任何改进。在 shell 中或在导入 numexpr 之前设置环境变量,例如

import os
os.environ['NUMEXPR_MAX_THREADS'] = '4'
os.environ['NUMEXPR_NUM_THREADS'] = '2'
import numexpr as ne 

This is not really something to worry about in most cases. The warning comes from this function, here the most important part:

...
    env_configured = False
    n_cores = detect_number_of_cores()
    if 'NUMEXPR_MAX_THREADS' in os.environ:
        # The user has configured NumExpr in the expected way, so suppress logs.
        env_configured = True
        n_cores = MAX_THREADS
...
    if 'NUMEXPR_NUM_THREADS' in os.environ:
        requested_threads = int(os.environ['NUMEXPR_NUM_THREADS'])
    elif 'OMP_NUM_THREADS' in os.environ:
        requested_threads = int(os.environ['OMP_NUM_THREADS'])
    else:
        requested_threads = n_cores
        if not env_configured:
            log.info('NumExpr defaulting to %d threads.'%n_cores)

So if neither NUMEXPR_MAX_THREADS nor NUMEXPR_NUM_THREADS nor OMP_NUM_THREADS are set, NumExpr uses so many threads as there are cores (even if the documentation says "at most 8", yet this is not what I see in the code).

You might want to use another number of threads, e.g. while really huge matrices are calculated and one could profit from it or to use less threads, because there is no improvement. Set the environment variables either in the shell or prior to importing numexpr, e.g.

import os
os.environ['NUMEXPR_MAX_THREADS'] = '4'
os.environ['NUMEXPR_NUM_THREADS'] = '2'
import numexpr as ne 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文