Lightning-AI / Lightning-AI/pytorch-lightning

Lightning 2.0 CPUAccelerator is extremely slow!

Open
#17,169 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug performance repro needed ver: 2.0.x waiting on author
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Bug description

I just updated lightning version to 2.0 and running inference on cpu is extremely slow.

My previous code can be [found here](https://github.com/Unbabel/COMET/blob/master/comet/models/base.py#L616). Inference is basically performed by initialising a trainer with devices=0 and strategy=None.

```python
trainer = ptl.Trainer(
devices=devices,
logger=False,
callbacks=callbacks,
accelerator=accelerator if gpus > 0 else "cpu",
strategy=None if gpus < 2 else "ddp",
enable_progress_bar=enable_progress_bar,
)
return_predictions = False if gpus > 1 else True
predictions = trainer.predict(
self, dataloaders=dataloader, return_predictions=return_predictions
)
```

Since in lightning 2.0 we cant pass `None` to the strategy, I replaced it with "cpu" if gpus < 1. Yet, this makes the code much slower. Is this normal? In gpu everything seems to work well.

### How to reproduce the bug

_No response_

### Error messages and logs

```
# Error messages and logs here please
```

### Environment

Current environment

```
#- Lightning Component (e.g. Trainer, LightningModule, LightningApp, LightningWork, LightningFlow):
#- PyTorch Lightning Version (e.g., 1.5.0):
#- Lightning App Version (e.g., 0.5.2):
#- PyTorch Version (e.g., 2.0):
#- Python version (e.g., 3.9):
#- OS (e.g., Linux):
#- CUDA/cuDNN version:
#- GPU models and configuration:
#- How you installed Lightning(`conda`, `pip`, source):
#- Running environment of LightningApp (e.g. local, cloud):
```

### More info

_No response_

cc @borda

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the Trainer.predict call shown in the issue and compare CPU inference using the Lightning 2.0 strategy settings with the previous configuration. Collect the missing Lightning, PyTorch, Python, OS, and installation details, then create a reproducible benchmark. Done means the CPU slowdown is reproduced and its cause or a documented resolution is established.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.