MCPcopy Create free account
hub / github.com/lingeringlight/START / allocate_inference_cache

Method allocate_inference_cache

models/mamba_simple.py:295–306  ·  view source on GitHub ↗
(self, batch_size, max_seqlen, dtype=None, **kwargs)

Source from the content-addressed store, hash-verified

293 return out.unsqueeze(1), conv_state, ssm_state
294
295 def allocate_inference_cache(self, batch_size, max_seqlen, dtype=None, **kwargs):
296 device = self.out_proj.weight.device
297 conv_dtype = self.conv1d.weight.dtype if dtype is None else dtype
298 conv_state = torch.zeros(
299 batch_size, self.d_model * self.expand, self.d_conv, device=device, dtype=conv_dtype
300 )
301 ssm_dtype = self.dt_proj.weight.dtype if dtype is None else dtype
302 # ssm_dtype = torch.float32
303 ssm_state = torch.zeros(
304 batch_size, self.d_model * self.expand, self.d_state, device=device, dtype=ssm_dtype
305 )
306 return conv_state, ssm_state
307
308 def _get_states_from_cache(self, inference_params, batch_size, initialize_states=False):
309 assert self.layer_idx is not None

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected