In your code snippet you are using:
adv_prob = nn.LogSoftmax(dim=1)(adv_prob)

which is undefined in the first execution so I assume it’s a typo?
I’m not able to see the issue in this code snippet so could you check what the difference might be?
net = models.resnet18()
optimizer = torch.optim.SGD(model.parameters(), lr=1e-3)
x = torch.randn(1, 3, 224, 224)
adv_x = torch.randn(1, 3, 224, 224)
y = torch.randint(0, 1000, (1,))

optimizer.zero_grad()

pred = net(x)
loss_nat = nn.CrossEntropyLoss()(pred, y).mean()
true_prob = nn.Softmax(dim=1)(pred)

adv_prob = net(adv_x)
adv_prob = nn.LogSoftmax(dim=1)(adv_prob)
loss_rob = nn.KLDivLoss()(adv_prob, true_prob).mean() # this doesn't work
# loss_nat = nn.CrossEntropyLoss()(pred, y).mean() # this works, although not desired

loss = loss_nat + loss_rob
loss.backward()