Skip to content

Instantly share code, notes, and snippets.

@anijain2305
Created April 10, 2024 06:07
Show Gist options
  • Save anijain2305/cf8e44096a90cdb90b931cf8972a3b10 to your computer and use it in GitHub Desktop.
Save anijain2305/cf8e44096a90cdb90b931cf8972a3b10 to your computer and use it in GitHub Desktop.
import torch
from collections import OrderedDict
torch._dynamo.config.error_on_recompile = True
d = {
30: 4,
25: 2,
20: 1,
}
d = OrderedDict(d)
# This line causes the problem
d.move_to_end(30)
@torch.compile(backend="eager")
def fn(x, d):
return x * d[30] * d[25]
fn(torch.randn(4), d)
fn(torch.randn(4), d)
@anijain2305
Copy link
Author

Run it with this cmd, it will fail

TORCHDYNAMO_CPP_GUARD_MANAGER=1 python examples/ord_dicts.py

My debug prints show that odict_keys order is different from PyDict_Next

DictGuardManager-sideA: L['d'] keys=odict_keys([25, 20, 30])
DictGuardManager-sideB: L['d'] size=3 key=30
DictGuardManager-sideB: L['d'] size=3 key=25
DictGuardManager-sideB: L['d'] size=3 key=20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment