Training yolov8 throws an error - AttributeError: 'NoneType' object has no attribute '_free_weak_ref'


I’m facing an issue during training with yolov8. After each epoch the following errror appears several times.

lib\site-packages\torch\", line 520, in _free_weak_ref
AttributeError: ‘NoneType’ object has no attribute ‘_free_weak_ref’
Exception ignored in: <function StorageWeakRef.del at 0x000002448E3708B0>

Although I’m able to train and save yolov8 models, time to time, the training crashes, which is very frustrating taking into account a training takes 5 hours and after 3 hours of training the program crashes.

I’m using anaconda env and I installed the following packages

conda install pytorch==1.11.0 torchvision==0.12.0 torchaudio==0.11.0 cudatoolkit=11.3 -c pytorch

Everything worked fine with yolov5, but with yolov8 this issue happens.


The issue seems to be related to this one which is apparently fixed in 1.12.0+, so you might want to update your PyTorch release.

Interesting, I went to that page before. But I managed to solve the issue by not updating the pytorch. I mean I worked with yolov5 in pytorch 1.11 and no issue happened. In fact the most recent version of pytorch gave me problems that is why months ago I downgraded to 1.11
But now I solved the issue by upgrading the version. Thank you very much!