Thanks for taking the time to go through the notebook. I really appreciate it!
I am still a beginner to Pytorch, could you please elaborate a bit on what you mean, specially regarding the.torch.autograd.set_detect_anomaly(True) ?
Regarding getting the Inf at last cell, please select and copy the numerical values of the tensor from cell-17 output, and paste it inside the cell-21, assigning it to the variable X_new = torch.tensor( paste here ). Afterwards, if I use the Loss function on this copy-pasted variable:  X_new in cell 22, I get a valid number as output. But this same, matrix was giving Loss = inf in cell-18 and inside the main training code-block.
If it again gives Inf in the last cell, changing the two random.seed()s at the start only 1 or 2 times will surely generate this scenario.

Screen Shot 2019-09-04 at 9.28.27 PM.png2276×1282 293 KB

After copying and pasting this matrix to the cell21, passing this numbers doesn’t generate Inf from the loss function, as it generated in Cell-18.

Screen Shot 2019-09-04 at 9.31.19 PM.png2270×1038 321 KB

What effect is grad_fn having on these numbers?
Thanks again!