FutureMa commited on
Commit
d5a6ea0
·
verified ·
1 Parent(s): a9eb293

Upload 2 files

Browse files
Files changed (2) hide show
  1. README.md +147 -0
  2. assets/locotrainer.png +0 -0
README.md ADDED
@@ -0,0 +1,147 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ library_name: transformers
3
+ license: mit
4
+ base_model: Qwen/Qwen3-4B-Instruct-2507
5
+ tags:
6
+ - code
7
+ - agent
8
+ - tool-calling
9
+ - distillation
10
+ - qwen3
11
+ - ms-swift
12
+ - codebase-analysis
13
+ language:
14
+ - en
15
+ pipeline_tag: text-generation
16
+ ---
17
+
18
+ <div align="center">
19
+ <img src="assets/locotrainer.png" width="55%" alt="LocoTrainer" />
20
+ </div>
21
+
22
+ <br>
23
+
24
+ <div align="center">
25
+
26
+ [![MODEL](https://img.shields.io/badge/Model-FFB300?style=for-the-badge&logo=huggingface&logoColor=white)](https://huggingface.co/LocoreMind/LocoTrainer-4B)
27
+ [![GGUF](https://img.shields.io/badge/GGUF-FF6F00?style=for-the-badge&logo=huggingface&logoColor=white)](https://huggingface.co/LocoreMind/LocoTrainer-4B-GGUF)
28
+ [![GitHub](https://img.shields.io/badge/GitHub-181717?style=for-the-badge&logo=github&logoColor=white)](https://github.com/LocoreMind/LocoTrainer)
29
+
30
+ </div>
31
+
32
+ ## Introduction
33
+
34
+ **LocoTrainer-4B** is a 4B-parameter MS-SWIFT domain expert agent trained via knowledge distillation from **Qwen3-Coder-Next**. Unlike general-purpose code agents, it combines multi-turn tool-calling with deep MS-SWIFT framework knowledge — enabling it to analyze codebases and generate comprehensive markdown reports without a separate reasoning model.
35
+
36
+ | | LocoTrainer-4B |
37
+ |:--|:--|
38
+ | **Base Model** | [Qwen3-4B-Instruct-2507](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507) |
39
+ | **Teacher Model** | Qwen3-Coder-Next |
40
+ | **Training Method** | Full-parameter SFT (distillation) |
41
+ | **Training Data** | 361,830 samples (agent trajectory + MS-SWIFT knowledge + project paths) |
42
+ | **Max Sequence Length** | 32,768 tokens |
43
+ | **Training Hardware** | 8x NVIDIA H100 80GB |
44
+ | **Training Time** | ~25 hours |
45
+ | **Framework** | MS-SWIFT |
46
+
47
+ ## Key Features
48
+
49
+ - **MS-SWIFT Domain Expert**: Trained on MS-SWIFT documentation, CLI parameters, and project structure paths — answers framework questions accurately
50
+ - **Tool-Calling Agent**: Generates structured `<tool_call>` JSON for Read, Grep, Glob, Bash, and Write tools
51
+ - **End-to-End Reports**: From a single question to a complete, well-structured markdown analysis report
52
+ - **Long Context**: 32K training covers 90% of long-context analysis scenarios
53
+ - **Local Deployment**: GGUF quantized version available for zero API cost inference
54
+
55
+ ## Quick Start
56
+
57
+ ```python
58
+ from transformers import AutoModelForCausalLM, AutoTokenizer
59
+
60
+ model_name = "LocoreMind/LocoTrainer-4B"
61
+
62
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
63
+ model = AutoModelForCausalLM.from_pretrained(
64
+ model_name,
65
+ torch_dtype="auto",
66
+ device_map="auto"
67
+ )
68
+
69
+ messages = [
70
+ {
71
+ "role": "system",
72
+ "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)."
73
+ },
74
+ {
75
+ "role": "user",
76
+ "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."
77
+ }
78
+ ]
79
+
80
+ text = tokenizer.apply_chat_template(
81
+ messages,
82
+ tokenize=False,
83
+ add_generation_prompt=True,
84
+ )
85
+ model_inputs = tokenizer([text], return_tensors="pt").to(model.device)
86
+
87
+ generated_ids = model.generate(
88
+ **model_inputs,
89
+ max_new_tokens=1024,
90
+ )
91
+ output_ids = generated_ids[0][len(model_inputs.input_ids[0]):].tolist()
92
+
93
+ content = tokenizer.decode(output_ids, skip_special_tokens=True)
94
+ print(content)
95
+ ```
96
+
97
+ ## LocoTrainer Framework
98
+
99
+ LocoTrainer-4B is designed to run inside the **LocoTrainer agent framework**, which handles the full agent loop — tool execution, multi-turn conversation, and report generation.
100
+
101
+ ```bash
102
+ pip install locotrainer
103
+
104
+ locotrainer run -q "What are the default LoRA settings in ms-swift?"
105
+ # → output/output.md
106
+ ```
107
+
108
+ For full setup and usage, refer to the [GitHub repository](https://github.com/LocoreMind/LocoTrainer).
109
+
110
+ ## Training Details
111
+
112
+ | Parameter | Value |
113
+ |:----------|:------|
114
+ | Base model | Qwen3-4B-Instruct-2507 |
115
+ | Teacher model | Qwen3-Coder-Next |
116
+ | Method | Full-parameter SFT |
117
+ | Training data | 361,830 samples |
118
+ | Data composition | Agent trajectory + MS-SWIFT knowledge + project structure paths |
119
+ | Hardware | 8x NVIDIA H100 80GB |
120
+ | DeepSpeed | ZeRO-2 |
121
+ | Precision | BF16 |
122
+ | Epochs | 1 |
123
+ | Max sequence length | 32,768 tokens |
124
+ | Attention | Flash Attention 2 |
125
+ | Kernel optimization | Liger Kernel |
126
+ | Learning rate | 1e-5, warmup ratio 0.05 |
127
+ | Batch size | 1/GPU, gradient accumulation 4 (effective batch 32) |
128
+ | Template | qwen3_nothinking |
129
+ | Framework | MS-SWIFT |
130
+ | Training time | ~25 hours |
131
+
132
+ ## Known Limitations
133
+
134
+ - Specialized for MS-SWIFT; performance on unrelated codebases is untested
135
+ - 4B parameters — complex multi-hop reasoning may require a larger model
136
+ - MS-SWIFT project structure knowledge reflects the training data snapshot; may drift as the framework evolves
137
+
138
+ ## License
139
+
140
+ MIT
141
+
142
+ ## Acknowledgments
143
+
144
+ - [Qwen Team](https://huggingface.co/Qwen) for the Qwen3-4B-Instruct-2507 base model
145
+ - [MS-SWIFT](https://github.com/modelscope/ms-swift) for the training framework and the codebase this model specializes in
146
+ - [llama.cpp](https://github.com/ggerganov/llama.cpp) for efficient local inference
147
+ - [Anthropic](https://www.anthropic.com/) for the Claude Code agent loop design that inspired this work
assets/locotrainer.png ADDED