omry / omegaconf

Flexible Python configuration system. The last one you will ever need.
BSD 3-Clause "New" or "Revised" License
1.98k stars 113 forks source link

Hashing of equal DictConfig objects differ #1190

Open esskov opened 3 months ago

esskov commented 3 months ago

Describe the bug It seems there is an issue related to how much metadata or context is passed when hashing a DictConfig object. As a consequence, hashes of two DictConfig objects differ, in cases where the objects are in fact equal. We have observed this in cases where the 2 objects are "sub configs" of the parent DictConfig object.

To Reproduce

import joblib
import hashlib
import pickle
from omegaconf import OmegaConf, DictConfig

d = OmegaConf.create({'a' : {'c': 1}, 'b' : {'c': 1}})

assert joblib.hash(DictConfig(d.a)) == joblib.hash(DictConfig(d.b)) # Passes
assert joblib.hash(d.a) == joblib.hash(d.b) # Fails

assert hashlib.md5(pickle.dumps(DictConfig(d.a))).hexdigest() == hashlib.md5(pickle.dumps(DictConfig(d.b))).hexdigest() # Passes
assert hashlib.md5(pickle.dumps(d.a)).hexdigest() == hashlib.md5(pickle.dumps(d.b)).hexdigest() # Fails

Expected behavior I would expect all 4 assert statements to pass. It is unexpected that hash(d.a) != hash(d.b) when d.a == d.b.

Additional context