Skip to content
Open
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions mlx_lm/models/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,9 @@ def merge(cls, caches):
return cache

def empty(self):
# Models can create ArraysCache(size=0) for non-attention layers, producing an empty self.cache list
if len(self.cache) == 0:
return True
return self.cache[0] is None

@property
Expand Down
7 changes: 7 additions & 0 deletions mlx_lm/models/switch_layers.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,13 @@ def __call__(self, x, indices) -> mx.array:

return x.squeeze(-2)

# quantized experts with SwiGLU; required for quantized ZAYA compatibility
def to_quantized(self, group_size: int = 64, bits: int = 4, mode: str = "affine"):
"""Quantize the SwitchLinear sublayers."""
self.gate_proj = self.gate_proj.to_quantized(group_size, bits, mode)
self.up_proj = self.up_proj.to_quantized(group_size, bits, mode)
self.down_proj = self.down_proj.to_quantized(group_size, bits, mode)


class SwitchMLP(nn.Module):
def __init__(
Expand Down
Loading