add `hasattr()` (#29332)
Summary:
Pull Request resolved: https://github.com/pytorch/pytorch/pull/29332
Even though we're statically typed, this can be useful, e.g. as
shorthand when iterating through a module list.
Test Plan: Imported from OSS
Differential Revision: D18393097
Pulled By: suo
fbshipit-source-id: aa42e955f88d1b8a876d0727055eb596453b9839