fromtypingimportList,Tupleimportpackaging.versionaspvimporttorchimporttransformersimporttransformers.cache_utilsifpv.Version(transformers.__version__)>pv.Version("4.49.99999"):defmake_dynamic_cache(key_value_pairs:List[Tuple[torch.Tensor,torch.Tensor]],)->transformers.cache_utils.DynamicCache:""" Creates an instance of :class:`transformers.cache_utils.DynamicCache`. This version is valid for ``transformers >= 4.50``. :param key_value_pairs: list of pairs of (key, values) :return: :class:`transformers.cache_utils.DynamicCache` """returntransformers.cache_utils.DynamicCache(key_value_pairs)else:
[docs]defmake_dynamic_cache(key_value_pairs:List[Tuple[torch.Tensor,torch.Tensor]],)->transformers.cache_utils.DynamicCache:""" Creates an instance of :class:`transformers.cache_utils.DynamicCache`. This version is valid for ``transformers < 4.50``. :param key_value_pairs: list of pairs of (key, values) :return: :class:`transformers.cache_utils.DynamicCache` """cache=transformers.cache_utils.DynamicCache(len(key_value_pairs))fori,(key,value)inenumerate(key_value_pairs):cache.update(key,value,i)returncache