Thanks for your answer!
Generally, I try to implement something very similar to the f.conv2d layer, i.e., f.conv2d gets a 4D tensor with several layers, iterate over them one by one, and calculates convolution for each layer.
So, my question is how to iterate over 4D tensor one by one?
As you can see in my code, I got a 4D tensor of  layers (images) and iterate over the tensor with ‘double for,’ then I tried to copy results into a new 4D tensor (self.layers).
But I am pretty sure that is the wrong implementation and runs very slow. (The layers suppose to be with trainable parameters for gradients calculation.)