i have an error after make one loss func
class Latent_Classifier(nn.Module):
    def __init__(self):
        super(Latent_Classifier, self).__init__()
        
        self.encoder = nn.Sequential(
            nn.Linear(128, 750),
            nn.LeakyReLU(0.2),
            nn.Linear(750, 750),
            nn.Linear(750, 1)
        )
        
    def forward(self,latent_z):
        x1 = self.encoder(latent_z)
        print(x1.size())
        _eps = 1e-15
        loss = -(x1 + _eps).log().mean()-(1 - x1 + _eps).log().mean()
        
        return loss

i use this func as
classifier = Latent_Classifier()

f_classifier = classifier(latent_f)
lm_classifier = classifier(latent_l)

loss = 4000*(f_loss + m_loss) + 30 * (f_classifier + lm_classifier) + 2000 * lm_loss

loss.backward()

in loss.backward() i got an error msg
CUDA error: an illegal memory access was encountered
before using classifier loss, i have no error msg
is an error in function Latent_Classifier?
when i executed it using ‘torch.device(“cpu”)’ not cuda:0 it works well