bad_grad.py 610 B

1234567891011121314151617181920212223242526
  1. #!/usr/bin/env python3
  2. # -*- coding: utf-8 -*-
  3. __author__ = "Christian Heider Nielsen"
  4. __doc__ = r"""
  5. Created on 31-10-2020
  6. """
  7. if __name__ == "__main__":
  8. import torch
  9. from draugr.torch_utilities import register_bad_grad_hooks
  10. x = torch.randn(10, 10, requires_grad=True)
  11. y = torch.randn(10, 10, requires_grad=True)
  12. z = x / (y * 0)
  13. z = z.sum() * 2
  14. get_dot = register_bad_grad_hooks(z)
  15. z.backward()
  16. dot = get_dot()
  17. # dot.save('tmp.dot') # to get .dot
  18. # dot.render('tmp') # to get SVG
  19. dot # in Jupyter, you can just render the variable