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)
@betatim @ncclementi @jameslamb @tonyhoo Made a megathread on the CPU Oversubscription problem: #5180
Side comment:
psutilis 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_countfrom 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
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 + Fsearched 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 wherenum_cpuand 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.
While it probably should be better communicated, we do have this logic:
TabularPredictor.fit(..., num_cpus=..., num_gpus=...)(global control)'ag.num_cpus': ...,'ag.num_gpus': .../'ag_args_fit': {'num_cpus': ..., 'num_gpus': ...}(model hyperparameters)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:
Where
CPU Countis, we could add aCPU Utilizationwhich 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 😊
I think there might be. To me, this looks very clearly like CPU oversubscription, and there might be ways for
autogluonto prevent it or at least make it easier for users to diagnose.Specifically, given something like the following:
I observed:
autogluonto perform single-threaded training, training for one example completes 40x-300x faster than using the default behaviorWhy 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):And that
autogluontried to use every available CPU by default: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
autogluonto considern_jobsornum_threadsor similar constructor argument forTabularPredictor?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)
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 withautogluon, apologies if there is an easier way I’ve just missed.train_autogluon.py (click me)
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,
106sand21sare both fast enough, in absolute terms, to not be too annoying.Next, I ran the following in 4 separate shells to occupy some CPUs.
(any CPU-intensive operation should be fine for this purpose)
Then ran training again.
Roughly the same timings as before.
Next, increased it to 12 of those “do something CPU-intensive” processes running at the same time.
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
autogluonis introducing additional demands on the CPU here… I’m not able to replicate this amount of slowdown with purelightgbmcode, even using the same dataset and parameters asTabularPredictor.fit().train_lgbm.py (click me)
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
autogluontaking a long time in absolute terms.machine details (click me)
Grabbed those scripts.
First, tried in a `venv`, installing everything with `pip` (click me)
Then, tried in a `conda` env installing `autogluon` and its dependencies with `pip` (click me)
Then one more time, with `conda` + installing `autogluon` and its dependencies with `conda`. (click me)
In all 3 environment-setup variations, that sample
autogluoncode 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)
autogluonis using multiprocessing while eachlightgbmtraining run is trying to use multithreading with 1 thread per CPUn_jobs=-1inoptunaorscikit-learnANDnum_threads=-1inlightgbmnum_threads: 1in LightGBM parameters, maybe set environment variableOMP_NUM_THREADS=1for other libraries… if the code runs FASTER, then that’s evidence that you had a CPU oversubscription/contention problem.autogluonexample writes around 120MB of files to disk… maybe it’s those writes that are slowdd if=/dev/zero of=/tmp/output bs=8k count=10k;(for me, this reports write speeds of 2.1GB/s)torch,scikit-learn, andxgboosteach vendor their own copies oflibgomp.soLD_DEBUG=libs LD_DEBUG_OUTPUT=/tmp/ld-logsor similar, see https://github.com/microsoft/LightGBM/issues/6509#issuecomment-2212348002 for an example… those logs will tell you what libraries were loaded and in what order