I guess I misunderstood the question.



 saluei:

                if some condition meet:


What kind of condition is this? Does it involve any operation with parameters?



 saluei:

            for n,x in self.model.named_parameters():
                if some condition meet:
                   reg_params = torch.cat([reg_params,x[[1,2],:,:,:].view(-1)]) #index 1 and 2 is sample



I am not sure if there is an issue with this code.
Can you change it as follows and try?
reg_params = []
for n,x in self.model.named_parameters():
    if some condition meet:
        reg_params.append(reg_params,x[[1,2],:,:,:].view(-1)) #index 1 and 2 is sample

reg_params = torrch.cat(reg_params, dim=0)

It will be great if you could provide a compact runnable code to see whats the issue.