cache-dit 0.3.1__py3-none-any.whl → 0.3.3__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cache-dit might be problematic. Click here for more details.

Files changed (34) hide show
  1. cache_dit/__init__.py +1 -0
  2. cache_dit/_version.py +2 -2
  3. cache_dit/cache_factory/__init__.py +3 -6
  4. cache_dit/cache_factory/block_adapters/block_adapters.py +21 -64
  5. cache_dit/cache_factory/cache_adapters/__init__.py +0 -1
  6. cache_dit/cache_factory/cache_adapters/cache_adapter.py +82 -21
  7. cache_dit/cache_factory/cache_blocks/__init__.py +4 -0
  8. cache_dit/cache_factory/cache_blocks/offload_utils.py +115 -0
  9. cache_dit/cache_factory/cache_blocks/pattern_base.py +3 -0
  10. cache_dit/cache_factory/cache_contexts/__init__.py +10 -8
  11. cache_dit/cache_factory/cache_contexts/cache_context.py +186 -117
  12. cache_dit/cache_factory/cache_contexts/cache_manager.py +63 -131
  13. cache_dit/cache_factory/cache_contexts/calibrators/__init__.py +132 -0
  14. cache_dit/cache_factory/cache_contexts/{v2/calibrators → calibrators}/foca.py +1 -1
  15. cache_dit/cache_factory/cache_contexts/{v2/calibrators → calibrators}/taylorseer.py +7 -2
  16. cache_dit/cache_factory/cache_interface.py +128 -111
  17. cache_dit/cache_factory/params_modifier.py +87 -0
  18. cache_dit/metrics/__init__.py +3 -1
  19. cache_dit/utils.py +12 -21
  20. {cache_dit-0.3.1.dist-info → cache_dit-0.3.3.dist-info}/METADATA +200 -434
  21. {cache_dit-0.3.1.dist-info → cache_dit-0.3.3.dist-info}/RECORD +27 -31
  22. cache_dit/cache_factory/cache_adapters/v2/__init__.py +0 -3
  23. cache_dit/cache_factory/cache_adapters/v2/cache_adapter_v2.py +0 -524
  24. cache_dit/cache_factory/cache_contexts/taylorseer.py +0 -102
  25. cache_dit/cache_factory/cache_contexts/v2/__init__.py +0 -13
  26. cache_dit/cache_factory/cache_contexts/v2/cache_context_v2.py +0 -288
  27. cache_dit/cache_factory/cache_contexts/v2/cache_manager_v2.py +0 -799
  28. cache_dit/cache_factory/cache_contexts/v2/calibrators/__init__.py +0 -81
  29. /cache_dit/cache_factory/cache_blocks/{utils.py → pattern_utils.py} +0 -0
  30. /cache_dit/cache_factory/cache_contexts/{v2/calibrators → calibrators}/base.py +0 -0
  31. {cache_dit-0.3.1.dist-info → cache_dit-0.3.3.dist-info}/WHEEL +0 -0
  32. {cache_dit-0.3.1.dist-info → cache_dit-0.3.3.dist-info}/entry_points.txt +0 -0
  33. {cache_dit-0.3.1.dist-info → cache_dit-0.3.3.dist-info}/licenses/LICENSE +0 -0
  34. {cache_dit-0.3.1.dist-info → cache_dit-0.3.3.dist-info}/top_level.txt +0 -0
@@ -1,81 +0,0 @@
1
- from cache_dit.cache_factory.cache_contexts.v2.calibrators.base import (
2
- CalibratorBase,
3
- )
4
- from cache_dit.cache_factory.cache_contexts.v2.calibrators.taylorseer import (
5
- TaylorSeerCalibrator,
6
- )
7
- from cache_dit.cache_factory.cache_contexts.v2.calibrators.foca import (
8
- FoCaCalibrator,
9
- )
10
-
11
- import dataclasses
12
- from typing import Any, Dict
13
-
14
-
15
- from cache_dit.logger import init_logger
16
-
17
- logger = init_logger(__name__)
18
-
19
-
20
- @dataclasses.dataclass
21
- class CalibratorConfig: # no V1
22
- enable_calibrator: bool = False
23
- enable_encoder_calibrator: bool = False
24
- calibrator_type: str = "taylorseer" # taylorseer or foca, etc.
25
- calibrator_cache_type: str = "residual" # residual or hidden_states
26
- calibrator_kwargs: Dict[str, Any] = dataclasses.field(default_factory=dict)
27
-
28
- def strify(self) -> str:
29
- return "CalibratorBase"
30
-
31
- def to_kwargs(self) -> Dict:
32
- return self.calibrator_kwargs.copy()
33
-
34
-
35
- @dataclasses.dataclass
36
- class TaylorSeerCalibratorConfig(CalibratorConfig):
37
- enable_calibrator: bool = True
38
- enable_encoder_calibrator: bool = True
39
- calibrator_type: str = "taylorseer"
40
- taylorseer_order: int = 1
41
-
42
- def strify(self) -> str:
43
- if self.taylorseer_order:
44
- return f"TaylorSeer_O({self.taylorseer_order})"
45
- return "TaylorSeer_O(0)"
46
-
47
- def to_kwargs(self) -> Dict:
48
- kwargs = self.calibrator_kwargs.copy()
49
- kwargs["n_derivatives"] = self.taylorseer_order
50
- return kwargs
51
-
52
-
53
- @dataclasses.dataclass
54
- class FoCaCalibratorConfig(CalibratorConfig):
55
- enable_calibrator: bool = True
56
- enable_encoder_calibrator: bool = True
57
- calibrator_type: str = "foca"
58
-
59
- def strify(self) -> str:
60
- return "FoCa"
61
-
62
-
63
- class Calibrator:
64
- _supported_calibrators = [
65
- "taylorseer",
66
- ]
67
-
68
- def __new__(
69
- cls,
70
- calibrator_config: CalibratorConfig,
71
- ) -> CalibratorBase:
72
- assert (
73
- calibrator_config.calibrator_type in cls._supported_calibrators
74
- ), f"Calibrator {calibrator_config.calibrator_type} is not supported now!"
75
-
76
- if calibrator_config.calibrator_type.lower() == "taylorseer":
77
- return TaylorSeerCalibrator(**calibrator_config.to_kwargs())
78
- else:
79
- raise ValueError(
80
- f"Calibrator {calibrator_config.calibrator_type} is not supported now!"
81
- )