autogluon: [BUG] CPU Oversubscription causes 100x+ Slowdown in Tabular

Bug Report Checklist

  • I provided code that demonstrates a minimal reproducible example.
  • I confirmed bug exists on the latest mainline of AutoGluon via source install.
  • I confirmed bug exists on the latest stable version of AutoGluon.

Describe the bug I’m trying to run this example locally https://colab.research.google.com/github/autogluon/autogluon/blob/stable/docs/tutorials/tabular/tabular-essentials.ipynb

With a clean environment installing autogluon=1.3.1 via pip. When I try to run

predictor = TabularPredictor(label=label).fit(train_data)

It stalls during (I interrupt it after 3 min)

Fitting model: LightGBMXT

In the colab version I don’t see this behavior but the environment is clearly not the same. I tried different combinations given that

  • The lightgbm version is different (colab 4.5, when installing locally 4.6)
  • I tried both python 3.11 and 3.12

But it still stalls,

Expected behavior In colab it runs fairly quickly. I would expect locally to run the same

To Reproduce Create a clean environment and install pip install autogluon==1.3.1 and run locally the example from

https://auto.gluon.ai/stable/tutorials/tabular/tabular-essentials.html

Screenshots / Logs

Installed Versions In this env I tried forcing lightgbm to be in version 4.5 as in colab but taht didn’t work wither. By default now if we install autogluon==1.3.1 it will install lightgbm 4.6

# Replace this code with the output of the following:
from autogluon.core.utils import show_versions
show_versions()

INSTALLED VERSIONS
------------------
date                   : 2025-06-11
time                   : 23:39:12.367895
python                 : 3.12.11.final.0
OS                     : Linux
OS-release             : 5.15.0-125-generic
Version                : #135-Ubuntu SMP Fri Sep 27 13:53:58 UTC 2024
machine                : x86_64
processor              : x86_64
num_cores              : 128
cpu_ram_mb             : 1031901.06640625
cuda version           : 12.565.57.01
num_gpus               : 8
gpu_ram_mb             : [45485, 45485, 45485, 45485, 45485, 45485, 45485, 45485]
avail_disk_size_mb     : 4804205

accelerate             : 1.7.0
autogluon              : 1.3.1
autogluon.common       : 1.3.1
autogluon.core         : 1.3.1
autogluon.features     : 1.3.1
autogluon.multimodal   : 1.3.1
autogluon.tabular      : 1.3.1
autogluon.timeseries   : 1.3.1
boto3                  : 1.38.35
catboost               : 1.2.8
coreforecast           : 0.0.15
defusedxml             : 0.7.1
einops                 : 0.8.1
evaluate               : 0.4.3
fastai                 : 2.8.2
fugue                  : 0.9.1
gluonts                : 0.16.1
huggingface-hub        : 0.33.0
hyperopt               : 0.2.7
imodels                : None
jinja2                 : 3.1.6
joblib                 : 1.5.1
jsonschema             : 4.23.0
lightgbm               : 4.5.0
lightning              : 2.5.1.post0
matplotlib             : 3.10.3
mlforecast             : 0.13.6
networkx               : 3.5
nlpaug                 : 1.1.11
nltk                   : 3.8.1
numpy                  : 2.1.3
nvidia-ml-py3          : 7.352.0
omegaconf              : 2.3.0
onnx                   : None
onnxruntime            : None
onnxruntime-gpu        : None
openmim                : 0.3.9
optimum                : None
optimum-intel          : None
orjson                 : 3.10.18
pandas                 : 2.2.3
pdf2image              : 1.17.0
Pillow                 : 11.2.1
psutil                 : 7.0.0
pyarrow                : 20.0.0
pytesseract            : 0.3.13
pytorch-lightning      : 2.5.1.post0
pytorch-metric-learning: 2.8.1
ray                    : 2.44.1
requests               : 2.32.4
scikit-image           : 0.25.2
scikit-learn           : 1.6.1
scikit-learn-intelex   : None
scipy                  : 1.15.3
seqeval                : 1.2.2
skl2onnx               : None
spacy                  : 3.8.7
statsforecast          : 2.0.1
tabpfn                 : None
tensorboard            : 2.19.0
text-unidecode         : 1.3
timm                   : 1.0.3
torch                  : 2.6.0
torchmetrics           : 1.7.2
torchvision            : 0.21.0
tqdm                   : 4.67.1
transformers           : 4.49.0
utilsforecast          : 0.2.10
xgboost                : 3.0.2

Note: If I create the environment via conda, I don’t have this issue. only when using purely pip.

About this issue

  • Original URL
  • State: open
  • Created a year ago
  • Comments: 19 (4 by maintainers)

Most upvoted comments

@betatim @ncclementi @jameslamb @tonyhoo Made a megathread on the CPU Oversubscription problem: #5180

Side comment: psutil is probably not the best tool to find out how many cores to use. IIRC it does not take into account limits set on k8s pods or docker containers or other cgroups based ways to limit how much CPU a process can use.

cpu_count from https://loky.readthedocs.io/en/stable/ takes all sorts of these limits into account.

In my experience counting CPUs when you are “deployed” (e.g. on some k8s based platform) is a great way to oversubscribe your system

Thanks for the detailed analysis and all the useful context provided. Shout out to @jameslamb @ncclementi and @betatim. We will take a look and see if we can squeeze in the fix for 1.4.1

TabularPredictor.fit(..., num_cpus=..., num_gpus=...) (global control)

Thank you for this! I suspected that what I was doing with those per-model-type overrides was overcomplicated 😅

I think I did not find those options because I just Ctrl + F searched around on https://auto.gluon.ai/stable/api/autogluon.tabular.TabularPredictor.html for “cpu”, “thread”, “jobs”, “parallel”, etc. and didn’t find any matches.

Clicking [source] there takes me to https://auto.gluon.ai/stable/_modules/autogluon/tabular/predictor/predictor.html#TabularPredictor where num_cpu and other parallelism-control arguments are visible.

All that to say… I think the docs here have all the information I needed to find the better pattern, I just did a poor job of searching them.

I’ve subscribed to #5180, please feel free to @ me on any conversations related to this topic and LightGBM, I will try to help.

Thanks for all your help!

@betatim Good points! I added the psutil logic a very long time ago, and I am certain it is very suboptimal for all the different edge-cases that I am less familiar with.

@tonyhoo This will be important to resolve, either in 1.4 or as a fast follow in 1.4.1. We should test how AG interacts with docker/etc. For example, I know AutoGluon has caused a lot of issues on SLURM clusters without carefully specifying of num_cpus/num_gpus when running AG.

Very interesting, thanks again for the deep dive @jameslamb!

This makes sense. I’m surprised oversubscription becomes so extremely harmful with just 7-12 CPUs oversubscribed on a 128 CPU machine, but I guess that is the reality.

could / should there be a unified way to control the amount of parallelism for all model types, like a n_jobs or num_threads or similar constructor argument for TabularPredictor?

While it probably should be better communicated, we do have this logic:

  1. TabularPredictor.fit(..., num_cpus=..., num_gpus=...) (global control)
  2. 'ag.num_cpus': ..., 'ag.num_gpus': ... / 'ag_args_fit': {'num_cpus': ..., 'num_gpus': ...} (model hyperparameters)

should “use all available threads” as the default behavior be reconsidered? For example, maybe “half of all physical CPUs” or “min(psutil.cpu_count(), 16)” or something?

This is tough… We expect most users to use whatever comes default in AutoGluon and not look any deeper than that, so I am hesitant to restrict the thread usage by default as most users wouldn’t realize AutoGluon is running slower than it could be.

For most production usage, we expect AutoGluon to be running on a dedicated instance where there aren’t other major processes running in the background.

Having some way to detect that a separate process is using a lot of resources would be nice in theory, but then what to do with that information becomes complicated. It still doesn’t stop a scenario where, for example, a separate process is started after AutoGluon starts fitting, leading to oversubscription. Dynamic resource allocation based on external processes also is a big negative for reproducibility and debugging.

Maybe one solution is to log a warning if CPU utilization exceeds a certain % when AutoGluon reports its system information at the start of the fit call:

Verbosity: 2 (Standard Logging)
=================== System Info ===================
AutoGluon Version:  1.3.2b20250527
Python Version:     3.11.10
Operating System:   Linux
Platform Machine:   x86_64
Platform Version:   #1 SMP Wed Mar 12 14:53:59 UTC 2025
CPU Count:          8
Memory Avail:       28.71 GB / 30.95 GB (92.8%)
Disk Space Avail:   211.25 GB / 255.99 GB (82.5%)
===================================================
Beginning AutoGluon training ...

Where CPU Count is, we could add a CPU Utilization which could spot if other processes are using up a lot of resources.

Side Comment

I don’t have bandwidth to personally test this, but I’d be curious if the oversubscription problem still exists when fitting AutoGluon’s models with bagging via .fit(..., num_bag_folds=8), as this will use Ray to fit all 8 in parallel, splitting up the CPUs among them evenly. If we don’t observe the same severity of the issue, we could consider applying a limit to the CPU count when doing non-bagged sequential fits.

Thanks for the kind words @Innixma and for the help @tonyhoo 😊

Let us know if there is any further investigation required.

I think there might be. To me, this looks very clearly like CPU oversubscription, and there might be ways for autogluon to prevent it or at least make it easier for users to diagnose.

Specifically, given something like the following:

TabularPredictor(label="target").fit(
    train_data,
    fit_strategy='sequential',
    hyperparameters=hyperparams,
)

I observed:

Why I think this is CPU oversubscription

@ncclementi and I are colleagues, so we were able to pair in the same environment. That machine is a shared VM used by several of our coworkers. Using htop, we discovered that there was at least one other process using a substantial amount of CPU (close to 100% of 7 of the 128 available CPUs):

Image

And that autogluon tried to use every available CPU by default:

Image

I think this explains why @ncclementi observed such slow training times that I was originally not able to replicate on my not-very-busy local workstation.

Changes for autogluon to consider

  • could / should there be a unified way to control the amount of parallelism for all model types, like a n_jobs or num_threads or similar constructor argument for TabularPredictor?
  • should “use all available threads” as the default behavior be reconsidered? For example, maybe “half of all physical CPUs” or “min(psutil.cpu_count(), 16)” or something?

Reproducible Example

On my local workstation which has 32 physical CPUs (same details as https://github.com/autogluon/autogluon/issues/5160#issuecomment-2982059742), used the following modified version of the reproducible example above.

environment setup with `pip` and `venv` (click me)
python3.12 -m venv delete-me
source ./delete-me/bin/activate
pip install \
    --no-cache-dir \
        'autogluon==1.3.1' \
        'lightgbm==4.6.0'

Click below to see what I did to make it possible to force TabularPredictor.fit() to perform single-threaded training. I am not very familiar with autogluon, apologies if there is an easier way I’ve just missed.

train_autogluon.py (click me)
import copy
import pandas as pd
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from autogluon.tabular import TabularPredictor
from autogluon.tabular.configs.hyperparameter_configs import hyperparameter_config_dict
import sys

SINGLE_THREADED = "--single-threaded" in sys.argv

# Generate binary classification data
X, y = make_classification(n_samples=1_000, n_features=10, n_informative=5, n_classes=2, random_state=42)
df = pd.DataFrame(X, columns=[f"feature_{i}" for i in range(X.shape[1])])
df["target"] = y
train_data, test_data = train_test_split(df, test_size=0.1, random_state=42)

# docs: https://auto.gluon.ai/dev/api/autogluon.tabular.TabularPredictor.fit.html

# get default hyperparameters
hyperparams = copy.deepcopy(hyperparameter_config_dict["default"])

# force some model types to perform single-threaded training

if SINGLE_THREADED:
    # -- LightGBM
    for i in range(len(hyperparams["GBM"])):
        hyperparams["GBM"][i].update({"num_threads": 1})

    # -- XGBoost
    if isinstance(hyperparams["XGB"], dict):
        hyperparams["XGB"].update({"nthread": 1})
    else:
        for i in range(len(hyperparams["XGB"])):
            hyperparams["XGB"][i].update({"nthread": 1})

    # -- NeuralNetFastAI
    if isinstance(hyperparams["FASTAI"], dict):
        hyperparams["FASTAI"].update({"ag_args_fit": {"num_cpus": 1}})
    else:
        for i in range(len(hyperparams["FASTAI"])):
            hyperparams["FASTAI"][i].update({"ag_args_fit": {"num_cpus": 1}})

    # -- Torch
    if isinstance(hyperparams["NN_TORCH"], dict):
        hyperparams["NN_TORCH"].update({"ag_args_fit": {"num_cpus": 1}})
    else:
        for i in range(len(hyperparams["NN_TORCH"])):
            hyperparams["NN_TORCH"][i].update({"ag_args_fit": {"num_cpus": 1}})

# train AutoGluon predictor with default metric (log_loss for binary classification)
TabularPredictor(label="target").fit(
    train_data,
    fit_strategy='sequential',
    hyperparameters=hyperparams,
)
time python ./train_autogluon.py
# real    0m16.489s
# user    1m46.778s
# sys     0m22.648s

time python ./train_autogluon.py --single-threaded
# real    0m11.166s
# user    0m21.794s
# sys     0m4.455s

Here you can already see some signs that multithread is maybe not that helpful for such a small dataset (1,000 rows, 10 features). But still, 106s and 21s are both fast enough, in absolute terms, to not be too annoying.

Next, I ran the following in 4 separate shells to occupy some CPUs.

dd if=/dev/urandom | bzip2 -9 >> /dev/null

(any CPU-intensive operation should be fine for this purpose)

Then ran training again.

time python ./train_autogluon.py
# real    0m11.272s
# user    1m2.717s
# sys     0m20.702s

time python ./train_autogluon.py --single-threaded
# real    0m7.452s
# user    0m16.655s
# sys     0m2.413s

Roughly the same timings as before.

Next, increased it to 12 of those “do something CPU-intensive” processes running at the same time.

time python ./train_autogluon.py
# real    7m56.179s
# user    155m17.302s
# sys     0m23.684s

time python ./train_autogluon.py --single-threaded
# real    0m8.921s
# user    0m16.302s
# sys     0m2.587s

Notice that the single-threaded training time did not change much, but multi-threaded training got much much slower… that’s CPU oversubscription at work! I’d expect to see larger slowdowns the more background CPU-intensive processes I added.

Shouldn’t the underlying machine learning libraries deal with this?

Maybe, but I see some evidence that autogluon is introducing additional demands on the CPU here… I’m not able to replicate this amount of slowdown with pure lightgbm code, even using the same dataset and parameters as TabularPredictor.fit().

train_lgbm.py (click me)
import copy
import lightgbm as lgb
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
from sklearn.metrics import accuracy_score

from autogluon.tabular.configs.hyperparameter_configs import hyperparameter_config_dict
import sys

SINGLE_THREADED = "--single-threaded" in sys.argv

# Generate binary classification dataset
X, y = make_classification(n_samples=10_000, n_features=10, n_informative=5, random_state=42)
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.1, random_state=42)

# Prepare datasets
dtrain = lgb.Dataset(X_train, label=y_train)
dtest = lgb.Dataset(X_test, label=y_test)

# get params that autogluon uses for 'LightGBMLarge' configuration
params = copy.deepcopy(hyperparameter_config_dict['default']['GBM'][2])

# remove autogluon-specific stuff
_ = params.pop('ag_args')

if SINGLE_THREADED:
    params.update({"num_threads": 1})
else:
    params.update({"num_threads": -1})

print(f"using params: {params}")

# Train LightGBM with built-in logloss metric
bst = lgb.train(
    train_set=dtrain,
    params={
        "objective": "binary",
        "metric": "binary_logloss",
        **params
    },
    valid_sets=[dtest],
    valid_names=["test"],
)

print(f"Best iteration: {bst.best_iteration}")
print(f"Best score: {bst.best_score}")

# Predict on training data
y_train_pred_proba = bst.predict(X_train, num_iteration=bst.best_iteration)
y_train_pred = (y_train_pred_proba >= 0.5).astype(int)

# Compute training accuracy
train_accuracy = accuracy_score(y_train, y_train_pred)
print(f"Training Accuracy: {train_accuracy:.4f}")
time python ./train_lgbm.py
# real    0m2.684s
# user    0m7.296s
# sys     0m5.658s

time python ./train_lgbm.py --single-threaded
# real    0m1.694s
# user    0m4.992s
# sys     0m0.157s

Just wanted to shoutout @jameslamb, that was an excellent deep dive, much appreciated! And of course, my eternal gratitude for the ever reliable LightGBM library 😃

👋🏻 LightGBM maintainer here. I tried these examples on my machine (x64_64, 32 CPUs, 125 GB RAM), and could not reproduce the finding of this autogluon taking a long time in absolute terms.

machine details (click me)
uname -a
Linux 3a948bd-lcedt 6.11.0-26-generic #26~24.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Apr 17 19:20:47 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
lscpu
Architecture:             x86_64
  CPU op-mode(s):         32-bit, 64-bit
  Address sizes:          46 bits physical, 48 bits virtual
  Byte Order:             Little Endian
CPU(s):                   32
  On-line CPU(s) list:    0-31
Vendor ID:                GenuineIntel
  Model name:             Intel(R) Core(TM) i9-14900K
nvidia-smi
+-----------------------------------------------------------------------------------------+
| NVIDIA-SMI 570.133.20             Driver Version: 570.133.20     CUDA Version: 12.8     |
|-----------------------------------------+------------------------+----------------------+
| GPU  Name                 Persistence-M | Bus-Id          Disp.A | Volatile Uncorr. ECC |
| Fan  Temp   Perf          Pwr:Usage/Cap |           Memory-Usage | GPU-Util  Compute M. |
|                                         |                        |               MIG M. |
|=========================================+========================+======================|
|   0  NVIDIA RTX A6000               Off |   00000000:01:00.0  On |                  Off |
| 30%   36C    P8             28W /  300W |    1058MiB /  49140MiB |     13%      Default |
|                                         |                        |                  N/A |
+-----------------------------------------+------------------------+----------------------+

Grabbed those scripts.

wget \
  -O ./train_lgbm.py \
  https://gist.githubusercontent.com/ncclementi/00e0377a49fa4c76e7845a0c3fd2dc7c/raw/4cdee01580ca31f0e0aa2392a25752194803bc78/train_lgbm.py

wget \
  -O ./train_autogluon.py \
  https://gist.githubusercontent.com/ncclementi/00e0377a49fa4c76e7845a0c3fd2dc7c/raw/4cdee01580ca31f0e0aa2392a25752194803bc78/traing_auto_lgbm.py
First, tried in a `venv`, installing everything with `pip` (click me)
rm -rf ./AutogluonModels

python3.12 -m venv delete-me
source ./delete-me/bin/activate
pip install \
    --no-cache-dir \
        'autogluon==1.3.1' \
        'lightgbm==4.6.0'

time python ./train_lgbm.py
# real    0m0.589s
# user    0m5.270s
# sys     0m0.154s

time python ./train_autogluon.py
# real    0m15.984s
# user    1m41.507s
# sys     0m20.566s
Then, tried in a `conda` env installing `autogluon` and its dependencies with `pip` (click me)
rm -rf ./AutogluonModels
rm -rf ./delete-me

conda create \
    --yes \
    --name test-autogluon-lgbm \
        'python=3.12'

source activate test-autogluon-lgbm 
pip install \
    --no-cache-dir \
        'autogluon==1.3.1' \
        'lightgbm==4.6.0'

time python ./train_lgbm.py
# real    0m0.621s
# user    0m5.643s
# sys     0m0.166s

time python ./train_autogluon.py
# real    0m14.916s
# user    1m3.607s
# sys     0m21.794s
Then one more time, with `conda` + installing `autogluon` and its dependencies with `conda`. (click me)
rm -rf ./AutogluonModels
source deactivate

conda env remove \
  --yes \
  --name test-autogluon-lgbm

conda create \
    --yes \
    --name test-autogluon-lgbm \
        'autogluon==1.3.1' \
        'lightgbm==4.6.0' \
        'python=3.12'

source activate test-autogluon-lgbm

time python ./train_lgbm.py
# real    0m0.571s
# user    0m0.512s
# sys     0m0.111s

time python ./train_autogluon.py
# real    0m16.075s
# user    0m30.787s
# sys     0m20.144s

In all 3 environment-setup variations, that sample autogluon code took less than 30 seconds of clock time and less than 2 minutes of CPU time to run.

Hopefully this copy-pastable example helps.

Some ideas to explore, that might explain why @ncclementi and I are seeing different performance (esp. for LightGBM)

  • CPU oversubscription
    • like maybe autogluon is using multiprocessing while each lightgbm training run is trying to use multithreading with 1 thread per CPU
    • we see this in LightGBM bug reports often, for example when folks use n_jobs=-1 in optuna or scikit-learn AND num_threads=-1 in lightgbm
    • how to test that: pass num_threads: 1 in LightGBM parameters, maybe set environment variable OMP_NUM_THREADS=1 for other libraries… if the code runs FASTER, then that’s evidence that you had a CPU oversubscription/contention problem.
  • slow disks
    • I noticed that this autogluon example writes around 120MB of files to disk… maybe it’s those writes that are slow
    • how to test that: check with something like dd if=/dev/zero of=/tmp/output bs=8k count=10k; (for me, this reports write speeds of 2.1GB/s)
  • multiple OpenMP versions loaded