MCPcopy Create free account
hub / github.com/ModalityDance/Omni-R1 / update

Method update

src/transformers/src/transformers/cache_utils.py:34–58  ·  view source on GitHub ↗

Updates the cache with the new `key_states` and `value_states` for the layer `layer_idx`. Parameters: key_states (`torch.Tensor`): The new key states to cache. value_states (`torch.Tensor`): The new value states to cache.

(
        self,
        key_states: torch.Tensor,
        value_states: torch.Tensor,
        layer_idx: int,
        cache_kwargs: Optional[Dict[str, Any]] = None,
    )

Source from the content-addressed store, hash-verified

32 super().__init__()
33
34 def update(
35 self,
36 key_states: torch.Tensor,
37 value_states: torch.Tensor,
38 layer_idx: int,
39 cache_kwargs: Optional[Dict[str, Any]] = None,
40 ) -> Tuple[torch.Tensor, torch.Tensor]:
41 """
42 Updates the cache with the new `key_states` and `value_states` for the layer `layer_idx`.
43
44 Parameters:
45 key_states (`torch.Tensor`):
46 The new key states to cache.
47 value_states (`torch.Tensor`):
48 The new value states to cache.
49 layer_idx (`int`):
50 The index of the layer to cache the states for.
51 cache_kwargs (`Dict[str, Any]`, `optional`):
52 Additional arguments for the cache subclass. These are specific to each subclass and allow new types of
53 cache to be created.
54
55 Return:
56 A tuple containing the updated key and value states.
57 """
58 raise NotImplementedError("Make sure to implement `update` in a subclass.")
59
60 def get_seq_length(self, layer_idx: Optional[int] = 0) -> int:
61 """Returns the sequence length of the cached states. A layer index can be optionally passed."""

Callers 15

extract_warningsFunction · 0.45
get_model_classesFunction · 0.45
get_job_timeFunction · 0.45
get_all_model_namesFunction · 0.45
get_job_linksFunction · 0.45
get_artifacts_linksFunction · 0.45
reduce_by_errorFunction · 0.45

Calls

no outgoing calls

Tested by 15

get_model_classesFunction · 0.36
test_stepMethod · 0.36
mockenv_contextFunction · 0.36
get_paramsFunction · 0.36
_execute_with_envMethod · 0.36