Fix `toIValue` dict iteration (#26856)
Summary:
It's not clear why, but using the `[]` accessory in pybind was causing an error (for something I ran into while scripting MaskR-CNN)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/26856
Pulled By: driazati
Differential Revision: D17589635
fbshipit-source-id: 142a9b4e30bcf2b65f1ba03c2d6775f2baff43f5