LFM2-24B-A2B
在 Clore.ai 上部署 Liquid AI 的 LFM2-24B-A2B——混合 SSM+Attention 架构,总参数 24B / 激活参数 2B
最后更新于
这有帮助吗?
这有帮助吗?
pip install vllm>=0.6.0
# 或 最新 版本
pip install git+https://github.com/vllm-project/vllm.gitvllm serve liquid-ai/LFM2-24B-A2B \
--model liquid-ai/LFM2-24B-A2B \
--tensor-parallel-size 1 \
--dtype float16 \
--max-model-len 32768 \
--served-model-name lfm2-24b \
--trust-remote-code \
--disable-log-statsfrom openai import OpenAI
client = OpenAI(
base_url="http://localhost:8000/v1",
api_key="EMPTY"
)
response = client.chat.completions.create(
model="lfm2-24b",
messages=[
{"role": "system", "content": "你是一个专注于技术解释的乐于助人的 AI 助手。"},
{"role": "user", "content": "解释状态空间模型与传统 Transformer 之间的区别"}
],
max_tokens=1024,
temperature=0.7
)
print(response.choices[0].message.content)# 安装 Ollama
curl -fsSL https://ollama.com/install.sh | sh
# 拉取 LFM2 模型
ollama pull liquid-ai/lfm2:24b
# 交互式运行
ollama run liquid-ai/lfm2:24b
# API 模式
ollama serveimport requests
# 简单补全
response = requests.post('http://localhost:11434/api/generate',
json={
'model': 'liquid-ai/lfm2:24b',
'prompt': '写一个使用记忆化的 Python 函数来计算斐波那契数列',
'stream': False
}
)
print(response.json()['response'])
# 聊天格式
chat_response = requests.post('http://localhost:11434/api/chat',
json={
'model': 'liquid-ai/lfm2:24b',
'messages': [
{'role': 'user', 'content': '用通俗的词解释量子纠缠'}
],
'stream': False
}
)
print(chat_response.json()['message']['content'])FROM nvidia/cuda:12.1-devel-ubuntu22.04
# 安装 Python 3.10
RUN apt-get update && apt-get install -y \
python3.10 python3-pip curl && \
rm -rf /var/lib/apt/lists/*
# 安装 vLLM
RUN pip install vllm>=0.6.0 transformers
# 设置环境变量
ENV PYTHONUNBUFFERED=1
# 预下载模型(可选)
# RUN python3 -c "from transformers import AutoModel; AutoModel.from_pretrained('liquid-ai/LFM2-24B-A2B', trust_remote_code=True)"
EXPOSE 8000
CMD ["vllm", "serve", "liquid-ai/LFM2-24B-A2B", \
"--host", "0.0.0.0", \
"--port", "8000", \
"--dtype", "float16", \
"--max-model-len", "16384", \
"--trust-remote-code"]docker build -t lfm2-24b .
docker run --gpus all -p 8000:8000 lfm2-24bimport time
from openai import OpenAI
client = OpenAI(base_url="http://localhost:8000/v1", api_key="EMPTY")
def speed_test():
prompts = [
"用一段话解释机器学习",
"写一个快速的 Python 排序算法",
"描述可再生能源的好处",
"法国的首都是什么以及为什么重要?",
"创建一个简单的 HTML 页面结构"
]
total_tokens = 0
total_time = 0
for prompt in prompts:
start_time = time.time()
response = client.chat.completions.create(
model="lfm2-24b",
messages=[{"role": "user", "content": prompt}],
max_tokens=200,
temperature=0.1
)
end_time = time.time()
tokens = len(response.choices[0].message.content.split())
duration = end_time - start_time
total_tokens += tokens
total_time += duration
print(f"Prompt: {prompt[:30]}...")
print(f"Tokens: {tokens}, Time: {duration:.2f}s, Speed: {tokens/duration:.1f} tok/s\n")
avg_speed = total_tokens / total_time
print(f"Average speed: {avg_speed:.1f} tokens/second")
return avg_speed
# 运行速度测试
speed_test()# 安装 auto-gptq
pip install auto-gptq
# 使用量化模型(显存降至约 ~3GB)
vllm serve liquid-ai/LFM2-24B-A2B-GPTQ \
--model liquid-ai/LFM2-24B-A2B-GPTQ \
--quantization gptq \
--dtype float16 \
--max-model-len 16384# 安装 autoawq
pip install autoawq
# 使用 AWQ 量化模型
vllm serve liquid-ai/LFM2-24B-A2B-AWQ \
--model liquid-ai/LFM2-24B-A2B-AWQ \
--quantization awq \
--dtype float16vllm serve liquid-ai/LFM2-24B-A2B \
--model liquid-ai/LFM2-24B-A2B \
--dtype float16 \
--max-model-len 8192 \
--gpu-memory-utilization 0.85 \
--swap-space 4 \
--trust-remote-codevllm serve liquid-ai/LFM2-24B-A2B \
--model liquid-ai/LFM2-24B-A2B \
--tensor-parallel-size 1 \
--max-num-seqs 32 \
--max-num-batched-tokens 8192 \
--dtype float16 \
--trust-remote-code