Fix some sign comparisons and a loop (#61663)
Summary: Pull Request resolved: https://github.com/pytorch/pytorch/pull/61663
Test Plan: Sandcastle
Reviewed By: ngimel
Differential Revision: D29696766
fbshipit-source-id: eb5a77bd0cfafeb6209d274f121f10dca20d461a