for the visualization : Print Autograd Graph
for the hook I let you look at the doc explaining how to use it.