I didn’t understand properly, where you trying to me implement in the following manner
for epoch in epochs:
    for idx, batch in enumerate(test_loader):
        x, y = batch['img'], batch['label']
        h = x.register_hook()
        output = model(x)
        optim.zero_grad()
        loss = criterion(output,y)
        loss.backward()
        optimizer.step()
    writer.add_histogram("conv1grad",h[0],epoch)
    writer.add_histogram("conv2grad",h[1],epoch)

Something like this !?
Also can you please tell me how to index inside Sequential Block if my implementation is correct.
Thanks