[cond] error on closed over variables (#99367)
As reported in https://github.com/pytorch/pytorch/issues/90469, the implementation of inlining nested function branches for `cond` doesn't properly handle variables captured from outer scopes. This leads to some examples accidentally working, some others generating incorrect code that don't crash but do the wrong thing, and still others that outright crash because of references to non-existent variables.
Properly supporting closed variables is tricky (see https://github.com/pytorch/pytorch/pull/91981 for an abandoned attempt). While this is definitely something we should be able to support longer term, for now it is better to explicitly error and suggest the fix to the user (amounting to rewriting branches to take closed variables explicitly).
Differential Revision: [D45058621](https://our.internmc.facebook.com/intern/diff/D45058621/)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/99367
Approved by: https://github.com/ezyang, https://github.com/tugsbayasgalan