Lightning-AI / Lightning-AI/torchmetrics
LPIPS turn slow during training
- Dominant language
- Python
- Stars
- 2.5k
- Forks
- 526
- Avg merge
- 6d 11h
- Merged PRs (30d)
- 5
Description
## 🐛 the append operation in update() cause training turing slow
### To Reproduce
Here is a simple demo for reimplementation.
When using torchmetrics==1.7.0, it works well, but with 1.8.1 the time per iteration gradually increases.
After checking the commit history, I suspect this is caused by the append operation in update() at line 148.
```python
# Ideally attach a minimal code sample to reproduce the decried issue.
# Minimal means having the shortest code but still preserving the bug.
class Loss(nn.Module):
def __init__(self, dssim_weight, codebook_weight):
super().__init__()
self.lpips = LearnedPerceptualImagePatchSimilarity(net_type='vgg')
def forward(self, colors, rec_colors):
img_lpips = self.lpips(rec_colors, colors)
return img_lpips
```
- TorchMetrics version (if build from source, add commit SHA): 1.8.1
- Python & PyTorch Version (e.g., 1.0): ???
- Any other relevant information such as OS (e.g., Linux): ???
### Additional context
Contributor guide
Research direction
Start with LearnedPerceptualImagePatchSimilarity and its update() implementation, especially the suspected append operation at line 148, then reproduce the provided Loss example with torchmetrics 1.7.0 and 1.8.1. Profile iteration time and compare the behavior; done means the gradual slowdown is reproduced, its cause is confirmed, and the corrected behavior is covered by an appropriate regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning, performance
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100