[JIT] Use type cache in erasing shape information (#55828)
Summary:
`unshapedType` can be very slow on a graph with many modules and recursively contained classes, because each Type you have to recursively descend and map over. Speed it up with a type cache.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/55828
Reviewed By: ngimel
Differential Revision: D27717995
Pulled By: eellison
fbshipit-source-id: f1d502bef0356e78100c27bf00f6caf08a75d68c