Cverlpeng:

Is that right? Are the two functions the same?


It doesn’t have the side-effect of modifing its input, you could compare results.
loss_fuse = nn.KLDivLoss().forward(out_seg_sm[:,1:,:,:], out_dt_norm.clone())
loss_fuse < 0 why?

The typical way to get negative kl_div is because your arguments are not probability distributions, and indeed out_dt_norm has little reason to be. You could do something like
dt_out_unnormalized = dt_out.clamp(min, max)
dt_out = dt_out_unnormalized. / dt_out_unnormalized.sum((2, 3))

with (2, 3) replaced by whatever dimensons you want the normalization to cover.
(You should be using torch.nn.functional.kl_div, too, and don’t need the clone.)
I must admit I don’t know what you are trying to achieve in terms of modelling and so I cannot say if it is mathematically sound or not.
Best regards
Thomas