def forward_hook(module, input, output):
        layer_inputs.append(input[0])
        layer_outputs.append(output)

    def backward_hook(module, grad_input, grad_output):
        grad_inputs.append(grad_input[0].detach().clone())
        grad_outputs.append(grad_output[0].detach().clone())

    # register_index = 0
    for p in model.modules():
        if isinstance(p, nn.Conv2d):
            p.register_forward_hook(forward_hook)
            p.register_backward_hook(backward_hook)

I just want to get the grad data of every convolution layer in ResNet101
There should be 208 items in the grad list but there are sometimes 207 or 206 or 205.