[JIT] Fix toIValue handling of AttributeError when casting ClassType (#49188)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/49188
Test Plan: Imported from OSS
Reviewed By: pbelevich
Differential Revision: D25476573
Pulled By: jamesr66a
fbshipit-source-id: cec296fae71cc0cdf36bde60417d7d3b1aa84198