|
|
@@ -1582,9 +1582,10 @@ Models generally achieve baseline performance due to small parameter scales and
|
|
|
|
|
|
## Model Conversion
|
|
|
|
|
|
-* [./scripts/convert_model.py](./scripts/convert_model.py) enables conversion between `torch models/transformers` models
|
|
|
+* [./scripts/convert_model.py](./scripts/convert_model.py) enables mutual conversion of `torch / transformers` models
|
|
|
+* Unless otherwise specified, `MiniMind2` models are by default in `Transformers` format and require `t2t` conversion beforehand!
|
|
|
+
|
|
|
|
|
|
----
|
|
|
|
|
|
## OpenAI-API Based MiniMind Service Interface
|
|
|
|
|
|
@@ -1592,13 +1593,12 @@ Models generally achieve baseline performance due to small parameter scales and
|
|
|
|
|
|
* Download model weights from [Huggingface](https://huggingface.co/collections/jingyaogong/minimind-66caf8d999f5c7fa64f399e5), file structure:
|
|
|
```
|
|
|
- <MiniMind-Model-Name> (root dir)
|
|
|
- ├─<MiniMind-Model-Name>
|
|
|
+ minimind (root dir)
|
|
|
+ ├─<MiniMind-Model-Name> (e.g. MiniMind2)
|
|
|
| ├── config.json
|
|
|
| ├── generation_config.json
|
|
|
- | ├── LMConfig.py
|
|
|
- | ├── model.py
|
|
|
- | ├── pytorch_model.bin
|
|
|
+ | ├── model_minimind.py or w/o
|
|
|
+ | ├── pytorch_model.bin or model.safetensors
|
|
|
| ├── special_tokens_map.json
|
|
|
| ├── tokenizer_config.json
|
|
|
| ├── tokenizer.json
|
|
|
@@ -1631,6 +1631,8 @@ Models generally achieve baseline performance due to small parameter scales and
|
|
|
|
|
|
vLLM is an extremely popular efficient inference framework supporting fast deployment of large models, optimizing GPU memory usage and throughput.
|
|
|
|
|
|
+Start minimind2 in openai-serve format:
|
|
|
+
|
|
|
```bash
|
|
|
vllm serve ./MiniMind2 --model-impl transformers --served-model-name "minimind" --port 8998
|
|
|
```
|
|
|
@@ -1639,62 +1641,109 @@ vllm serve ./MiniMind2 --model-impl transformers --served-model-name "minimind"
|
|
|
|
|
|
llama.cpp is a C++ library that can be used directly from command line, supports multi-threaded inference, and supports GPU acceleration.
|
|
|
|
|
|
-After referencing official repository installation, insert at ~760 line in `convert_hf_to_gguf.py`
|
|
|
+**Directory Structure**: It is recommended to place llama.cpp and minimind in the same parent directory
|
|
|
|
|
|
-```text
|
|
|
-# Add MiniMind2 tokenizer support
|
|
|
+```
|
|
|
+parent/
|
|
|
+├── minimind/ # MiniMind project directory
|
|
|
+│ ├── MiniMind2/ # HuggingFace format MiniMind2 model (generated by convert_model.py first)
|
|
|
+│ │ ├── config.json
|
|
|
+│ │ ├── model.safetensors
|
|
|
+│ │ └── ...
|
|
|
+│ ├── model/
|
|
|
+│ ├── trainer/
|
|
|
+│ └── ...
|
|
|
+└── llama.cpp/ # llama.cpp project directory
|
|
|
+ ├── build/
|
|
|
+ ├── convert_hf_to_gguf.py
|
|
|
+ └── ...
|
|
|
+```
|
|
|
+
|
|
|
+0. Follow the official `llama.cpp` installation steps
|
|
|
+
|
|
|
+1. Insert at the end of the `get_vocab_base_pre` function in `convert_hf_to_gguf.py`:
|
|
|
+
|
|
|
+```python
|
|
|
+# Add MiniMind tokenizer support (you can use any existing one like qwen2)
|
|
|
if res is None:
|
|
|
- res = "smollm"
|
|
|
+ res = "qwen2"
|
|
|
```
|
|
|
|
|
|
-Convert custom-trained minimind model -> gguf
|
|
|
+2. Convert your custom-trained minimind model: huggingface -> gguf
|
|
|
|
|
|
```bash
|
|
|
-python convert_hf_to_gguf.py ../minimind/MiniMind2/
|
|
|
+# Execute under llama.cpp, will generate ../minimind/MiniMind2/MiniMind2-xxx.gguf
|
|
|
+python convert_hf_to_gguf.py ../minimind/MiniMind2
|
|
|
```
|
|
|
|
|
|
-Quantize model
|
|
|
+3. Quantize the model (optional)
|
|
|
|
|
|
```bash
|
|
|
-./build/bin/llama-quantize ../minimind/MiniMind2/MiniMind2-109M-F16.gguf ../minimind/MiniMind2/Q4-MiniMind2.gguf Q4_K_M
|
|
|
+./build/bin/llama-quantize ../minimind/MiniMind2/MiniMind2.gguf ../minimind/MiniMind2/Q4-MiniMind2.gguf Q4_K_M
|
|
|
```
|
|
|
|
|
|
-Command line inference
|
|
|
+4. Command line inference test
|
|
|
|
|
|
```bash
|
|
|
-./build/bin/llama-cli -m ../minimind/MiniMind2/MiniMind2-109M-F16.gguf --chat-template chatml
|
|
|
+./build/bin/llama-cli -m ../minimind/MiniMind2/MiniMind2.gguf -sys "You are a helpful assistant" # system prompt must be fixed
|
|
|
```
|
|
|
|
|
|
## <img src="https://ollama.com/public/cloud.png" height="28" style="vertical-align: middle;"/> [ollama](https://ollama.ai)
|
|
|
|
|
|
ollama is a tool for running large models locally, supports multiple open-source LLMs, simple and easy to use.
|
|
|
|
|
|
-Load custom gguf model through ollama, create new minimind.modelfile:
|
|
|
+1. Load custom gguf model through ollama
|
|
|
+
|
|
|
+Create `minimind.modelfile` under `MiniMind2`:
|
|
|
|
|
|
```text
|
|
|
-FROM ./MiniMind2-109M-F16.gguf
|
|
|
-TEMPLATE """{{ if .System }}<|im_start|>system
|
|
|
+FROM ./Q4-MiniMind2.gguf
|
|
|
+
|
|
|
+SYSTEM """You are a helpful assistant"""
|
|
|
+
|
|
|
+TEMPLATE """<|im_start|>system
|
|
|
{{ .System }}<|im_end|>
|
|
|
-{{ end }}{{ if .Prompt }}<|im_start|>user
|
|
|
+<|im_start|>user
|
|
|
{{ .Prompt }}<|im_end|>
|
|
|
-{{ end }}<|im_start|>assistant
|
|
|
+<|im_start|>assistant
|
|
|
+{{ .Response }}<|im_end|>
|
|
|
"""
|
|
|
```
|
|
|
|
|
|
-Load model and name as `minimind2`
|
|
|
+2. Load and name this model as `minimind-local`
|
|
|
|
|
|
```bash
|
|
|
-ollama create -f minimind.modelfile minimind2
|
|
|
+ollama create -f minimind.modelfile minimind-local
|
|
|
```
|
|
|
|
|
|
-Start inference
|
|
|
+3. Start inference
|
|
|
|
|
|
-```text
|
|
|
-ollama run minimind2
|
|
|
-> Hello, I am MiniMind2, a model based on xxxxxxxx
|
|
|
+```bash
|
|
|
+ollama run minimind-local
|
|
|
+```
|
|
|
+
|
|
|
+<details>
|
|
|
+<summary>📤 Push your model to Ollama Hub</summary>
|
|
|
+
|
|
|
+```bash
|
|
|
+# 1. Rename your local model to your_username/minimind tag
|
|
|
+ollama cp minimind-local:latest your_username/minimind:latest
|
|
|
+
|
|
|
+# 2. Push the model
|
|
|
+ollama push your_username/minimind:latest
|
|
|
+```
|
|
|
+</details>
|
|
|
+<br/>
|
|
|
+
|
|
|
+⭐️ You can also directly use the ollama model I provided with one command:
|
|
|
+
|
|
|
+```bash
|
|
|
+ollama run jingyaogong/minimind2 # Other options: minimind2-r1 / minimind2-small / minimind2-small-r1
|
|
|
+>>> What's your name?
|
|
|
+I am a language model...
|
|
|
```
|
|
|
|
|
|
-> For more usage of the above three-party frameworks, please refer to their official documentation 😊
|
|
|
+> For more usage of the above third-party frameworks, please refer to their official documentation 😊
|
|
|
|
|
|
# 📌 Acknowledge
|
|
|
|