Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why " NumExpr defaulting to 8 threads. " warning message shown in python?

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

like image 868
Akash Kumar Avatar asked Feb 27 '26 08:02

Akash Kumar


1 Answers

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 
like image 103
ead Avatar answered Feb 28 '26 22:02

ead



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!