Fix set_grad for extension backends
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/23516
Test Plan: Imported from OSS
Differential Revision: D16546732
Pulled By: li-roy
fbshipit-source-id: bbf9498de98fd807c64862d628da35d0097f2ee0