Instructions to use mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL")# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL") model = AutoModelForCausalLM.from_pretrained("mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- vLLM
How to use mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker
docker model run hf.co/mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL
- SGLang
How to use mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL", "prompt": "Once upon a time,", "max_tokens": 512, "temperature": 0.5 }' - Docker Model Runner
How to use mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL with Docker Model Runner:
docker model run hf.co/mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL
军舰 commited on
Commit ·
aa9de2b
1
Parent(s): e3678d1
Update upload model to huggingface hub.
Browse files
README.md
CHANGED
|
@@ -4,15 +4,15 @@ license: mit
|
|
| 4 |
|
| 5 |
## [mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL](https://huggingface.co/mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL)
|
| 6 |
|
| 7 |
-
本次微调的模型我已经上传到了 HuggingFace Hub 上,大家可以
|
| 8 |
|
| 9 |
-
### 安装
|
| 10 |
|
| 11 |
```bash
|
| 12 |
pip install mlx-lm
|
| 13 |
```
|
| 14 |
|
| 15 |
-
### 生成
|
| 16 |
```
|
| 17 |
python -m mlx_lm.generate --model mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL \
|
| 18 |
--max-tokens 50 \
|
|
@@ -61,7 +61,7 @@ if __name__ == "__main__":
|
|
| 61 |
|
| 62 |
### 样本示例
|
| 63 |
|
| 64 |
-
```
|
| 65 |
table: 1-10753917-1
|
| 66 |
columns: Season, Driver, Team, Engine, Poles, Wins, Podiums, Points, Margin of defeat
|
| 67 |
Q: Which podiums did the alfa romeo team have?
|
|
@@ -129,7 +129,7 @@ python fuse.py --model mistralai/Mistral-7B-v0.1 \
|
|
| 129 |
```
|
| 130 |
|
| 131 |
|
| 132 |
-
## 生成
|
| 133 |
|
| 134 |
### 王军建的姓名是什么?
|
| 135 |
|
|
@@ -244,13 +244,69 @@ SELECT COUNT Name FROM students WHERE Grade = 9
|
|
| 244 |
|
| 245 |
附加的提示信息可以轻松添加,不用太在意放置的位置。
|
| 246 |
|
| 247 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 248 |
|
| 249 |
```bash
|
| 250 |
-
|
| 251 |
-
|
| 252 |
-
--quantize \
|
| 253 |
-
--upload-repo mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL
|
| 254 |
```
|
| 255 |
|
| 256 |
|
|
|
|
| 4 |
|
| 5 |
## [mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL](https://huggingface.co/mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL)
|
| 6 |
|
| 7 |
+
本次微调的模型我已经上传到了 HuggingFace Hub 上,大家可以进行尝试。
|
| 8 |
|
| 9 |
+
### 安装 mlx-lm
|
| 10 |
|
| 11 |
```bash
|
| 12 |
pip install mlx-lm
|
| 13 |
```
|
| 14 |
|
| 15 |
+
### 生成 SQL
|
| 16 |
```
|
| 17 |
python -m mlx_lm.generate --model mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL \
|
| 18 |
--max-tokens 50 \
|
|
|
|
| 61 |
|
| 62 |
### 样本示例
|
| 63 |
|
| 64 |
+
```
|
| 65 |
table: 1-10753917-1
|
| 66 |
columns: Season, Driver, Team, Engine, Poles, Wins, Podiums, Points, Margin of defeat
|
| 67 |
Q: Which podiums did the alfa romeo team have?
|
|
|
|
| 129 |
```
|
| 130 |
|
| 131 |
|
| 132 |
+
## 生成 SQL
|
| 133 |
|
| 134 |
### 王军建的姓名是什么?
|
| 135 |
|
|
|
|
| 244 |
|
| 245 |
附加的提示信息可以轻松添加,不用太在意放置的位置。
|
| 246 |
|
| 247 |
+
|
| 248 |
+
## 上传模型到 HuggingFace Hub
|
| 249 |
+
|
| 250 |
+
1. 加入 [MLX Community](https://huggingface.co/mlx-community) 组织
|
| 251 |
+
|
| 252 |
+
2. 在 MLX Community 组织中创建一个新的模型 [mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL](https://huggingface.co/mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL)
|
| 253 |
+
|
| 254 |
+
3. 克隆仓库 [mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL](https://huggingface.co/mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL)
|
| 255 |
+
|
| 256 |
+
```bash
|
| 257 |
+
git clone https://huggingface.co/mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL
|
| 258 |
+
```
|
| 259 |
+
|
| 260 |
+
4. 将生成的模型文件(`lora_fused_model` 目录下的所有文件)复制到仓库目录下
|
| 261 |
+
|
| 262 |
+
5. 上传模型到 HuggingFace Hub
|
| 263 |
+
|
| 264 |
+
```bash
|
| 265 |
+
git add .
|
| 266 |
+
git commit -m "Fine tuning Text2SQL based on Mistral-7B using LoRA on MLX"
|
| 267 |
+
git push
|
| 268 |
+
```
|
| 269 |
+
|
| 270 |
+
### git push 错误
|
| 271 |
+
|
| 272 |
+
1. 不能 push
|
| 273 |
+
|
| 274 |
+
错误信息:
|
| 275 |
+
|
| 276 |
+
```
|
| 277 |
+
Uploading LFS objects: 0% (0/2), 0 B | 0 B/s, done.
|
| 278 |
+
batch response: Authorization error.
|
| 279 |
+
error: failed to push some refs to 'https://huggingface.co/mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL'
|
| 280 |
+
```
|
| 281 |
+
|
| 282 |
+
解决方法:
|
| 283 |
+
|
| 284 |
+
```bash
|
| 285 |
+
vim .git/config
|
| 286 |
+
```
|
| 287 |
+
```conf
|
| 288 |
+
[remote "origin"]
|
| 289 |
+
url = https://wangjunjian:write_token@huggingface.co/mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL
|
| 290 |
+
fetch = +refs/heads/*:refs/remotes/origin/*
|
| 291 |
+
```
|
| 292 |
+
|
| 293 |
+
2. 不能上传大于 5GB 的文件
|
| 294 |
+
|
| 295 |
+
错误信息:
|
| 296 |
+
|
| 297 |
+
```
|
| 298 |
+
warning: current Git remote contains credentials
|
| 299 |
+
batch response:
|
| 300 |
+
You need to configure your repository to enable upload of files > 5GB.
|
| 301 |
+
Run "huggingface-cli lfs-enable-largefiles ./path/to/your/repo" and try again.
|
| 302 |
+
```
|
| 303 |
+
|
| 304 |
+
|
| 305 |
+
解决方法:
|
| 306 |
|
| 307 |
```bash
|
| 308 |
+
huggingface-cli longin
|
| 309 |
+
huggingface-cli lfs-enable-largefiles /Users/junjian/HuggingFace/mlx-community/Mistral-7B-v0.1-LoRA-Text2SQL
|
|
|
|
|
|
|
| 310 |
```
|
| 311 |
|
| 312 |
|