LocoTrainer-4B 是一款拥有40亿参数的MS-SWIFT领域专家智能体,通过知识蒸馏技术从Qwen3-Coder-Next训练而来。与通用代码智能体不同,它将多轮工具调用与深厚的MS-SWIFT框架知识相结合,无需依赖单独的推理模型即可完成代码库分析并生成完整的Markdown报告。
LocoTrainer通过vLLM调用LocoTrainer-4B模型分析MS-SWIFT代码库
| LocoTrainer-4B | |
|---|---|
| 基础模型 | Qwen3-4B-Instruct-2507 |
| 教师模型 | Qwen3-Coder-Next |
| 训练方式 | 全参数SFT(蒸馏) |
| 训练数据 | 361,830条样本(智能体轨迹 + MS-SWIFT知识 + 项目路径) |
| 最大序列长度 | 32,768 tokens |
| 训练硬件 | 8x NVIDIA H100 80GB |
| 训练时间 | ~25小时 |
| 开发框架 | MS-SWIFT |
<tool_call> JSON,支持Read、Grep、Glob、Bash和Write工具from transformers import AutoModelForCausalLM, AutoTokenizer
model_name = "LocoreMind/LocoTrainer-4B"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForCausalLM.from_pretrained(
model_name,
torch_dtype="auto",
device_map="auto"
)
messages = [
{
"role": "system",
"content": "You are Claude Code, Anthropic's official CLI for Claude.\n\nYou are an interactive agent that helps users with software engineering tasks.\n\nCRITICAL CONSTRAINTS:\n1. ALWAYS use absolute file paths in tool calls.\n2. EFFICIENCY: Use multiple tool calls to explore the codebase.\n3. OUTPUT: Save your findings as a well-structured markdown document.\n\nENV: Working directory is /Users/developer/workspace (macOS, zsh)."
},
{
"role": "user",
"content": "What are the default LoRA settings in ms-swift?\n\nAnalyze the codebase at /Users/developer/workspace/ms-swift and save your findings as a well-structured markdown document to /Users/developer/workspace/output/output.md."
}
]
text = tokenizer.apply_chat_template(
messages,
tokenize=False,
add_generation_prompt=True,
)
model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
generated_ids = model.generate(
**model_inputs,
max_new_tokens=1024,
)
output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
content = tokenizer.decode(output_ids, skip_special_tokens=True)
print(content)LocoTrainer-4B 旨在运行于 LocoTrainer 智能体框架 内部,该框架负责处理完整的智能体循环——工具执行、多轮对话以及报告生成。
pip install locotrainer
locotrainer run -q "What are the default LoRA settings in ms-swift?"
# → output/output.md如需完整的设置和使用说明,请参考 GitHub 仓库。
| 参数 | 值 |
|---|---|
| 基础模型 | Qwen3-4B-Instruct-2507 |
| 教师模型 | Qwen3-Coder-Next |
| 训练方法 | 全参数 SFT |
| 训练数据 | 361,830 样本 |
| 数据构成 | 智能体轨迹 + MS-SWIFT 知识 + 项目结构路径 |
| 硬件 | 8x NVIDIA H100 80GB |
| DeepSpeed | ZeRO-2 |
| 精度 | BF16 |
| 训练轮次 | 1 |
| 最大序列长度 | 32,768 tokens |
| 注意力机制 | Flash Attention 2 |
| 内核优化 | Liger Kernel |
| 学习率 | 1e-5,预热比例 0.05 |
| 批处理大小 | 每 GPU 1,梯度累积 4(有效批大小 32) |
| 模板 | qwen3_nothinking |
| 框架 | MS-SWIFT |
| 训练时间 | ~25 小时 |
MIT