mlx-apple-silicon
БесплатноБез исполняемых скриптовНе проверенRun LLMs on Apple Silicon with MLX/mlx_lm - unified memory, 4-bit quantization, streaming generation, prompt caching. Optimal for M-series chips.
от plurigrid★ 73 звезды на GitHubОб этом скилле
MLX Apple Silicon Skill
"Unified memory means no GPU↔CPU transfers - arrays live in shared memory."
Trit: +1 (PLUS - generative) Color: Warm (optimistic/fast)
Overview
MLX is Apple's ML framework for Apple Silicon:
- Unified Memory: No GPU↔CPU data transfers
- Lazy Evaluation: Compute only what's needed
- Metal Backend: Native GPU acceleration
- 4-bit Quantization: 75% smaller models
MLX-LM provides high-level LLM APIs.
Quick Start
# Install (macOS Apple Silicon)
pip install mlx mlx-lm
# Install (Linux CUDA - v0.28+)
pip install "mlx[cuda]"
# Generate text
mlx_lm.generate --model mlx-community/Mistral-7B-Instruct-v0.3-4bit \
--prompt "Hello" --max-tokens 100
# Interactive chat
mlx_lm.chat --model mlx-community/Mistral-7B-Instruct-v0.3-4bit
# Vision/Multimodal (mlx-vlm)
pip install mlx-vlm
mlx_vlm.chat --model mlx-community/Qwen2.5-VL-7B-Instruct-4bit
Python API
Basic Generation
from mlx_lm import load, generate
# Load 4-bit quantized model
model, tokenizer = load("mlx-community/Mistral-7B-Instruct-v0.3-4bit")
# Generate
messages = [{"role": "user", "content": "Write a haiku"}]
prompt = tokenizer.apply_chat_template(messages, add_generation_prompt=True)
text = generate(model, tokenizer, prompt=prompt, max_tokens=100)
print(text)
Streaming Generation
from mlx_lm import load, stream_generate
model, tokenizer = load("mlx-community/Mistral-7B-Instruct-v0.3-4bit")
for response in stream_generate(model, tokenizer, prompt="Hello", max_tokens=100):
print(response.text, end="", flush=True)
# response.token, response.logprobs, response.generation_tps available
Batch Generation
from mlx_lm import load, batch_generate
model, tokenizer = load("mlx-community/Mistral-7B-Instruct-v0.3-4bit")
prompts = ["Story about AI", "Explain ML", "Write a poem"]
result = batch_generate(model, tokenizer, prompts, max_tokens=100)
for text in result.texts:
print(text)
Sampling Control
from mlx_lm import load, generate
from mlx_lm.sample_utils import make_sampler
model, tokenizer = load("mlx-community/Mistral-7B-Instruct-v0.3-4bit")
sampler = make_sampler(
temp=0.7, # Temperature
top_p=0.9, # Nucleus sampling
top_k=50, # Top-k sampling
min_p=0.05, # Min probability threshold
repetition_penalty=1.1
)
text = generate(model, tokenizer, prompt="Tell me a joke", sampler=sampler)
Prompt Caching (Multi-turn)
from mlx_lm import load, stream_generate
from mlx_lm.models.cache import make_prompt_cache, save_prompt_cache, load_prompt_cache
model, tokenizer = load("mlx-community/Mistral-7B-Instruct-v0.3-4bit")
# Create cache for system prompt + context
system = "You are an expert. " + long_context
cache = make_prompt_cache(model)
# Prime the cache
for r in stream_generate(model, tokenizer, system, prompt_cache=cache, max_tokens=1):
break
# Save for reuse
save_prompt_cache("my_cache.safetensors", cache)
# Later: reuse with different queries
cache = load_prompt_cache("my_cache.safetensors")
for r in stream_generate(model, tokenizer, "What is 2+2?", prompt_cache=cache, max_tokens=50):
print(r.text, end="", flush=True)
KV Cache Rotation (Long Sequences)
from mlx_lm import load, generate
model, tokenizer = load("mlx-community/Mistral-7B-Instruct-v0.3-4bit")
# Limit KV cache to 512 tokens (bounded memory for long sequences)
text = generate(
model, tokenizer,
prompt="Very long context...",
max_kv_size=512,
max_tokens=1000
)
Speculative Decoding
from mlx_lm import load, stream_generate
# Main model
model, tokenizer = load("mlx-community/Mistral-7B-Instruct-v0.3-4bit")
# Faster draft model
draft_model, _ = load("mlx-community/Mistral-3B-Instruct-4bit")
for r in stream_generate(
model, tokenizer,
prompt="Tell me about ML",
draft_model=draft_model,
num_draft_tokens=3,
max_tokens=512
):
print(r.text, end="", flush=True)
Model Conversion & Quantization
from mlx_lm import convert
# Download, quantize, and optionally upload
convert(
hf_path="mistralai/Mistral-7B-Instruct-v0.3",
mlx_path="./my-mistral-4bit",
quantize=True,
q_bits=4, # 4-bit, 8-bit, or MXFP4/NVFP4
q_group_size=64,
dtype="float16",
upload_repo="mlx-community/my-mistral-4bit" # Optional
)
# CLI conversion
mlx_lm.convert --hf-path mistralai/Mistral-7B-Instruct-v0.3 \
-q --upload-repo mlx-community/my-mistral-4bit
LoRA/QLoRA Fine-Tuning
LoRALinear Adapter
import mlx.core as mx
import mlx.nn as nn
class LoRALinear(nn.Module):
"""Low-Rank Adaptation: W' = W + scale * (A @ B)"""
def __init__(self, input_dims, output_dims, r=8, scale=20.0, dropout=0.0):
self.linear = nn.Linear(inp
Установить mlx-apple-silicon в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
FAQ
Что делает скилл mlx-apple-silicon?
Run LLMs on Apple Silicon with MLX/mlx_lm - unified memory, 4-bit quantization, streaming generation, prompt caching. Optimal for M-series chips.
Как установить скилл mlx-apple-silicon?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл mlx-apple-silicon запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic