try hooking tensors of interest with:
def _on_gradient_of_watched(name,gr):
	gr = gr.detach().cpu().clone()
	...

def watch_tensor(name: str, te) -> None:
	if te.requires_grad:
		te.register_hook(lambda gr: _on_gradient_of_watched(name, gr))