I hoped to read module gradients from register_backward_hook
 module.weight.grad

But it is either None or all zeros. What hook should I use for the gradients?
(I can get gradients w/o problem from the training loop).
This is my model and I tested on MNIST.
class M2(nn.Module):
    def __init__(self):
        super().__init__()        
        self.l1 = nn.Linear(28*28, 10)
        
    def forward(self, x):
        x = x.reshape(-1, 28*28)        
        x = F.relu(self.l1(x))        
        return x

Here is the full notebook:

  
      gist.github.com
  
  
    https://gist.github.com/dejanbatanjac/86d02413118cd7fb10b479c1d4c8f318 4
Grad catch.ipynb
{
  "cells": [
    {
      "metadata": {
        "trusted": true
      },
      "cell_type": "code",
      "source": "%matplotlib inline\n\nimport torch\nimport torch.nn as nn\nimport torch.nn.functional as F\nfrom torch.utils.data import DataLoader, Dataset, TensorDataset\nfrom torch.optim import *\nimport torchvision\n\n",
      "execution_count": 1,
      "outputs": []
This file has been truncated. show original