Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fusing module with multiple hooks causes RuntimeError: OrderedDict mutated during iteration in fuse_known_modules #69158

Open
bfineran opened this issue Nov 30, 2021 · 2 comments
Assignees
Labels
low priority We're unlikely to get around to doing this in the near future oncall: quantization Quantization support in PyTorch Stale triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module

Comments

@bfineran
Copy link

bfineran commented Nov 30, 2021

馃悰 Bug

if a module that is to be fused by torch.quantization.fuse_modules.fuse_known_modules has multiple hooks, then a RuntimeError: OrderedDict mutated during iteration will be raised since the loops iterate over the dict items() but delete from the dict during iteration.

To Reproduce

from torch.quantization.fuse_modules import fuse_known_modules
from torch.nn import Conv2d, ReLU

conv = Conv2d(10, 10, (3,3))
relu = ReLU()

# register any forward hooks to relu or pre forward hooks to conv
relu.register_forward_hook(lambda x: None)
relu.register_forward_hook(lambda x: None)

fuse_known_modules([conv, relu])

A quick fix would be unwrapping the .items() iterations into lists

cc @jerryzh168 @jianyuh @raghuramank100 @jamesr66a @vkuzo @jgong5 @Xia-Weiwen @leslie-fang-intel

@samdow samdow added oncall: quantization Quantization support in PyTorch triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Nov 30, 2021
@github-actions github-actions bot added this to Need Triage in Quantization Triage Nov 30, 2021
@z-a-f
Copy link
Contributor

z-a-f commented Dec 1, 2021

@jerryzh168 How do we support hooks in the fustion right now?

@z-a-f z-a-f removed the triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module label Dec 1, 2021
@github-actions github-actions bot added the Stale label Jan 30, 2022
@andrewor14 andrewor14 added low priority We're unlikely to get around to doing this in the near future triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module labels Oct 18, 2023
@andrewor14
Copy link
Contributor

@bfineran Any plans to reopen your PR, which was closed automatically from being stale?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
low priority We're unlikely to get around to doing this in the near future oncall: quantization Quantization support in PyTorch Stale triaged This issue has been looked at a team member, and triaged and prioritized into an appropriate module
Projects
Quantization Triage
  
Need Triage
Development

Successfully merging a pull request may close this issue.

5 participants