[forward ad] Fix codegen to ignore undefined outputs (#81114) (#81114) (#81878)
Summary:
I don't think there's a way to avoid functions returning undefined tensors as outputs, so codegen will have to detect them before calling _set_fw_grad. Alternatively, we can just make calling _set_fw_grad with undefined self a no-op, but I'm biasing toward keeping _set_fw_grad more strict in case it is called in other areas.
Fixes https://github.com/pytorch/pytorch/issues/81111
Pull Request resolved: https://github.com/pytorch/pytorch/pull/81114
Approved by: https://github.com/albanD
Test Plan: contbuild & OSS CI, see https://hud.pytorch.org/commit/pytorch/pytorch/f69768fed4e0b00a5493b49a9646f587695b5e78
Reviewed By: mehtanirav
Differential Revision: D37754419
Pulled By: soulitzer
fbshipit-source-id: ca5f2e703a838fa5cbc161604c5b98460456cdc0
Co-authored-by: soulitzer (Meta Employee) <soulitzer@gmail.com>