Skip to content

Commit 1748fbc

Browse files
committed
fix dynamiccache
1 parent ccc8552 commit 1748fbc

2 files changed

Lines changed: 11 additions & 0 deletions

File tree

CHANGELOGS.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Change Logs
44
0.9.1
55
+++++
66

7+
* :pr:`408`: fix torch_deepcopy for empty DynamicCache and transformers==5.1.0
8+
79
0.9.0
810
+++++
911

onnx_diagnostic/helpers/torch_helper.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,15 @@ def torch_deepcopy(value: Any) -> Any:
850850
if value.__class__.__name__ == "DynamicCache":
851851
from .cache_helper import CacheKeyValue
852852

853+
if (
854+
hasattr(value, "layers")
855+
and len(value.layers) == 1
856+
and value.layers[0].keys is None
857+
):
858+
import transformers
859+
860+
return transformers.cache_utils.DynamicCache(None)
861+
853862
ca = CacheKeyValue(value)
854863
pairs = list(zip(ca.key_cache, ca.value_cache))
855864
assert not hasattr(value, "layers") or len(value.layers) == len(pairs), (

0 commit comments

Comments
 (0)