Skip to content

Commit f36359a

Browse files
authored
remove non-deterministic hashing (#243)
1 parent 0e3c278 commit f36359a

File tree

2 files changed

+2
-8
lines changed

2 files changed

+2
-8
lines changed

autointent/_hash.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,13 @@ class Hasher:
1515
hashing embeddings from :py:class:`autointent.Embedder`.
1616
"""
1717

18-
def __init__(self, strict: bool = False) -> None:
18+
def __init__(self) -> None:
1919
"""Initialize the Hasher instance and sets up the internal xxhash state.
2020
2121
This state will be used for progressively hashing values using the
2222
`update` method and obtaining the final digest using `hexdigest`.
2323
"""
2424
self._state = xxhash.xxh64()
25-
self.strict = strict
2625

2726
def hash(self, value: Any) -> int: # noqa: ANN401
2827
"""Generate a hash for the given value using xxhash.
@@ -33,11 +32,6 @@ def hash(self, value: Any) -> int: # noqa: ANN401
3332
Returns:
3433
The resulting hash digest as a hexadecimal string.
3534
"""
36-
if hasattr(value, "__hash__") and value.__hash__ not in {None, object.__hash__}:
37-
return hash(value)
38-
if self.strict:
39-
msg = "Object is not hashable."
40-
raise ValueError(msg)
4135
return xxhash.xxh64(pickle.dumps(value)).intdigest()
4236

4337
def update(self, value: Any) -> None: # noqa: ANN401

autointent/generation/_cache.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def _get_cache_key(self, messages: list[Message], output_model: type[T], generat
131131
Returns:
132132
Cache key as a hexadecimal string.
133133
"""
134-
hasher = Hasher(strict=True)
134+
hasher = Hasher()
135135
hasher.update(json.dumps(messages))
136136
hasher.update(json.dumps(output_model.model_json_schema()))
137137
hasher.update(json.dumps(generation_params))

0 commit comments

Comments
 (0)