[Pytorch] Only print gradient of a tensor if it requires_grad (#54446)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/54446
Several people now have run into an issue with printing tensors using lite interpreter in xplat. https://fb.workplace.com/groups/2148543255442743/?multi_permalinks=2620088118288252¬if_id=1616432955971055¬if_t=work_group_activity&ref=notif This is due to the fallback of _fw_grad also requiring autograd to exist. Introduce a new function that can be used to guard against calling _fw_grad if autograd isnt built.
ghstack-source-id: 126334787
Test Plan: ci, tested the guard in by printing in a tensor in a situation where autograd isnt built.
Reviewed By: albanD
Differential Revision: D27239164
fbshipit-source-id: 4b98b4b7770b153bc2c13c95f7d256425e09ef39