Move pattern match for foreach before bulky if-else in `save_variables` (#100445)
One caveat could be that the first if branch doesn't seem to use `arg.expr` at all.
fixes https://github.com/pytorch/pytorch/pull/96405#discussion_r1175669480.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/100445
Approved by: https://github.com/soulitzer