For me this looks different:
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-2-c48dcde9ba4c> in <module>
     24 out = MyBadFn.apply(inp)
     25 
---> 26 out.sum().backward()

venv/lib/python3.8/site-packages/torch/tensor.py in backward(self, gradient, retain_graph, create_graph)
    193                 products. Defaults to ``False``.
    194         """
--> 195         torch.autograd.backward(self, gradient, retain_graph, create_graph)
    196 
    197     def register_hook(self, hook):

venv/lib/python3.8/site-packages/torch/autograd/__init__.py in backward(tensors, grad_tensors, retain_graph, create_graph, grad_variables)
     95         retain_graph = create_graph
     96 
---> 97     Variable._execution_engine.run_backward(
     98         tensors, grad_tensors, retain_graph, create_graph,
     99         allow_unreachable=True)  # allow_unreachable flag

RuntimeError: Function 'MyBadFnBackward' returned nan values in its 0th output.

Regarding my “real” problem: I seem to have gradient explosion and am now trying to figure out why.
Edit: I think my Jupyter Notebook is messing with the errors. When I run this in a normal Python file, I get the following instead:
venv/bin/python test.py
Warning: Traceback of forward call that caused the error:
  File "test.py", line 24, in <module>
    out = MyBadFn.apply(inp)
 (print_stack at /pytorch/torch/csrc/autograd/python_anomaly_mode.cpp:57)
Traceback (most recent call last):
  File "test.py", line 26, in <module>
    out.sum().backward()
  File "venv/lib/python3.8/site-packages/torch/tensor.py", line 195, in backward
    torch.autograd.backward(self, gradient, retain_graph, create_graph)
  File "venv/lib/python3.8/site-packages/torch/autograd/__init__.py", line 97, in backward
    Variable._execution_engine.run_backward(
RuntimeError: Function 'MyBadFnBackward' returned nan values in its 0th output.