Preserve leaf-ness and requires_grad-ness in minified repros (#102899)
Also some minor refactoring
Signed-off-by: Edward Z. Yang <ezyang@meta.com>
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102899
Approved by: https://github.com/albanD