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

I am getting the following error while trying to use the BCEWithLogitsLoss from torch.nn.

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

I am wondering why it is happening?

In [1]: import torch

In [2]: dir(torch.nn)
Out[2]: 
['AdaptiveAvgPool1d',
 'AdaptiveAvgPool2d',
 'AdaptiveMaxPool1d',
 'AdaptiveMaxPool2d',
 'AvgPool1d',
 'AvgPool2d',
 'AvgPool3d',
 'BCELoss',
 'BatchNorm1d',
 'BatchNorm2d',
 'BatchNorm3d',
 'Bilinear',
 'ConstantPad2d',
...

No such method, only BSELoss exists. What makes you feel BCEWithLogitsLoss exists?

See the followings.

The first two are in master branch. Are you building master from source, or are you using a binary release version? eg what is the result of:

import torch
print(torch.version.__version__)

?

Oh, no. I am not building master from source. I am using pytorch 0.1.12_2 binary version.

How can I use those two loss functions?

Build from source :slight_smile:

Can you point me to a documentation to do that?

It’s a new feature. You may use some hacky ways to include that from github repo, or install pytorch from source.

1 Like