Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions vllm_mlx/utils/mamba_cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,18 @@ class BatchMambaCache(MambaCache):
mlx-lm's BatchGenerator, specifically the `extract` method.
"""

def __init__(self, left_padding: Optional[List[int]] = None):
def __init__(self, left_padding: Optional[List[int]] = None, size: int = 2):
"""
Initialize BatchMambaCache.

Args:
left_padding: Amount of left padding for each sequence in batch
size: Number of state arrays (default 2 for Mamba models)
"""
super().__init__(left_padding=left_padding)
if HAS_MAMBA_CACHE:
super().__init__(left_padding=left_padding)
else:
super().__init__(size=size, left_padding=left_padding)
self._batch_size = len(left_padding) if left_padding else 0

def extract(self, idx: int) -> MambaCache:
Expand All @@ -54,7 +58,11 @@ def extract(self, idx: int) -> MambaCache:
Returns:
A new MambaCache with the extracted state
"""
cache = MambaCache()
size = len(self.cache)
if HAS_MAMBA_CACHE:
cache = MambaCache()
else:
cache = MambaCache(size=size)
# Extract the state arrays for this index
cache.cache = [
mx.contiguous(c[idx : idx + 1]) if c is not None else None
Expand Down
Loading