Thank you @LeviViana, the model can be trained after setting  requires_grad  to  True  for  t  and  f,
but the loss doesn’t change,I will look into this. By the way, should I put a negative sign in front of torch.sum(prob) to make it a minimum optimization?