No condition does not have any parameters and operation.
Your suggestion does not work and has the error “Trying to backward through the graph a second time (or directly access saved tensors…”
I change the code to this and it works but I do not know why this works??
this line :
reg_params = torch.cat([reg_params,x[[1,2],:,:,:].view(-1)])

changed to
temp =[1,2]
for i in temp:
      reg_params = torch.cat([reg_params,x[i,:,:,:].view(-1)])
....

Thank you InnovArul