Gon04 commited on
Commit
1377e3a
·
1 Parent(s): cca62aa

add attribute file

Browse files
app.py ADDED
@@ -0,0 +1,88 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import streamlit as st
3
+ from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
4
+ from llama_index.embeddings.huggingface import HuggingFaceEmbedding
5
+ from llama_index.legacy.callbacks import CallbackManager
6
+ from llama_index.llms.openai_like import OpenAILike
7
+
8
+
9
+ # Get API_KEY in Env
10
+ api_key = os.getenv('INTERNLM_API_KEY')
11
+
12
+ # Create an instance of CallbackManager
13
+ callback_manager = CallbackManager()
14
+
15
+ api_base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
16
+ model = "internlm2.5-latest"
17
+ # api_key = " your api_key"
18
+
19
+ # api_base_url = "https://api.siliconflow.cn/v1"
20
+ # model = "internlm/internlm2_5-7b-chat"
21
+ # api_key = "请填写 API Key"
22
+
23
+ llm =OpenAILike(model=model, api_base=api_base_url, api_key=api_key, is_chat_model=True,callback_manager=callback_manager)
24
+
25
+
26
+
27
+ st.set_page_config(page_title="llama_index_demo", page_icon="🦜🔗")
28
+ st.title("llama_index_demo")
29
+
30
+ # 初始化模型
31
+ @st.cache_resource
32
+ def init_models():
33
+ embed_model = HuggingFaceEmbedding(
34
+ model_name="./model/sentence-transformer"
35
+ )
36
+ Settings.embed_model = embed_model
37
+
38
+ #用初始化llm
39
+ Settings.llm = llm
40
+
41
+ documents = SimpleDirectoryReader("./data").load_data()
42
+ index = VectorStoreIndex.from_documents(documents)
43
+ query_engine = index.as_query_engine()
44
+
45
+ return query_engine
46
+
47
+ # 检查是否需要初始化模型
48
+ if 'query_engine' not in st.session_state:
49
+ st.session_state['query_engine'] = init_models()
50
+
51
+ def greet2(question):
52
+ response = st.session_state['query_engine'].query(question)
53
+ return response
54
+
55
+
56
+ # Store LLM generated responses
57
+ if "messages" not in st.session_state.keys():
58
+ st.session_state.messages = [{"role": "assistant", "content": "你好,我是你的助手,有什么我可以帮助你的吗?"}]
59
+
60
+ # Display or clear chat messages
61
+ for message in st.session_state.messages:
62
+ with st.chat_message(message["role"]):
63
+ st.write(message["content"])
64
+
65
+ def clear_chat_history():
66
+ st.session_state.messages = [{"role": "assistant", "content": "你好,我是你的助手,有什么我可以帮助你的吗?"}]
67
+
68
+ st.sidebar.button('Clear Chat History', on_click=clear_chat_history)
69
+
70
+ # Function for generating LLaMA2 response
71
+ def generate_llama_index_response(prompt_input):
72
+ return greet2(prompt_input)
73
+
74
+ # User-provided prompt
75
+ if prompt := st.chat_input():
76
+ st.session_state.messages.append({"role": "user", "content": prompt})
77
+ with st.chat_message("user"):
78
+ st.write(prompt)
79
+
80
+ # Gegenerate_llama_index_response last message is not from assistant
81
+ if st.session_state.messages[-1]["role"] != "assistant":
82
+ with st.chat_message("assistant"):
83
+ with st.spinner("Thinking..."):
84
+ response = generate_llama_index_response(prompt)
85
+ placeholder = st.empty()
86
+ placeholder.markdown(response)
87
+ message = {"role": "assistant", "content": response}
88
+ st.session_state.messages.append(message)
data/README_zh-CN.md ADDED
@@ -0,0 +1,304 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <div align="center">
2
+ <img src="https://github.com/InternLM/lmdeploy/assets/36994684/0cf8d00f-e86b-40ba-9b54-dc8f1bc6c8d8" width="600"/>
3
+ <br /><br />
4
+
5
+ [![GitHub Repo stars](https://img.shields.io/github/stars/InternLM/xtuner?style=social)](https://github.com/InternLM/xtuner/stargazers)
6
+ [![license](https://img.shields.io/github/license/InternLM/xtuner.svg)](https://github.com/InternLM/xtuner/blob/main/LICENSE)
7
+ [![PyPI](https://img.shields.io/pypi/v/xtuner)](https://pypi.org/project/xtuner/)
8
+ [![Downloads](https://static.pepy.tech/badge/xtuner)](https://pypi.org/project/xtuner/)
9
+ [![issue resolution](https://img.shields.io/github/issues-closed-raw/InternLM/xtuner)](https://github.com/InternLM/xtuner/issues)
10
+ [![open issues](https://img.shields.io/github/issues-raw/InternLM/xtuner)](https://github.com/InternLM/xtuner/issues)
11
+
12
+ 👋 加入我们:[![Static Badge](https://img.shields.io/badge/-grey?style=social&logo=wechat&label=微信)](https://cdn.vansin.top/internlm/xtuner.jpg)
13
+ [![Static Badge](https://img.shields.io/badge/-grey?style=social&logo=twitter&label=推特)](https://twitter.com/intern_lm)
14
+ [![Static Badge](https://img.shields.io/badge/-grey?style=social&logo=discord&label=Discord)](https://discord.gg/xa29JuW87d)
15
+
16
+ 🔍 探索我们的模型:
17
+ [![Static Badge](https://img.shields.io/badge/-gery?style=social&label=🤗%20Huggingface)](https://huggingface.co/xtuner)
18
+ [![Static Badge](https://img.shields.io/badge/-gery?style=social&label=🤖%20ModelScope)](https://www.modelscope.cn/organization/xtuner)
19
+ [![Static Badge](https://img.shields.io/badge/-gery?style=social&label=🧰%20OpenXLab)](https://openxlab.org.cn/usercenter/xtuner)
20
+ [![Static Badge](https://img.shields.io/badge/-gery?style=social&label=🧠%20WiseModel)](https://www.wisemodel.cn/organization/xtuner)
21
+
22
+ [English](README.md) | 简体中文
23
+
24
+ </div>
25
+
26
+ ## 🚀 Speed Benchmark
27
+
28
+ - XTuner 与 LLaMA-Factory 在 Llama2-7B 模型上的训练效率对比
29
+
30
+ <div align=center>
31
+ <img src="https://github.com/InternLM/xtuner/assets/41630003/9c9dfdf4-1efb-4daf-84bf-7c379ae40b8b" style="width:80%">
32
+ </div>
33
+
34
+ - XTuner 与 LLaMA-Factory 在 Llama2-70B 模型上的训练效率对比
35
+
36
+ <div align=center>
37
+ <img src="https://github.com/InternLM/xtuner/assets/41630003/5ba973b8-8885-4b72-b51b-c69fa1583bdd" style="width:80%">
38
+ </div>
39
+
40
+ ## 🎉 更新
41
+ - **\[2024/07\]** 支持 [MiniCPM](xtuner/configs/minicpm/) 模型!
42
+ - **\[2024/07\]** 支持训练 [DPO](https://github.com/InternLM/xtuner/tree/main/xtuner/configs/dpo), [ORPO](https://github.com/InternLM/xtuner/tree/main/xtuner/configs/orpo) 还有 [Reward Model](https://github.com/InternLM/xtuner/tree/main/xtuner/configs/reward_model) ! 并且能够支持打包数据以及序列并行功能! 请参考 [文档](https://xtuner.readthedocs.io/zh-cn/latest/dpo/overview.html) 了解更多信息。
43
+ - **\[2024/07\]** 支持 [InternLM 2.5](xtuner/configs/internlm/internlm2_5_chat_7b/) 模型!
44
+ - **\[2024/06\]** 支持 [DeepSeek V2](xtuner/configs/deepseek/deepseek_v2_chat/) models! **训练速度提升一倍!**
45
+ - **\[2024/04\]** 多模态大模型 [LLaVA-Phi-3-mini](https://huggingface.co/xtuner/llava-phi-3-mini-hf) 发布!快速开始请查阅此[文档](xtuner/configs/llava/phi3_mini_4k_instruct_clip_vit_large_p14_336)!
46
+ - **\[2024/04\]** 多模态大模型 [LLaVA-Llama-3-8B](https://huggingface.co/xtuner/llava-llama-3-8b) 和 [LLaVA-Llama-3-8B-v1.1](https://huggingface.co/xtuner/llava-llama-3-8b-v1_1) 发布!快速开始请查阅此[文档](xtuner/configs/llava/llama3_8b_instruct_clip_vit_large_p14_336)!
47
+ - **\[2024/04\]** 支持 [Llama 3](xtuner/configs/llama) 模型!
48
+ - **\[2024/04\]** 支持序列并行训练策略以实现语言模型超长上下文训练!\[[文档](https://github.com/InternLM/xtuner/blob/docs/docs/zh_cn/acceleration/train_extreme_long_sequence.rst)\] \[[速度基准](https://github.com/InternLM/xtuner/blob/docs/docs/zh_cn/acceleration/benchmark.rst)\]
49
+ - **\[2024/02\]** 支持 [Gemma](xtuner/configs/gemma) 模型!
50
+ - **\[2024/02\]** 支持 [Qwen1.5](xtuner/configs/qwen/qwen1_5) 模型!
51
+ - **\[2024/01\]** 支持 [InternLM2](xtuner/configs/internlm) 模型!同时,最新版的多模态大模型 [LLaVA-Internlm2-7B](https://huggingface.co/xtuner/llava-internlm2-7b) / [20B](https://huggingface.co/xtuner/llava-internlm2-20b) 发布,其表现出强大的性能!
52
+ - **\[2024/01\]** 支持 [DeepSeek-MoE](https://huggingface.co/deepseek-ai/deepseek-moe-16b-chat) 模型!20GB 显存即可实现 QLoRA 微调,4x80GB 即可实现全参数微调。快速开始请查阅相关[配置文件](xtuner/configs/deepseek/)!
53
+ - **\[2023/12\]** 🔥 支持多模态模型 VLM([LLaVA-v1.5](https://github.com/haotian-liu/LLaVA))预训练和指令微调!快速开始请查阅此[文档](xtuner/configs/llava/README_zh-CN.md)!
54
+ - **\[2023/12\]** 🔥 支持 [Mixtral 8x7B](https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1) 模型!快速开始请查阅此[文档](xtuner/configs/mixtral/README.md)!
55
+ - **\[2023/11\]** 支持 [ChatGLM3-6B](xtuner/configs/chatglm) 模型!
56
+ - **\[2023/10\]** 支持 [MSAgent-Bench](https://modelscope.cn/datasets/damo/MSAgent-Bench) 数据集,并且微调所得大语言模型可应用至 [Lagent](https://github.com/InternLM/lagent) 框架!
57
+ - **\[2023/10\]** 优化数据处理逻辑以兼容 `system` 字段,相关细节请查阅[文档](docs/zh_cn/user_guides/dataset_format.md)!
58
+ - **\[2023/09\]** 支持 [InternLM-20B](xtuner/configs/internlm) 系列模型!
59
+ - **\[2023/09\]** 支持 [Baichuan2](xtuner/configs/baichuan) 系列模型!
60
+ - **\[2023/08\]** XTuner 正式发布!众多微调模型已上传至 [HuggingFace](https://huggingface.co/xtuner)!
61
+
62
+ ## 📖 介绍
63
+
64
+ XTuner 是一个高效、灵活、全能的轻量化大模型微调工具库。
65
+
66
+ **高效**
67
+
68
+ - 支持大语言模型 LLM、多模态图文模型 VLM 的预训练及轻量级微调。XTuner 支持在 8GB 显存下微调 7B 模型,同时也支持多节点跨设备微调更大尺度模型(70B+)。
69
+ - 自动分发高性能算子(如 FlashAttention、Triton kernels 等)以加速训练吞吐。
70
+ - 兼容 [DeepSpeed](https://github.com/microsoft/DeepSpeed) 🚀,轻松应用各种 ZeRO 训练优化策略。
71
+
72
+ **灵活**
73
+
74
+ - 支持多种大语言模型,包括但不限于 [InternLM](https://huggingface.co/internlm)、[Mixtral-8x7B](https://huggingface.co/mistralai)、[Llama 2](https://huggingface.co/meta-llama)、[ChatGLM](https://huggingface.co/THUDM)、[Qwen](https://huggingface.co/Qwen)、[Baichuan](https://huggingface.co/baichuan-inc)。
75
+ - 支持多模态图文模型 LLaVA 的预训练与微调。利用 XTuner 训得模型 [LLaVA-InternLM2-20B](https://huggingface.co/xtuner/llava-internlm2-20b) 表现优异。
76
+ - 精心设计的数据管道,兼容任意数据格式,开源数据或自定义数据皆可快速上手。
77
+ - 支持 [QLoRA](http://arxiv.org/abs/2305.14314)、[LoRA](http://arxiv.org/abs/2106.09685)、全量参数微调等多种微调算法,支撑用户根据具体需求作出最优选择。
78
+
79
+ **全能**
80
+
81
+ - 支持增量预训练、指令微调与 Agent 微调。
82
+ - 预定义众多开源对话模版,支持与开源或训练所得模型进行对话。
83
+ - 训练所得模型可无缝接入部署工具库 [LMDeploy](https://github.com/InternLM/lmdeploy)、大规模评测工具库 [OpenCompass](https://github.com/open-compass/opencompass) 及 [VLMEvalKit](https://github.com/open-compass/VLMEvalKit)。
84
+
85
+ ## 🔥 支持列表
86
+
87
+ <table>
88
+ <tbody>
89
+ <tr align="center" valign="middle">
90
+ <td>
91
+ <b>模型</b>
92
+ </td>
93
+ <td>
94
+ <b>数据集</b>
95
+ </td>
96
+ <td>
97
+ <b>数据格式</b>
98
+ </td>
99
+ <td>
100
+ <b>微调算法</b>
101
+ </td>
102
+ </tr>
103
+ <tr valign="top">
104
+ <td align="left" valign="top">
105
+ <ul>
106
+ <li><a href="https://huggingface.co/internlm">InternLM 2 / 2.5</a></li>
107
+ <li><a href="https://huggingface.co/meta-llama">Llama 2 / 3</a></li>
108
+ <li><a href="https://huggingface.co/collections/microsoft/phi-3-6626e15e9585a200d2d761e3">Phi-3</a></li>
109
+ <li><a href="https://huggingface.co/THUDM/chatglm2-6b">ChatGLM2</a></li>
110
+ <li><a href="https://huggingface.co/THUDM/chatglm3-6b">ChatGLM3</a></li>
111
+ <li><a href="https://huggingface.co/Qwen/Qwen-7B">Qwen</a></li>
112
+ <li><a href="https://huggingface.co/baichuan-inc/Baichuan2-7B-Base">Baichuan2</a></li>
113
+ <li><a href="https://huggingface.co/mistralai/Mixtral-8x7B-Instruct-v0.1">Mixtral</a></li>
114
+ <li><a href="https://huggingface.co/deepseek-ai/DeepSeek-V2-Chat">DeepSeek V2</a></li>
115
+ <li><a href="https://huggingface.co/google">Gemma</a></li>
116
+ <li><a href="https://huggingface.co/openbmb">MiniCPM</a></li>
117
+ <li>...</li>
118
+ </ul>
119
+ </td>
120
+ <td>
121
+ <ul>
122
+ <li><a href="https://modelscope.cn/datasets/damo/MSAgent-Bench">MSAgent-Bench</a></li>
123
+ <li><a href="https://huggingface.co/datasets/fnlp/moss-003-sft-data">MOSS-003-SFT</a> 🔧</li>
124
+ <li><a href="https://huggingface.co/datasets/tatsu-lab/alpaca">Alpaca en</a> / <a href="https://huggingface.co/datasets/silk-road/alpaca-data-gpt4-chinese">zh</a></li>
125
+ <li><a href="https://huggingface.co/datasets/WizardLM/WizardLM_evol_instruct_V2_196k">WizardLM</a></li>
126
+ <li><a href="https://huggingface.co/datasets/timdettmers/openassistant-guanaco">oasst1</a></li>
127
+ <li><a href="https://huggingface.co/datasets/garage-bAInd/Open-Platypus">Open-Platypus</a></li>
128
+ <li><a href="https://huggingface.co/datasets/HuggingFaceH4/CodeAlpaca_20K">Code Alpaca</a></li>
129
+ <li><a href="https://huggingface.co/datasets/burkelibbey/colors">Colorist</a> 🎨</li>
130
+ <li><a href="https://github.com/WangRongsheng/ChatGenTitle">Arxiv GenTitle</a></li>
131
+ <li><a href="https://github.com/LiuHC0428/LAW-GPT">Chinese Law</a></li>
132
+ <li><a href="https://huggingface.co/datasets/Open-Orca/OpenOrca">OpenOrca</a></li>
133
+ <li><a href="https://huggingface.co/datasets/shibing624/medical">Medical Dialogue</a></li>
134
+ <li>...</li>
135
+ </ul>
136
+ </td>
137
+ <td>
138
+ <ul>
139
+ <li><a href="docs/zh_cn/user_guides/incremental_pretraining.md">Incremental Pre-training</a> </li>
140
+ <li><a href="docs/zh_cn/user_guides/single_turn_conversation.md">Single-turn Conversation SFT</a> </li>
141
+ <li><a href="docs/zh_cn/user_guides/multi_turn_conversation.md">Multi-turn Conversation SFT</a> </li>
142
+ </ul>
143
+ </td>
144
+ <td>
145
+ <ul>
146
+ <li><a href="http://arxiv.org/abs/2305.14314">QLoRA</a></li>
147
+ <li><a href="http://arxiv.org/abs/2106.09685">LoRA</a></li>
148
+ <li>全量参数微调</li>
149
+ <li><a href="https://arxiv.org/abs/2305.18290">DPO</a></li>
150
+ <li><a href="https://arxiv.org/abs/2403.07691">ORPO</a></li>
151
+ <li>Reward Model</a></li>
152
+ </ul>
153
+ </td>
154
+ </tr>
155
+ </tbody>
156
+ </table>
157
+
158
+ ## 🛠️ 快速上手
159
+
160
+ ### 安装
161
+
162
+ - 推荐使用 conda 先构建一个 Python-3.10 的虚拟环境
163
+
164
+ ```bash
165
+ conda create --name xtuner-env python=3.10 -y
166
+ conda activate xtuner-env
167
+ ```
168
+
169
+ - 通过 pip 安装 XTuner:
170
+
171
+ ```shell
172
+ pip install -U xtuner
173
+ ```
174
+
175
+ 亦可集成 DeepSpeed 安装:
176
+
177
+ ```shell
178
+ pip install -U 'xtuner[deepspeed]'
179
+ ```
180
+
181
+ - 从源码安装 XTuner:
182
+
183
+ ```shell
184
+ git clone https://github.com/InternLM/xtuner.git
185
+ cd xtuner
186
+ pip install -e '.[all]'
187
+ ```
188
+
189
+ ### 微调
190
+
191
+ XTuner 支持微调大语言模型。数据集预处理指南请查阅[文档](./docs/zh_cn/user_guides/dataset_prepare.md)。
192
+
193
+ - **步骤 0**,准备配置文件。XTuner 提供多个开箱即用的配置文件,用户可以通过下列命令查看:
194
+
195
+ ```shell
196
+ xtuner list-cfg
197
+ ```
198
+
199
+ 或者,如果所提供的配置文件不能满足使用需求,请导出所提供的配置文件并进行相应更改:
200
+
201
+ ```shell
202
+ xtuner copy-cfg ${CONFIG_NAME} ${SAVE_PATH}
203
+ vi ${SAVE_PATH}/${CONFIG_NAME}_copy.py
204
+ ```
205
+
206
+ - **步骤 1**,开始微调。
207
+
208
+ ```shell
209
+ xtuner train ${CONFIG_NAME_OR_PATH}
210
+ ```
211
+
212
+ 例如,我们可以利用 QLoRA 算法在 oasst1 数据集上微调 InternLM2.5-Chat-7B:
213
+
214
+ ```shell
215
+ # 单卡
216
+ xtuner train internlm2_5_chat_7b_qlora_oasst1_e3 --deepspeed deepspeed_zero2
217
+ # 多卡
218
+ (DIST) NPROC_PER_NODE=${GPU_NUM} xtuner train internlm2_5_chat_7b_qlora_oasst1_e3 --deepspeed deepspeed_zero2
219
+ (SLURM) srun ${SRUN_ARGS} xtuner train internlm2_5_chat_7b_qlora_oasst1_e3 --launcher slurm --deepspeed deepspeed_zero2
220
+ ```
221
+
222
+ - `--deepspeed` 表示使用 [DeepSpeed](https://github.com/microsoft/DeepSpeed) 🚀 来优化训练过程。XTuner 内置了多种策略,包括 ZeRO-1、ZeRO-2、ZeRO-3 等。如果用户期望关闭此功能,请直接移除此参数。
223
+
224
+ - 更多示例,请查阅[文档](./docs/zh_cn/user_guides/finetune.md)。
225
+
226
+ - **步骤 2**,将保存的 PTH 模型(如果使用的DeepSpeed,则将会是一个文件夹)转换为 HuggingFace 模型:
227
+
228
+ ```shell
229
+ xtuner convert pth_to_hf ${CONFIG_NAME_OR_PATH} ${PTH} ${SAVE_PATH}
230
+ ```
231
+
232
+ ### 对话
233
+
234
+ XTuner 提供与大语言模型对话的工具。
235
+
236
+ ```shell
237
+ xtuner chat ${NAME_OR_PATH_TO_LLM} --adapter {NAME_OR_PATH_TO_ADAPTER} [optional arguments]
238
+ ```
239
+
240
+ 例如:
241
+
242
+ 与 InternLM2.5-Chat-7B 对话:
243
+
244
+ ```shell
245
+ xtuner chat internlm/internlm2-chat-7b --prompt-template internlm2_chat
246
+ ```
247
+
248
+ 更多示例,请查阅[文档](./docs/zh_cn/user_guides/chat.md)。
249
+
250
+ ### 部署
251
+
252
+ - **步骤 0**,将 HuggingFace adapter 合并到大语言模型:
253
+
254
+ ```shell
255
+ xtuner convert merge \
256
+ ${NAME_OR_PATH_TO_LLM} \
257
+ ${NAME_OR_PATH_TO_ADAPTER} \
258
+ ${SAVE_PATH} \
259
+ --max-shard-size 2GB
260
+ ```
261
+
262
+ - **步骤 1**,使用任意推理框架部署微调后的大语言模型,例如 [LMDeploy](https://github.com/InternLM/lmdeploy) 🚀:
263
+
264
+ ```shell
265
+ pip install lmdeploy
266
+ python -m lmdeploy.pytorch.chat ${NAME_OR_PATH_TO_LLM} \
267
+ --max_new_tokens 256 \
268
+ --temperture 0.8 \
269
+ --top_p 0.95 \
270
+ --seed 0
271
+ ```
272
+
273
+ 🔥 追求速度更快、显存占用更低的推理?欢迎体验 [LMDeploy](https://github.com/InternLM/lmdeploy) 提供的 4-bit 量化!使用指南请见[文档](https://github.com/InternLM/lmdeploy/tree/main#quantization)。
274
+
275
+ ### 评测
276
+
277
+ - 推荐使用一站式平台 [OpenCompass](https://github.com/InternLM/opencompass) 来评测大语言模型,其目前已涵盖 50+ 数据集的约 30 万条题目。
278
+
279
+ ## 🤝 贡献指南
280
+
281
+ 我们感谢所有的贡献者为改进和提升 XTuner 所作出的努力。请参考[贡献指南](.github/CONTRIBUTING.md)来了解参与项目贡献的相关指引。
282
+
283
+ ## 🎖️ 致谢
284
+
285
+ - [Llama 2](https://github.com/facebookresearch/llama)
286
+ - [DeepSpeed](https://github.com/microsoft/DeepSpeed)
287
+ - [QLoRA](https://github.com/artidoro/qlora)
288
+ - [LMDeploy](https://github.com/InternLM/lmdeploy)
289
+ - [LLaVA](https://github.com/haotian-liu/LLaVA)
290
+
291
+ ## 🖊️ 引用
292
+
293
+ ```bibtex
294
+ @misc{2023xtuner,
295
+ title={XTuner: A Toolkit for Efficiently Fine-tuning LLM},
296
+ author={XTuner Contributors},
297
+ howpublished = {\url{https://github.com/InternLM/xtuner}},
298
+ year={2023}
299
+ }
300
+ ```
301
+
302
+ ## 开源许可证
303
+
304
+ 该项目采用 [Apache License 2.0 开源许可证](LICENSE)。同时,请遵守所使用的模型与数据集的许可证。
download_hf.py ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ import os
2
+
3
+ # 设置环境变量
4
+ os.environ['HF_ENDPOINT'] = 'https://hf-mirror.com'
5
+
6
+ # 下载模型
7
+ os.system('huggingface-cli download --resume-download sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2 --local-dir ./model/sentence-transformer')
model/sentence-transformer/.gitattributes ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.bin.* filter=lfs diff=lfs merge=lfs -text
2
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.h5 filter=lfs diff=lfs merge=lfs -text
5
+ *.tflite filter=lfs diff=lfs merge=lfs -text
6
+ *.tar.gz filter=lfs diff=lfs merge=lfs -text
7
+ *.ot filter=lfs diff=lfs merge=lfs -text
8
+ *.onnx filter=lfs diff=lfs merge=lfs -text
9
+ *.arrow filter=lfs diff=lfs merge=lfs -text
10
+ *.ftz filter=lfs diff=lfs merge=lfs -text
11
+ *.joblib filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.pb filter=lfs diff=lfs merge=lfs -text
15
+ *.pt filter=lfs diff=lfs merge=lfs -text
16
+ *.pth filter=lfs diff=lfs merge=lfs -text
17
+ pytorch_model.bin filter=lfs diff=lfs merge=lfs -text
18
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
19
+ unigram.json filter=lfs diff=lfs merge=lfs -text
20
+ .git/lfs/objects/8a/01/8a016203ad4fe42aaad6e9329f70e4ea2ea19d4e14e43f1a36ec140233e604ef filter=lfs diff=lfs merge=lfs -text
21
+ model.safetensors filter=lfs diff=lfs merge=lfs -text
model/sentence-transformer/1_Pooling/config.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "word_embedding_dimension": 384,
3
+ "pooling_mode_cls_token": false,
4
+ "pooling_mode_mean_tokens": true,
5
+ "pooling_mode_max_tokens": false,
6
+ "pooling_mode_mean_sqrt_len_tokens": false
7
+ }
model/sentence-transformer/README.md ADDED
@@ -0,0 +1,164 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - multilingual
4
+ - ar
5
+ - bg
6
+ - ca
7
+ - cs
8
+ - da
9
+ - de
10
+ - el
11
+ - en
12
+ - es
13
+ - et
14
+ - fa
15
+ - fi
16
+ - fr
17
+ - gl
18
+ - gu
19
+ - he
20
+ - hi
21
+ - hr
22
+ - hu
23
+ - hy
24
+ - id
25
+ - it
26
+ - ja
27
+ - ka
28
+ - ko
29
+ - ku
30
+ - lt
31
+ - lv
32
+ - mk
33
+ - mn
34
+ - mr
35
+ - ms
36
+ - my
37
+ - nb
38
+ - nl
39
+ - pl
40
+ - pt
41
+ - ro
42
+ - ru
43
+ - sk
44
+ - sl
45
+ - sq
46
+ - sr
47
+ - sv
48
+ - th
49
+ - tr
50
+ - uk
51
+ - ur
52
+ - vi
53
+ license: apache-2.0
54
+ library_name: sentence-transformers
55
+ tags:
56
+ - sentence-transformers
57
+ - feature-extraction
58
+ - sentence-similarity
59
+ - transformers
60
+ language_bcp47:
61
+ - fr-ca
62
+ - pt-br
63
+ - zh-cn
64
+ - zh-tw
65
+ pipeline_tag: sentence-similarity
66
+ ---
67
+
68
+ # sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2
69
+
70
+ This is a [sentence-transformers](https://www.SBERT.net) model: It maps sentences & paragraphs to a 384 dimensional dense vector space and can be used for tasks like clustering or semantic search.
71
+
72
+
73
+
74
+ ## Usage (Sentence-Transformers)
75
+
76
+ Using this model becomes easy when you have [sentence-transformers](https://www.SBERT.net) installed:
77
+
78
+ ```
79
+ pip install -U sentence-transformers
80
+ ```
81
+
82
+ Then you can use the model like this:
83
+
84
+ ```python
85
+ from sentence_transformers import SentenceTransformer
86
+ sentences = ["This is an example sentence", "Each sentence is converted"]
87
+
88
+ model = SentenceTransformer('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
89
+ embeddings = model.encode(sentences)
90
+ print(embeddings)
91
+ ```
92
+
93
+
94
+
95
+ ## Usage (HuggingFace Transformers)
96
+ Without [sentence-transformers](https://www.SBERT.net), you can use the model like this: First, you pass your input through the transformer model, then you have to apply the right pooling-operation on-top of the contextualized word embeddings.
97
+
98
+ ```python
99
+ from transformers import AutoTokenizer, AutoModel
100
+ import torch
101
+
102
+
103
+ # Mean Pooling - Take attention mask into account for correct averaging
104
+ def mean_pooling(model_output, attention_mask):
105
+ token_embeddings = model_output[0] #First element of model_output contains all token embeddings
106
+ input_mask_expanded = attention_mask.unsqueeze(-1).expand(token_embeddings.size()).float()
107
+ return torch.sum(token_embeddings * input_mask_expanded, 1) / torch.clamp(input_mask_expanded.sum(1), min=1e-9)
108
+
109
+
110
+ # Sentences we want sentence embeddings for
111
+ sentences = ['This is an example sentence', 'Each sentence is converted']
112
+
113
+ # Load model from HuggingFace Hub
114
+ tokenizer = AutoTokenizer.from_pretrained('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
115
+ model = AutoModel.from_pretrained('sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2')
116
+
117
+ # Tokenize sentences
118
+ encoded_input = tokenizer(sentences, padding=True, truncation=True, return_tensors='pt')
119
+
120
+ # Compute token embeddings
121
+ with torch.no_grad():
122
+ model_output = model(**encoded_input)
123
+
124
+ # Perform pooling. In this case, max pooling.
125
+ sentence_embeddings = mean_pooling(model_output, encoded_input['attention_mask'])
126
+
127
+ print("Sentence embeddings:")
128
+ print(sentence_embeddings)
129
+ ```
130
+
131
+
132
+
133
+ ## Evaluation Results
134
+
135
+
136
+
137
+ For an automated evaluation of this model, see the *Sentence Embeddings Benchmark*: [https://seb.sbert.net](https://seb.sbert.net?model_name=sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2)
138
+
139
+
140
+
141
+ ## Full Model Architecture
142
+ ```
143
+ SentenceTransformer(
144
+ (0): Transformer({'max_seq_length': 128, 'do_lower_case': False}) with Transformer model: BertModel
145
+ (1): Pooling({'word_embedding_dimension': 384, 'pooling_mode_cls_token': False, 'pooling_mode_mean_tokens': True, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False})
146
+ )
147
+ ```
148
+
149
+ ## Citing & Authors
150
+
151
+ This model was trained by [sentence-transformers](https://www.sbert.net/).
152
+
153
+ If you find this model helpful, feel free to cite our publication [Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks](https://arxiv.org/abs/1908.10084):
154
+ ```bibtex
155
+ @inproceedings{reimers-2019-sentence-bert,
156
+ title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
157
+ author = "Reimers, Nils and Gurevych, Iryna",
158
+ booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
159
+ month = "11",
160
+ year = "2019",
161
+ publisher = "Association for Computational Linguistics",
162
+ url = "http://arxiv.org/abs/1908.10084",
163
+ }
164
+ ```
model/sentence-transformer/config.json ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "old_models/paraphrase-multilingual-MiniLM-L12-v2/0_Transformer",
3
+ "architectures": [
4
+ "BertModel"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "gradient_checkpointing": false,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 384,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 1536,
13
+ "layer_norm_eps": 1e-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "transformers_version": "4.7.0",
21
+ "type_vocab_size": 2,
22
+ "use_cache": true,
23
+ "vocab_size": 250037
24
+ }
model/sentence-transformer/config_sentence_transformers.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "__version__": {
3
+ "sentence_transformers": "2.0.0",
4
+ "transformers": "4.7.0",
5
+ "pytorch": "1.9.0+cu102"
6
+ }
7
+ }
model/sentence-transformer/model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eaa086f0ffee582aeb45b36e34cdd1fe2d6de2bef61f8a559a1bbc9bd955917b
3
+ size 470641600
model/sentence-transformer/modules.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [
2
+ {
3
+ "idx": 0,
4
+ "name": "0",
5
+ "path": "",
6
+ "type": "sentence_transformers.models.Transformer"
7
+ },
8
+ {
9
+ "idx": 1,
10
+ "name": "1",
11
+ "path": "1_Pooling",
12
+ "type": "sentence_transformers.models.Pooling"
13
+ }
14
+ ]
model/sentence-transformer/pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:16cc9e54df6e083272378abec2d75dc34d7a48b5276db3ccc050d18de672ac59
3
+ size 470693617
model/sentence-transformer/sentence_bert_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "max_seq_length": 128,
3
+ "do_lower_case": false
4
+ }
model/sentence-transformer/sentencepiece.bpe.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cfc8146abe2a0488e9e2a0c56de7952f7c11ab059eca145a0a727afce0db2865
3
+ size 5069051
model/sentence-transformer/special_tokens_map.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"bos_token": "<s>", "eos_token": "</s>", "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": false}}
model/sentence-transformer/tf_model.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22150b6ba00e477c7f816f1988d028fff924e2b52e14540889690c72c5add40e
3
+ size 470899176
model/sentence-transformer/tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2c3387be76557bd40970cec13153b3bbf80407865484b209e655e5e4729076b8
3
+ size 9081518
model/sentence-transformer/tokenizer_config.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {"do_lower_case": true, "unk_token": "<unk>", "sep_token": "</s>", "pad_token": "<pad>", "cls_token": "<s>", "mask_token": {"content": "<mask>", "single_word": false, "lstrip": true, "rstrip": false, "normalized": true, "__type": "AddedToken"}, "tokenize_chinese_chars": true, "strip_accents": null, "bos_token": "<s>", "eos_token": "</s>", "model_max_length": 512, "special_tokens_map_file": null, "name_or_path": "old_models/paraphrase-multilingual-MiniLM-L12-v2/0_Transformer"}
model/sentence-transformer/unigram.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:71b44701d7efd054205115acfa6ef126c5d2f84bd3affe0c59e48163674d19a6
3
+ size 14763234
requirements.txt ADDED
@@ -0,0 +1,132 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ aiohappyeyeballs==2.4.3
2
+ aiohttp==3.11.4
3
+ aiosignal==1.3.1
4
+ altair==5.4.1
5
+ annotated-types==0.7.0
6
+ anyio==4.6.2.post1
7
+ async-timeout==5.0.1
8
+ attrs==24.2.0
9
+ beautifulsoup4==4.12.3
10
+ blinker==1.9.0
11
+ cachetools==5.5.0
12
+ certifi==2024.8.30
13
+ charset-normalizer==3.4.0
14
+ click==8.1.7
15
+ dataclasses-json==0.6.7
16
+ Deprecated==1.2.15
17
+ dirtyjson==1.0.8
18
+ distro==1.9.0
19
+ einops==0.7.0
20
+ exceptiongroup==1.2.2
21
+ filelock==3.16.1
22
+ filetype==1.2.0
23
+ frozenlist==1.5.0
24
+ fsspec==2024.10.0
25
+ gitdb==4.0.11
26
+ GitPython==3.1.43
27
+ greenlet==3.1.1
28
+ h11==0.14.0
29
+ httpcore==1.0.7
30
+ httpx==0.27.2
31
+ huggingface-hub==0.26.2
32
+ idna==3.10
33
+ InstructorEmbedding==1.0.1
34
+ Jinja2==3.1.4
35
+ jiter==0.7.1
36
+ joblib==1.4.2
37
+ jsonschema==4.23.0
38
+ jsonschema-specifications==2024.10.1
39
+ llama-cloud==0.1.5
40
+ llama-index==0.11.20
41
+ llama-index-agent-openai==0.3.4
42
+ llama-index-cli==0.3.1
43
+ llama-index-core==0.11.23
44
+ llama-index-embeddings-huggingface==0.3.1
45
+ llama-index-embeddings-instructor==0.2.1
46
+ llama-index-embeddings-openai==0.2.5
47
+ llama-index-indices-managed-llama-cloud==0.6.0
48
+ llama-index-legacy==0.9.48.post4
49
+ llama-index-llms-openai==0.2.16
50
+ llama-index-llms-openai-like==0.2.0
51
+ llama-index-llms-replicate==0.3.0
52
+ llama-index-multi-modal-llms-openai==0.2.3
53
+ llama-index-program-openai==0.2.0
54
+ llama-index-question-gen-openai==0.2.0
55
+ llama-index-readers-file==0.2.2
56
+ llama-index-readers-llama-parse==0.3.0
57
+ llama-parse==0.5.14
58
+ markdown-it-py==3.0.0
59
+ MarkupSafe==3.0.2
60
+ marshmallow==3.23.1
61
+ mdurl==0.1.2
62
+ mpmath==1.3.0
63
+ multidict==6.1.0
64
+ mypy-extensions==1.0.0
65
+ narwhals==1.14.1
66
+ nest-asyncio==1.6.0
67
+ networkx==3.4.2
68
+ nltk==3.9.1
69
+ numpy==1.26.4
70
+ nvidia-cublas-cu12==12.1.3.1
71
+ nvidia-cuda-cupti-cu12==12.1.105
72
+ nvidia-cuda-nvrtc-cu12==12.1.105
73
+ nvidia-cuda-runtime-cu12==12.1.105
74
+ nvidia-cudnn-cu12==9.1.0.70
75
+ nvidia-cufft-cu12==11.0.2.54
76
+ nvidia-curand-cu12==10.3.2.106
77
+ nvidia-cusolver-cu12==11.4.5.107
78
+ nvidia-cusparse-cu12==12.1.0.106
79
+ nvidia-nccl-cu12==2.21.5
80
+ nvidia-nvjitlink-cu12==12.4.127
81
+ nvidia-nvtx-cu12==12.1.105
82
+ openai==1.54.4
83
+ packaging==24.2
84
+ pandas==2.2.3
85
+ pillow==10.4.0
86
+ propcache==0.2.0
87
+ protobuf==5.26.1
88
+ pyarrow==18.0.0
89
+ pydantic==2.9.2
90
+ pydantic_core==2.23.4
91
+ pydeck==0.9.1
92
+ Pygments==2.18.0
93
+ pypdf==4.3.1
94
+ python-dateutil==2.9.0.post0
95
+ pytz==2024.2
96
+ PyYAML==6.0.2
97
+ referencing==0.35.1
98
+ regex==2024.11.6
99
+ requests==2.32.3
100
+ rich==13.9.4
101
+ rpds-py==0.21.0
102
+ safetensors==0.4.5
103
+ scikit-learn==1.5.2
104
+ scipy==1.14.1
105
+ sentence-transformers==2.7.0
106
+ six==1.16.0
107
+ smmap==5.0.1
108
+ sniffio==1.3.1
109
+ soupsieve==2.6
110
+ SQLAlchemy==2.0.36
111
+ streamlit==1.39.0
112
+ striprtf==0.0.26
113
+ sympy==1.13.1
114
+ tenacity==8.5.0
115
+ threadpoolctl==3.5.0
116
+ tiktoken==0.8.0
117
+ tokenizers==0.20.3
118
+ toml==0.10.2
119
+ torch==2.5.0+cu121
120
+ torchaudio==2.5.0+cu121
121
+ torchvision==0.20.0+cu121
122
+ tornado==6.4.1
123
+ tqdm==4.67.0
124
+ transformers==4.46.3
125
+ triton==3.1.0
126
+ typing-inspect==0.9.0
127
+ typing_extensions==4.12.2
128
+ tzdata==2024.2
129
+ urllib3==2.2.3
130
+ watchdog==5.0.3
131
+ wrapt==1.16.0
132
+ yarl==1.17.2