|
44 | 44 |
|
45 | 45 | logger = logging.get_logger(__name__) |
46 | 46 | METADATA_FIELDS = ("_from_model_config", "_commit_hash", "_original_object_hash", "transformers_version") |
47 | | -CACHE_CONFIG_MAPPING = {} |
48 | 47 | NEED_SETUP_CACHE_CLASSES_MAPPING = {} |
49 | 48 | QUANT_BACKEND_CLASSES_MAPPING = {} |
50 | 49 | ALL_CACHE_IMPLEMENTATIONS = [] |
|
56 | 55 | HybridChunkedCache, |
57 | 56 | OffloadedHybridCache, |
58 | 57 | OffloadedStaticCache, |
59 | | - QuantizedCacheConfig, |
60 | 58 | QuantoQuantizedCache, |
61 | 59 | SlidingWindowCache, |
62 | 60 | StaticCache, |
63 | | - StaticCacheConfig, |
64 | 61 | ) |
65 | 62 | from .logits_process import SynthIDTextWatermarkLogitsProcessor, WatermarkLogitsProcessor |
66 | 63 |
|
67 | | - CACHE_CONFIG_MAPPING["quantized"] = QuantizedCacheConfig |
68 | | - CACHE_CONFIG_MAPPING["static"] = StaticCacheConfig |
69 | | - CACHE_CONFIG_MAPPING["sliding_window"] = StaticCacheConfig |
70 | | - CACHE_CONFIG_MAPPING["hybrid"] = StaticCacheConfig |
71 | 64 | NEED_SETUP_CACHE_CLASSES_MAPPING = { |
72 | 65 | "static": StaticCache, |
73 | 66 | "offloaded_static": OffloadedStaticCache, |
@@ -188,10 +181,8 @@ class GenerationConfig(PushToHubMixin): |
188 | 181 |
|
189 | 182 | If none is specified, we will use the default cache for the model (which is often [`DynamicCache`]). See |
190 | 183 | our [cache documentation](https://huggingface.co/docs/transformers/en/kv_cache) for further information. |
191 | | - cache_config (`CacheConfig` or `dict`, *optional*, default to `None`): |
192 | | - Arguments used in the key-value cache class can be passed in `cache_config`. Can be passed as a `Dict` and |
193 | | - it will be converted to its respective `CacheConfig` internally. |
194 | | - Otherwise can be passed as a `CacheConfig` class matching the indicated `cache_implementation`. |
| 184 | + cache_config (`dict`, *optional*, default to `None`): |
| 185 | + Arguments used in the key-value cache class can be passed in `cache_config`. |
195 | 186 | return_legacy_cache (`bool`, *optional*, default to `True`): |
196 | 187 | Whether to return the legacy or new format of the cache when `DynamicCache` is used by default. |
197 | 188 |
|
@@ -406,10 +397,6 @@ def __init__(self, **kwargs): |
406 | 397 | self.use_cache = kwargs.pop("use_cache", True) |
407 | 398 | self.cache_implementation = kwargs.pop("cache_implementation", None) |
408 | 399 | self.cache_config = kwargs.pop("cache_config", None) |
409 | | - if self.cache_implementation is not None and self.cache_implementation in CACHE_CONFIG_MAPPING: |
410 | | - cache_config_class = CACHE_CONFIG_MAPPING[self.cache_implementation] |
411 | | - if isinstance(self.cache_config, dict): |
412 | | - self.cache_config = cache_config_class.from_dict(self.cache_config) |
413 | 400 | self.return_legacy_cache = kwargs.pop("return_legacy_cache", None) |
414 | 401 | self.prefill_chunk_size = kwargs.pop("prefill_chunk_size", None) |
415 | 402 |
|
@@ -611,17 +598,6 @@ def validate(self, strict=False): |
611 | 598 | f"Invalid `cache_implementation` ({self.cache_implementation}). Choose one of: " |
612 | 599 | f"{ALL_CACHE_IMPLEMENTATIONS}" |
613 | 600 | ) |
614 | | - if self.cache_config is not None: |
615 | | - cache_class = CACHE_CONFIG_MAPPING.get(self.cache_implementation) |
616 | | - if cache_class is None: |
617 | | - raise ValueError( |
618 | | - "You provided a `cache_config` but the cache implementation you are using " |
619 | | - f"({self.cache_implementation}) does not require any config. Make sure to use the " |
620 | | - "correct cache implementation matching your cache config." |
621 | | - ) |
622 | | - if not isinstance(self.cache_config, cache_class): |
623 | | - self.cache_config = cache_class.from_dict(self.cache_config) |
624 | | - self.cache_config.validate() |
625 | 601 | # 1.3. Performance attributes |
626 | 602 | if self.compile_config is not None and not isinstance(self.compile_config, CompileConfig): |
627 | 603 | raise ValueError( |
|
0 commit comments