Fix a number of lint perf and safety issues in torch (#59897)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/59897
Test Plan: Sandcastle
Reviewed By: ngimel
Differential Revision: D29037012
fbshipit-source-id: 7c16286d5fc2b67964fb65f8374dfff4d1a7aefb