MCPcopy Create free account
hub / github.com/deepspeedai/DeepSpeed / __init__

Method __init__

deepspeed/utils/static_cache.py:216–236  ·  view source on GitHub ↗
(
        self,
        config,
        batch_size: int = 1,
        max_cache_len: int = 4096,
        device=None,
        dtype=None,
    )

Source from the content-addressed store, hash-verified

214 """
215
216 def __init__(
217 self,
218 config,
219 batch_size: int = 1,
220 max_cache_len: int = 4096,
221 device=None,
222 dtype=None,
223 ):
224 self.config = config
225 text_config = getattr(config, "text_config", config)
226 num_layers = getattr(text_config, "num_hidden_layers", 1)
227 self._layers = [DeepSpeedStaticLayer(max_cache_len) for _ in range(num_layers)]
228 self._max_cache_len = max_cache_len
229 self._write_position: torch.Tensor | None = None
230
231 if dtype is not None and device is not None and batch_size > 0:
232 num_heads = getattr(text_config, "num_key_value_heads", getattr(text_config, "num_attention_heads", 1))
233 # head_dim is not always hidden_size // num_attention_heads, so prefer the config value
234 head_dim = getattr(text_config, "head_dim", None) or (getattr(text_config, "hidden_size", 1) //
235 getattr(text_config, "num_attention_heads", 1))
236 self.early_initialization(batch_size, num_heads, head_dim, dtype, device)
237
238 @property
239 def layers(self):

Callers

nothing calls this directly

Calls 2

early_initializationMethod · 0.95

Tested by

no test coverage detected