Gradcheck got inf outputs

When doing gradcheck, the numerical and analytical outputs are quite similar except for some inf numbers.

 0.7561  0.0000  0.0000  ...   0.0000  0.0000  0.0000
 0.0000  0.9337  0.0000  ...   0.0000  0.0000  0.0000
 0.0000  0.0000  0.8344  ...   0.0000  0.0000  0.0000
          ...             ⋱             ...          
 0.0000  0.0000  0.0000  ...   0.7505  0.0000  0.0000
 0.0000  0.0000  0.0000  ...   0.0000  0.3850  0.0000
 0.0000  0.0000  0.0000  ...   0.0000  0.0000  0.6375
[torch.FloatTensor of size 144x576]
,)
analytical:(
 7.5606e-01  0.0000e+00  0.0000e+00  ...   0.0000e+00  0.0000e+00  0.0000e+00
 0.0000e+00  9.3370e-01  0.0000e+00  ...   0.0000e+00  0.0000e+00  0.0000e+00
 0.0000e+00  0.0000e+00  8.3444e-01  ...   0.0000e+00  0.0000e+00  0.0000e+00
                ...                   ⋱                   ...                
 0.0000e+00  0.0000e+00  0.0000e+00  ...   7.5054e-01  0.0000e+00  0.0000e+00
        inf  0.0000e+00  0.0000e+00  ...   0.0000e+00  3.8502e-01  0.0000e+00
        inf  0.0000e+00  0.0000e+00  ...   0.0000e+00  0.0000e+00  6.3747e-01
[torch.FloatTensor of size 144x576]

Is this meaning my costumed function is not working?

Probably inf grads are not what you want, so no.
You could add a hook to check when it happens.

Best regards

Thomas