Compute input gradient only if required (CPU) (#66069)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/66069
Test Plan: Imported from OSS
Reviewed By: dagitses
Differential Revision: D31431803
Pulled By: albanD
fbshipit-source-id: d4caba5fa092e4ee7411502021836370082670b2