[caffe2/torchgen] Fix codegen non-determinism (#101286)
Summary:
Fix several cases of leaking set-iteration-order to generated sources, causing non-determinism in generated code.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/101286
Approved by: https://github.com/Skylion007, https://github.com/albanD