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)

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


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