AttributeError: module 'torch.nn' has no attribute 'HuberLoss'

I’m using pytorch, pytorch-cpu 1.6.0 cpu_py38h3369884_1 conda-forge installed through anaconda and I get the following error.

>>> import torch
>>> torch.nn.HuberLoss()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'torch.nn' has no attribute 'HuberLoss'

I can see the HuberLoss implementation in the master branch on github, just wondering why this loss function is not found in my Pytorch installation.


nn.HuberLoss was introduces in PyTorch 1.9.0 so you would need to update your installation.

Thanks, I updated to the latest version 1.11.0 and HuberLoss is now available.