Issue with tensor: RuntimeError element 0 of tensors does not require grad and does not have a grad_fn

The issue is that you are converting tensors to numpy and it breaks the computational graph. I have provided a solution in your first code as there is easier way to achieve combine_channel.