Unsloth MCP Server
Unsloth MCP 服务器
Unsloth的 MCP 服务器 - 一个使 LLM 微调速度提高 2 倍且内存减少 80% 的库。
Unsloth 是什么?
Unsloth 是一个可以显著提高微调大型语言模型效率的库:
速度:与标准方法相比,微调速度提高 2 倍
内存:VRAM 使用量减少 80%,允许在消费级 GPU 上对更大的模型进行微调
上下文长度:上下文长度最多增加 13 倍(例如,80GB GPU 上的 Llama 3.3 有 89K 个令牌)
准确性:模型质量或性能没有损失
Unsloth 通过用 OpenAI 的 Triton 语言编写的自定义 CUDA 内核、优化的反向传播和动态 4 位量化实现这些改进。
Related MCP server: Model Context Protocol (MCP) Server
特征
针对 Llama、Mistral、Phi、Gemma 等模型进行优化微调
4 位量化,实现高效训练
扩展上下文长度支持
用于模型加载、微调和推理的简单 API
导出为各种格式(GGUF、Hugging Face 等)
快速入门
安装 Unsloth:
pip install unsloth安装并构建服务器:
cd unsloth-server npm install npm run build添加到 MCP 设置:
{ "mcpServers": { "unsloth-server": { "command": "node", "args": ["/path/to/unsloth-server/build/index.js"], "env": { "HUGGINGFACE_TOKEN": "your_token_here" // Optional }, "disabled": false, "autoApprove": [] } } }
可用工具
检查安装
验证 Unsloth 是否已正确安装在您的系统上。
参数:无
例子:
const result = await use_mcp_tool({
server_name: "unsloth-server",
tool_name: "check_installation",
arguments: {}
});列出支持的型号
获取 Unsloth 支持的所有模型的列表,包括 Llama、Mistral、Phi 和 Gemma 变体。
参数:无
例子:
const result = await use_mcp_tool({
server_name: "unsloth-server",
tool_name: "list_supported_models",
arguments: {}
});加载模型
加载具有 Unsloth 优化的预训练模型,以实现更快的推理和微调。
参数:
model_name(必需):要加载的模型的名称(例如,“unsloth/Llama-3.2-1B”)max_seq_length(可选):模型的最大序列长度(默认值:2048)load_in_4bit(可选):是否以 4 位量化加载模型(默认值:true)use_gradient_checkpointing(可选):是否使用梯度检查点来节省内存(默认值:true)
例子:
const result = await use_mcp_tool({
server_name: "unsloth-server",
tool_name: "load_model",
arguments: {
model_name: "unsloth/Llama-3.2-1B",
max_seq_length: 4096,
load_in_4bit: true
}
});微调模型
使用 LoRA/QLoRA 技术通过 Unsloth 优化对模型进行微调。
参数:
model_name(必需):需要微调的模型的名称dataset_name(必需):用于微调的数据集的名称output_dir(必需):保存微调模型的目录max_seq_length(可选):训练的最大序列长度(默认值:2048)lora_rank(可选):LoRA 微调的排名(默认值:16)lora_alpha(可选):LoRA 微调的 Alpha(默认值:16)batch_size(可选):训练的批次大小(默认值:2)gradient_accumulation_steps(可选):梯度累积步数(默认值:4)learning_rate(可选):训练的学习率(默认值:2e-4)max_steps(可选):最大训练步数(默认值:100)dataset_text_field(可选):数据集中包含文本的字段(默认值:“text”)load_in_4bit(可选):是否使用4位量化(默认值:true)
例子:
const result = await use_mcp_tool({
server_name: "unsloth-server",
tool_name: "finetune_model",
arguments: {
model_name: "unsloth/Llama-3.2-1B",
dataset_name: "tatsu-lab/alpaca",
output_dir: "./fine-tuned-model",
max_steps: 100,
batch_size: 2,
learning_rate: 2e-4
}
});生成文本
使用经过微调的 Unsloth 模型生成文本。
参数:
model_path(必需):微调模型的路径prompt(必需):提示文本生成max_new_tokens(可选):要生成的最大令牌数(默认值:256)temperature(可选):文本生成的温度(默认值:0.7)top_p(可选):文本生成的 Top-p(默认值:0.9)
例子:
const result = await use_mcp_tool({
server_name: "unsloth-server",
tool_name: "generate_text",
arguments: {
model_path: "./fine-tuned-model",
prompt: "Write a short story about a robot learning to paint:",
max_new_tokens: 512,
temperature: 0.8
}
});导出模型
将经过微调的 Unsloth 模型导出为各种格式以供部署。
参数:
model_path(必需):微调模型的路径export_format(必需):导出格式(gguf、ollama、vllm、huggingface)output_path(必需):保存导出模型的路径quantization_bits(可选):量化位(用于 GGUF 导出)(默认值:4)
例子:
const result = await use_mcp_tool({
server_name: "unsloth-server",
tool_name: "export_model",
arguments: {
model_path: "./fine-tuned-model",
export_format: "gguf",
output_path: "./exported-model.gguf",
quantization_bits: 4
}
});高级用法
自定义数据集
您可以通过正确格式化自定义数据集并将其托管在 Hugging Face 上或提供本地路径来使用它们:
const result = await use_mcp_tool({
server_name: "unsloth-server",
tool_name: "finetune_model",
arguments: {
model_name: "unsloth/Llama-3.2-1B",
dataset_name: "json",
data_files: {"train": "path/to/your/data.json"},
output_dir: "./fine-tuned-model"
}
});内存优化
对于有限硬件上的大型模型:
减少批次大小并增加梯度积累步骤
使用 4 位量化
启用梯度检查点
如果可能的话减少序列长度
故障排除
常见问题
CUDA 内存不足:减少批量大小,使用 4 位量化,或尝试更小的模型
导入错误:确保安装了正确版本的 torch、transformers 和 unsloth
未找到模型:请检查您是否正在使用受支持的模型名称或是否有权访问私有模型
版本兼容性
Python:3.10、3.11 或 3.12(不是 3.13)
CUDA:建议使用 11.8 或 12.1+
PyTorch:推荐 2.0+
性能基准
模型 | 显存 | 不懒惰的速度 | 显存减少 | 上下文长度 |
骆驼 3.3 (70B) | 80GB | 速度快 2 倍 | >75% | 13倍长 |
骆驼 3.1 (8B) | 80GB | 速度快 2 倍 | >70% | 12倍长 |
米斯特拉尔 v0.3 (7B) | 80GB | 速度快 2.2 倍 | 减少 75% | - |
要求
Python 3.10-3.12
支持 CUDA 的 NVIDIA GPU(推荐)
Node.js 和 npm
执照
Apache-2.0
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Latest Blog Posts
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/OtotaO/unsloth-mcp-server'
If you have feedback or need assistance with the MCP directory API, please join our Discord server