I’d recommend looking at Let’s talk about the PyTorch dispatcher : ezyang’s blog
and What (and Why) is __torch_dispatch__?.