Thank u very much. Yes, after commenting ‘loss.requires_grad = True’, I found out the real error, which is ‘element 0 of tensors does not require grad and does not have a grad_fn’. I had this error before, and added 'loss.requires_grad = True ’ naively. I compared it to the original code again and found out that there is no ‘loss.requires_grad = True’, just
loss = criterion(masks_pred, true_masks)
epoch_loss += loss.item()

I guess, this refers to what you meant, generally only be able to change the requires_grad attribute of leaf variables.  So, the problem is that I put wrong output inside the loss function. My new network architecture delivers three output instead of just one as what the original network architecture did. Now, I have new error. But, I am going to right direction. Many thanks. @ptrblck