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

Method __init__

deepspeed/utils/static_cache.py:286–313  ·  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

284 is_compileable = True
285
286 def __init__(
287 self,
288 config,
289 batch_size: int = 1,
290 max_cache_len: int = 4096,
291 device=None,
292 dtype=None,
293 ):
294 self.config = config
295 text_config = getattr(config, "text_config", config)
296 num_layers = getattr(text_config, "num_hidden_layers", 1)
297 # Hybrid families (e.g. qwen3_5) mix full_attention and
298 # linear_attention blocks behind one decoder-layer list; mirror the
299 # split so KV slots and GDN pass-through slots line up by index.
300 layer_types = getattr(text_config, "layer_types", None) or ["full_attention"] * num_layers
301 self._layers = [
302 DSStaticGDNSlot(max_cache_len) if t == "linear_attention" else DeepSpeedStaticLayer(max_cache_len)
303 for t in layer_types
304 ]
305 self._max_cache_len = max_cache_len
306 self._write_position: torch.Tensor | None = None
307
308 if dtype is not None and device is not None and batch_size > 0:
309 num_heads = getattr(text_config, "num_key_value_heads", getattr(text_config, "num_attention_heads", 1))
310 # head_dim is not always hidden_size // num_attention_heads, so prefer the config value
311 head_dim = getattr(text_config, "head_dim", None) or (getattr(text_config, "hidden_size", 1) //
312 getattr(text_config, "num_attention_heads", 1))
313 self.early_initialization(batch_size, num_heads, head_dim, dtype, device)
314
315 @property
316 def layers(self):

Callers

nothing calls this directly

Calls 3

early_initializationMethod · 0.95
DSStaticGDNSlotClass · 0.85

Tested by

no test coverage detected