Check for grad mode enabled in dynamic shape fusion check (#72161)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/72161
Following logic here: https://github.com/pytorch/pytorch/blob/3dce68fdf49ead9c659e15b8b641c2b78220c1a4/aten/src/ATen/core/tensor_type.cpp#L329
Test Plan: Imported from OSS
Reviewed By: navahgar
Differential Revision: D33934368
Pulled By: eellison
fbshipit-source-id: 8555ef72070559905f65c6e883a7ae49e5bbbdc3
(cherry picked from commit 1db78befd65edf5ee79621919b9c97796bb9d2b6)