Update:
We do not actually currently support recursive class definitions. I didn’t remember when I first replied. https://github.com/pytorch/pytorch/pull/21842 17 improves the error message in this case.
We will likely support it soon (before the next release) but for now it will not work.