Icarus011 commited on
Commit
c3cdcd0
·
verified ·
1 Parent(s): 9cadd1e

Delete llamaindex_demo

Browse files
llamaindex_demo/.ipynb_checkpoints/app-checkpoint.py DELETED
@@ -1,83 +0,0 @@
1
- import streamlit as st
2
- from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
3
- from llama_index.embeddings.huggingface import HuggingFaceEmbedding
4
- from llama_index.legacy.callbacks import CallbackManager
5
- from llama_index.llms.openai_like import OpenAILike
6
-
7
- # Create an instance of CallbackManager
8
- callback_manager = CallbackManager()
9
-
10
- api_base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
11
- model = "internlm2.5-latest"
12
- api_key = "eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFM1MTIifQ.eyJqdGkiOiI4MDAwNDUzMiIsInJvbCI6IlJPTEVfUkVHSVNURVIiLCJpc3MiOiJPcGVuWExhYiIsImlhdCI6MTczNzU1NTczMywiY2xpZW50SWQiOiJlYm1ydm9kNnlvMG5semFlazF5cCIsInBob25lIjoiMTgxNTQ1NzMwNTMiLCJ1dWlkIjoiMTU2ZTVjOGYtYTBkMy00ZmE2LTg4YmEtZjYwZDg0YWIwMWI1IiwiZW1haWwiOiIiLCJleHAiOjE3NTMxMDc3MzN9.CXFRD4GYmpMmqeKawi_NoVqt7LiZ6zDwYGGc-AVh-qmlgiGyAp9SbUrfbUu8YmyOBDSM3bcZ7gc9IUtm0NnHSg"
13
-
14
- # api_base_url = "https://api.siliconflow.cn/v1"
15
- # model = "internlm/internlm2_5-7b-chat"
16
- # api_key = "请填写 API Key"
17
-
18
- llm =OpenAILike(model=model, api_base=api_base_url, api_key=api_key, is_chat_model=True,callback_manager=callback_manager)
19
-
20
-
21
-
22
- st.set_page_config(page_title="llama_index_demo", page_icon="🦜🔗")
23
- st.title("llama_index_demo")
24
-
25
- # 初始化模型
26
- @st.cache_resource
27
- def init_models():
28
- embed_model = HuggingFaceEmbedding(
29
- model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
30
- )
31
- Settings.embed_model = embed_model
32
-
33
- #用初始化llm
34
- Settings.llm = llm
35
-
36
- documents = SimpleDirectoryReader("/root/llamaindex_demo/data").load_data()
37
- index = VectorStoreIndex.from_documents(documents)
38
- query_engine = index.as_query_engine()
39
-
40
- return query_engine
41
-
42
- # 检查是否需要初始化模型
43
- if 'query_engine' not in st.session_state:
44
- st.session_state['query_engine'] = init_models()
45
-
46
- def greet2(question):
47
- response = st.session_state['query_engine'].query(question)
48
- return response
49
-
50
-
51
- # Store LLM generated responses
52
- if "messages" not in st.session_state.keys():
53
- st.session_state.messages = [{"role": "assistant", "content": "你好,我是你的助手,有什么我可以帮助你的吗?"}]
54
-
55
- # Display or clear chat messages
56
- for message in st.session_state.messages:
57
- with st.chat_message(message["role"]):
58
- st.write(message["content"])
59
-
60
- def clear_chat_history():
61
- st.session_state.messages = [{"role": "assistant", "content": "你好,我是你的助手,有什么我可以帮助你的吗?"}]
62
-
63
- st.sidebar.button('Clear Chat History', on_click=clear_chat_history)
64
-
65
- # Function for generating LLaMA2 response
66
- def generate_llama_index_response(prompt_input):
67
- return greet2(prompt_input)
68
-
69
- # User-provided prompt
70
- if prompt := st.chat_input():
71
- st.session_state.messages.append({"role": "user", "content": prompt})
72
- with st.chat_message("user"):
73
- st.write(prompt)
74
-
75
- # Gegenerate_llama_index_response last message is not from assistant
76
- if st.session_state.messages[-1]["role"] != "assistant":
77
- with st.chat_message("assistant"):
78
- with st.spinner("Thinking..."):
79
- response = generate_llama_index_response(prompt)
80
- placeholder = st.empty()
81
- placeholder.markdown(response)
82
- message = {"role": "assistant", "content": response}
83
- st.session_state.messages.append(message)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
llamaindex_demo/.ipynb_checkpoints/download_hf-checkpoint.py DELETED
@@ -1,7 +0,0 @@
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 /root/model/sentence-transformer')
 
 
 
 
 
 
 
 
llamaindex_demo/.ipynb_checkpoints/llamaindex_RAG-checkpoint.py DELETED
@@ -1,48 +0,0 @@
1
- import os
2
- os.environ['NLTK_DATA'] = '/root/nltk_data'
3
-
4
- from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
5
- from llama_index.core.settings import Settings
6
- from llama_index.embeddings.huggingface import HuggingFaceEmbedding
7
- from llama_index.legacy.callbacks import CallbackManager
8
- from llama_index.llms.openai_like import OpenAILike
9
-
10
-
11
- # Create an instance of CallbackManager
12
- callback_manager = CallbackManager()
13
-
14
- api_base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
15
- model = "internlm2.5-latest"
16
- api_key = "eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFM1MTIifQ.eyJqdGkiOiI4MDAwNDUzMiIsInJvbCI6IlJPTEVfUkVHSVNURVIiLCJpc3MiOiJPcGVuWExhYiIsImlhdCI6MTczNzU1NTczMywiY2xpZW50SWQiOiJlYm1ydm9kNnlvMG5semFlazF5cCIsInBob25lIjoiMTgxNTQ1NzMwNTMiLCJ1dWlkIjoiMTU2ZTVjOGYtYTBkMy00ZmE2LTg4YmEtZjYwZDg0YWIwMWI1IiwiZW1haWwiOiIiLCJleHAiOjE3NTMxMDc3MzN9.CXFRD4GYmpMmqeKawi_NoVqt7LiZ6zDwYGGc-AVh-qmlgiGyAp9SbUrfbUu8YmyOBDSM3bcZ7gc9IUtm0NnHSg"
17
-
18
- # api_base_url = "https://api.siliconflow.cn/v1"
19
- # model = "internlm/internlm2_5-7b-chat"
20
- # api_key = "请填写 API Key"
21
-
22
-
23
-
24
- llm =OpenAILike(model=model, api_base=api_base_url, api_key=api_key, is_chat_model=True,callback_manager=callback_manager)
25
-
26
-
27
- #初始化一个HuggingFaceEmbedding对象,用于将文本转换为向量表示
28
- embed_model = HuggingFaceEmbedding(
29
- #指定了一个预训练的sentence-transformer模型的路径
30
- model_name="/root/model/sentence-transformer"
31
- )
32
- #将创建的嵌入模型赋值给全局设置的embed_model属性,
33
- #这样在后续的索引构建过程中就会使用这个模型。
34
- Settings.embed_model = embed_model
35
-
36
- #初始化llm
37
- Settings.llm = llm
38
-
39
- #从指定目录读取所有文档,并加载数据到内存中
40
- documents = SimpleDirectoryReader("/root/llamaindex_demo/data").load_data()
41
- #创建一个VectorStoreIndex,并使用之前加载的文档来构建索引。
42
- # 此索引将文档转换为向量,并存储这些向量以便于快速检索。
43
- index = VectorStoreIndex.from_documents(documents)
44
- # 创建一个查询引擎,这个引擎可以接收查询并返回相关文档的响应。
45
- query_engine = index.as_query_engine()
46
- response = query_engine.query("特朗普发行了什么加密货币?")
47
-
48
- print(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
llamaindex_demo/.ipynb_checkpoints/test_internlm-checkpoint.py DELETED
@@ -1,22 +0,0 @@
1
- from openai import OpenAI
2
-
3
- base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
4
- api_key = "eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFM1MTIifQ.eyJqdGkiOiI4MDAwNDUzMiIsInJvbCI6IlJPTEVfUkVHSVNURVIiLCJpc3MiOiJPcGVuWExhYiIsImlhdCI6MTczNzU1NTczMywiY2xpZW50SWQiOiJlYm1ydm9kNnlvMG5semFlazF5cCIsInBob25lIjoiMTgxNTQ1NzMwNTMiLCJ1dWlkIjoiMTU2ZTVjOGYtYTBkMy00ZmE2LTg4YmEtZjYwZDg0YWIwMWI1IiwiZW1haWwiOiIiLCJleHAiOjE3NTMxMDc3MzN9.CXFRD4GYmpMmqeKawi_NoVqt7LiZ6zDwYGGc-AVh-qmlgiGyAp9SbUrfbUu8YmyOBDSM3bcZ7gc9IUtm0NnHSg"
5
- model="internlm2.5-latest"
6
-
7
- # base_url = "https://api.siliconflow.cn/v1"
8
- # api_key = "sk-请填写准确的 token!"
9
- # model="internlm/internlm2_5-7b-chat"
10
-
11
- client = OpenAI(
12
- api_key=api_key ,
13
- base_url=base_url,
14
- )
15
-
16
- chat_rsp = client.chat.completions.create(
17
- model=model,
18
- messages=[{"role": "user", "content": "特朗普发行了什么加密货币?"}],
19
- )
20
-
21
- for choice in chat_rsp.choices:
22
- print(choice.message.content)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
llamaindex_demo/app.py DELETED
@@ -1,83 +0,0 @@
1
- import streamlit as st
2
- from llama_index.core import VectorStoreIndex, SimpleDirectoryReader, Settings
3
- from llama_index.embeddings.huggingface import HuggingFaceEmbedding
4
- from llama_index.legacy.callbacks import CallbackManager
5
- from llama_index.llms.openai_like import OpenAILike
6
-
7
- # Create an instance of CallbackManager
8
- callback_manager = CallbackManager()
9
-
10
- api_base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
11
- model = "internlm2.5-latest"
12
- api_key = "eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFM1MTIifQ.eyJqdGkiOiI4MDAwNDUzMiIsInJvbCI6IlJPTEVfUkVHSVNURVIiLCJpc3MiOiJPcGVuWExhYiIsImlhdCI6MTczNzU1NTczMywiY2xpZW50SWQiOiJlYm1ydm9kNnlvMG5semFlazF5cCIsInBob25lIjoiMTgxNTQ1NzMwNTMiLCJ1dWlkIjoiMTU2ZTVjOGYtYTBkMy00ZmE2LTg4YmEtZjYwZDg0YWIwMWI1IiwiZW1haWwiOiIiLCJleHAiOjE3NTMxMDc3MzN9.CXFRD4GYmpMmqeKawi_NoVqt7LiZ6zDwYGGc-AVh-qmlgiGyAp9SbUrfbUu8YmyOBDSM3bcZ7gc9IUtm0NnHSg"
13
-
14
- # api_base_url = "https://api.siliconflow.cn/v1"
15
- # model = "internlm/internlm2_5-7b-chat"
16
- # api_key = "请填写 API Key"
17
-
18
- llm =OpenAILike(model=model, api_base=api_base_url, api_key=api_key, is_chat_model=True,callback_manager=callback_manager)
19
-
20
-
21
-
22
- st.set_page_config(page_title="llama_index_demo", page_icon="🦜🔗")
23
- st.title("llama_index_demo")
24
-
25
- # 初始化模型
26
- @st.cache_resource
27
- def init_models():
28
- embed_model = HuggingFaceEmbedding(
29
- model_name="sentence-transformers/paraphrase-multilingual-MiniLM-L12-v2"
30
- )
31
- Settings.embed_model = embed_model
32
-
33
- #用初始化llm
34
- Settings.llm = llm
35
-
36
- documents = SimpleDirectoryReader("/root/llamaindex_demo/data").load_data()
37
- index = VectorStoreIndex.from_documents(documents)
38
- query_engine = index.as_query_engine()
39
-
40
- return query_engine
41
-
42
- # 检查是否需要初始化模型
43
- if 'query_engine' not in st.session_state:
44
- st.session_state['query_engine'] = init_models()
45
-
46
- def greet2(question):
47
- response = st.session_state['query_engine'].query(question)
48
- return response
49
-
50
-
51
- # Store LLM generated responses
52
- if "messages" not in st.session_state.keys():
53
- st.session_state.messages = [{"role": "assistant", "content": "你好,我是你的助手,有什么我可以帮助你的吗?"}]
54
-
55
- # Display or clear chat messages
56
- for message in st.session_state.messages:
57
- with st.chat_message(message["role"]):
58
- st.write(message["content"])
59
-
60
- def clear_chat_history():
61
- st.session_state.messages = [{"role": "assistant", "content": "你好,我是你的助手,有什么我可以帮助你的吗?"}]
62
-
63
- st.sidebar.button('Clear Chat History', on_click=clear_chat_history)
64
-
65
- # Function for generating LLaMA2 response
66
- def generate_llama_index_response(prompt_input):
67
- return greet2(prompt_input)
68
-
69
- # User-provided prompt
70
- if prompt := st.chat_input():
71
- st.session_state.messages.append({"role": "user", "content": prompt})
72
- with st.chat_message("user"):
73
- st.write(prompt)
74
-
75
- # Gegenerate_llama_index_response last message is not from assistant
76
- if st.session_state.messages[-1]["role"] != "assistant":
77
- with st.chat_message("assistant"):
78
- with st.spinner("Thinking..."):
79
- response = generate_llama_index_response(prompt)
80
- placeholder = st.empty()
81
- placeholder.markdown(response)
82
- message = {"role": "assistant", "content": response}
83
- st.session_state.messages.append(message)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
llamaindex_demo/data/.ipynb_checkpoints/README_zh-CN-checkpoint.md DELETED
@@ -1,304 +0,0 @@
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)。同时,请遵守所使用的模型与数据集的许可证。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
llamaindex_demo/data/.ipynb_checkpoints/trump-checkpoint.txt DELETED
@@ -1,38 +0,0 @@
1
- 当地时间1月17日晚间,特朗普在社交媒体上公布了他自己的meme币:TRUMP币。meme币,又被称为空气币,指和主流币种相比无基本面价值,但有主题性容易获取关注的虚拟币。
2
-
3
- 美国总统在就职前三天发行虚拟货币这样的事件史上前所未见。
4
-
5
- 起初,市场对此消息鲜少信以为真,猜测特朗普账号或许被盗,连马斯克也不能确定该消息的真伪。但数小时后,该发文仍旧存在,TRUMP币随之大涨。代币发行12小时后,其交易价格达到约30美元。截至北京时间1月19日晚9点30分,根据Coinbase(虚拟资产交易所)数据,TRUMP币的价格已上涨到71.65美元,流通市值为143.3亿美元,包含未解锁币在内的市值为716.5亿美元。特朗普身价由此大涨573.2亿美元(约合4198.8亿元人民币)。这相较于其发币之前的身价,大涨超10倍。
6
-
7
- 不少币圈人也参与了这场“狂欢”,一位币圈KOL(关键意见领袖)在社交媒体发文称,“7点50分许愿今年能赚1000万元,10点特朗普就来帮忙了。”根据他晒出的交易图,其于北京时间1月18日上午10点15分下单,账面盈利已超过1000万美元。也有人因手速太快错过了“暴富”机会,身处中国香港的虚拟资产从业者小孙告诉《财经》,“周六早上睡得迷迷糊糊下单了,赚了20美元后心安理得地卖出了。”
8
-
9
- “作为一位自带争议和全球化流量的名人,特朗普通过发币成功将个人品牌货币化。这是区块链生态中注意力直接转化为资产价值的典型事件,更成为meme币历史上影响力最大的事件之一。其背后是一种全新的经济逻辑:名人IP、热点事件和社区共识成为推动资本流动的核心动能。”HashKey首席分析师Jeffrey Ding对《财经》表示。
10
-
11
- Jeffrey Ding强调道,TRUMP币是一场资本与注意力的狂欢,但对于投资者而言,狂欢过后,风险可能才是最值得警惕的现实。
12
-
13
- 特朗普发币身价大涨
14
-
15
- 根据CoinGecko的价格数据,TRUMP币以0.1824美元(折合1.3361元人民币)的开盘价开始交易,12小时内涨超15000%至约30美元(折合约219.76元人民币),代币市值则上升至300亿美元(2197.56亿元人民币)。
16
-
17
- 截至北京时间1月19日晚9点30分,根据Coinbase数据,TRUMP币的价格已上涨到71.65美元。
18
-
19
- (数据来源:Coinbase)(数据来源:Coinbase)
20
- 按照10亿枚总量、2亿枚发行量计算,当前TRUMP币的总市值为716.5亿美元,流通市值为143.3亿美元;特朗普家族持有的8亿枚TRUMP币,市值约为573.2亿美元。
21
-
22
- 而福布斯2024年11月对特朗普身家的估值为56亿美元,这意味着,依靠发币,特朗普身价在短短两日内大涨超10倍。
23
-
24
- 根据GetTrumpMemes官网,TRUMP币80%的供应量由特朗普集团的附属公司CIC Digital和CIC共同拥有的实体Fight Fight Fight LLC持有。TRUMP币的初始发行量为2亿枚,三年内预计发行量将逐步增加到10亿枚。CIC Digital及其关联方将获得TRUMP交易活动产生的收入,收入未来24个月内解锁。
25
-
26
- 此外,官网还提到,TRUMP币上有特朗普在2024年7月遇刺事件中的形象,旨在表达对 “TRUMP” 符号及其相关艺术品所有权的独特理解和信念的支持和参与,并非意在成为证券资产。官网不涉及政治,与任何政治竞选活动或任何政治办公室或政府机构无关。
27
-
28
- Coinbase产品业务运营主管Conor Grogan在社交媒体上发文表示,TRUMP币供应的80%被锁定在一个多重签名钱包中,由创建者控制,只有20%的供应量在公众投资者和流动性之间平均分配。该项目获得了来自Binance和Gate的数百万美元种子资金,这两家交易所不向美国客户提供服务。
29
-
30
- 但对于特朗普发币,业界仍存在担忧。Jeffrey Ding告诉《财经》,首先,TRUMP币的火爆为Solana(去中心化托管平台)生态带来了巨大的链上流量,挑战了中心化交易所在市场中的传统地位。然而,这种基于注意力的经济模式高度投机,风险也不容忽视。TRUMP币的价值完全依赖于公众对特朗普及其政治符号的兴趣维持,一旦注意力转移或市场情绪改变,其价格可能迅速崩溃。此外,监管风险亦是悬在市场头顶的达摩克利斯之剑,尤其在美国,名人发币可能引发证券法合规问题,甚至可能成为监管整顿meme市场的潜在因素。
31
-
32
- 再度带涨比特币
33
-
34
- 有业内投资人表示,因为发行加密货币,特朗普和他的家族在过去12小时内赚的钱比他们过去50年赚的钱还要多。这或许也预示着,在特朗普任职美国总统后,利好加密货币的举动和政策,还会使TRUMP币在内的加密货币价格继续上涨。
35
-
36
- 业内人士分析称,此前由于特朗普竞选美国总统获胜,加密市场缔造了新一轮的牛市,比特币价格一度冲上了10万美元。此后由于多种复杂的原因,比特币价格出现了剧烈的震荡,一度回调跌破9万美元。随着特朗普就职日期的临近,加密市场此前因特朗普竞选获胜所催生的牛市,迎来了利好局部落地的节点。
37
-
38
- 华尔街知名投资机构伯恩斯坦(Bernstein)在最近发布的一份报告中预测,作为全球市值最大的加密货币,比特币的价格2025年将延续“超级牛市曲线”,预测2025年比特币将再次出现三位数级别的上涨幅度,触及20万美元这一历史级关口。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
llamaindex_demo/data/README_zh-CN.md DELETED
@@ -1,304 +0,0 @@
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)。同时,请遵守所使用的模型与数据集的许可证。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
llamaindex_demo/data/trump.txt DELETED
@@ -1,38 +0,0 @@
1
- 当地时间1月17日晚间,特朗普在社交媒体上公布了他自己的meme币:TRUMP币。meme币,又被称为空气币,指和主流币种相比无基本面价值,但有主题性容易获取关注的虚拟币。
2
-
3
- 美国总统在就职前三天发行虚拟货币这样的事件史上前所未见。
4
-
5
- 起初,市场对此消息鲜少信以为真,猜测特朗普账号或许被盗,连马斯克也不能确定该消息的真伪。但数小时后,该发文仍旧存在,TRUMP币随之大涨。代币发行12小时后,其交易价格达到约30美元。截至北京时间1月19日晚9点30分,根据Coinbase(虚拟资产交易所)数据,TRUMP币的价格已上涨到71.65美元,流通市值为143.3亿美元,包含未解锁币在内的市值为716.5亿美元。特朗普身价由此大涨573.2亿美元(约合4198.8亿元人民币)。这相较于其发币之前的身价,大涨超10倍。
6
-
7
- 不少币圈人也参与了这场“狂欢”,一位币圈KOL(关键意见领袖)在社交媒体发文称,“7点50分许愿今年能赚1000万元,10点特朗普就来帮忙了。”根据他晒出的交易图,其于北京时间1月18日上午10点15分下单,账面盈利已超过1000万美元。也有人因手速太快错过了“暴富”机会,身处中国香港的虚拟资产从业者小孙告诉《财经》,“周六早上睡得迷迷糊糊下单了,赚了20美元后心安理得地卖出了。”
8
-
9
- “作为一位自带争议和全球化流量的名人,特朗普通过发币成功将个人品牌货币化。这是区块链生态中注意力直接转化为资产价值的典型事件,更成为meme币历史上影响力最大的事件之一。其背后是一种全新的经济逻辑:名人IP、热点事件和社区共识成为推动资本流动的核心动能。”HashKey首席分析师Jeffrey Ding对《财经》表示。
10
-
11
- Jeffrey Ding强调道,TRUMP币是一场资本与注意力的狂欢,但对于投资者而言,狂欢过后,风险可能才是最值得警惕的现实。
12
-
13
- 特朗普发币身价大涨
14
-
15
- 根据CoinGecko的价格数据,TRUMP币以0.1824美元(折合1.3361元人民币)的开盘价开始交易,12小时内涨超15000%至约30美元(折合约219.76元人民币),代币市值则上升至300亿美元(2197.56亿元人民币)。
16
-
17
- 截至北京时间1月19日晚9点30分,根据Coinbase数据,TRUMP币的价格已上涨到71.65美元。
18
-
19
- (数据来源:Coinbase)(数据来源:Coinbase)
20
- 按照10亿枚总量、2亿枚发行量计算,当前TRUMP币的总市值为716.5亿美元,流通市值为143.3亿美元;特朗普家族持有的8亿枚TRUMP币,市值约为573.2亿美元。
21
-
22
- 而福布斯2024年11月对特朗普身家的估值为56亿美元,这意味着,依靠发币,特朗普身价在短短两日内大涨超10倍。
23
-
24
- 根据GetTrumpMemes官网,TRUMP币80%的供应量由特朗普集团的附属公司CIC Digital和CIC共同拥有的实体Fight Fight Fight LLC持有。TRUMP币的初始发行量为2亿枚,三年内预计发行量将逐步增加到10亿枚。CIC Digital及其关联方将获得TRUMP交易活动产生的收入,收入未来24个月内解锁。
25
-
26
- 此外,官网还提到,TRUMP币上有特朗普在2024年7月遇刺事件中的形象,旨在表达对 “TRUMP” 符号及其相关艺术品所有权的独特理解和信念的支持和参与,并非意在成为证券资产。官网不涉及政治,与任何政治竞选活动或任何政治办公室或政府机构无关。
27
-
28
- Coinbase产品业务运营主管Conor Grogan在社交媒体上发文表示,TRUMP币供应的80%被锁定在一个多重签名钱包中,由创建者控制,只有20%的供应量在公众投资者和流动性之间平均分配。该项目获得了来自Binance和Gate的数百万美元种子资金,这两家交易所不向美国客户提供服务。
29
-
30
- 但对于特朗普发币,业界仍存在担忧。Jeffrey Ding告诉《财经》,首先,TRUMP币的火爆为Solana(去中心化托管平台)生态带来了巨大的链上流量,挑战了中心化交易所在市场中的传统地位。然而,这种基于注意力的经济模式高度投机,风险也不容忽视。TRUMP币的价值完全依赖于公众对特朗普及其政治符号的兴趣维持,一旦注意力转移或市场情绪改变,其价格可能迅速崩溃。此外,监管风险亦是悬在市场头顶的达摩克利斯之剑,尤其在美国,名人发币可能引发证券法合规问题,甚至可能成为监管整顿meme市场的潜在因素。
31
-
32
- 再度带涨比特币
33
-
34
- 有业内投资人表示,因为发行加密货币,特朗普和他的家族在过去12小时内赚的钱比他们过去50年赚的钱还要多。这或许也预示着,在特朗普任职美国总统后,利好加密货币的举动和政策,还会使TRUMP币在内的加密货币价格继续上涨。
35
-
36
- 业内人士分析称,此前由于特朗普竞选美国总统获胜,加密市场缔造了新一轮的牛市,比特币价格一度冲上了10万美元。此后由于多种复杂的原因,比特币价格出现了剧烈的震荡,一度回调跌破9万美元。随着特朗普就职日期的临近,加密市场此前因特朗普竞选获胜所催生的牛市,迎来了利好局部落地的节点。
37
-
38
- 华尔街知名投资机构伯恩斯坦(Bernstein)在最近发布的一份报告中预测,作为全球市值最大的加密货币,比特币的价格2025年将延续“超级牛市曲线”,预测2025年比特币将再次出现三位数级别的上涨幅度,触及20万美元这一历史级关口。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
llamaindex_demo/download_hf.py DELETED
@@ -1,7 +0,0 @@
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 /root/model/sentence-transformer')
 
 
 
 
 
 
 
 
llamaindex_demo/llamaindex_RAG.py DELETED
@@ -1,48 +0,0 @@
1
- import os
2
- os.environ['NLTK_DATA'] = '/root/nltk_data'
3
-
4
- from llama_index.core import VectorStoreIndex, SimpleDirectoryReader
5
- from llama_index.core.settings import Settings
6
- from llama_index.embeddings.huggingface import HuggingFaceEmbedding
7
- from llama_index.legacy.callbacks import CallbackManager
8
- from llama_index.llms.openai_like import OpenAILike
9
-
10
-
11
- # Create an instance of CallbackManager
12
- callback_manager = CallbackManager()
13
-
14
- api_base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
15
- model = "internlm2.5-latest"
16
- api_key = "eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFM1MTIifQ.eyJqdGkiOiI4MDAwNDUzMiIsInJvbCI6IlJPTEVfUkVHSVNURVIiLCJpc3MiOiJPcGVuWExhYiIsImlhdCI6MTczNzU1NTczMywiY2xpZW50SWQiOiJlYm1ydm9kNnlvMG5semFlazF5cCIsInBob25lIjoiMTgxNTQ1NzMwNTMiLCJ1dWlkIjoiMTU2ZTVjOGYtYTBkMy00ZmE2LTg4YmEtZjYwZDg0YWIwMWI1IiwiZW1haWwiOiIiLCJleHAiOjE3NTMxMDc3MzN9.CXFRD4GYmpMmqeKawi_NoVqt7LiZ6zDwYGGc-AVh-qmlgiGyAp9SbUrfbUu8YmyOBDSM3bcZ7gc9IUtm0NnHSg"
17
-
18
- # api_base_url = "https://api.siliconflow.cn/v1"
19
- # model = "internlm/internlm2_5-7b-chat"
20
- # api_key = "请填写 API Key"
21
-
22
-
23
-
24
- llm =OpenAILike(model=model, api_base=api_base_url, api_key=api_key, is_chat_model=True,callback_manager=callback_manager)
25
-
26
-
27
- #初始化一个HuggingFaceEmbedding对象,用于将文本转换为向量表示
28
- embed_model = HuggingFaceEmbedding(
29
- #指定了一个预训练的sentence-transformer模型的路径
30
- model_name="/root/model/sentence-transformer"
31
- )
32
- #将创建的嵌入模型赋值给全局设置的embed_model属性,
33
- #这样在后续的索引构建过程中就会使用这个模型。
34
- Settings.embed_model = embed_model
35
-
36
- #初始化llm
37
- Settings.llm = llm
38
-
39
- #从指定目录读取所有文档,并加载数据到内存中
40
- documents = SimpleDirectoryReader("/root/llamaindex_demo/data").load_data()
41
- #创建一个VectorStoreIndex,并使用之前加载的文档来构建索引。
42
- # 此索引将文档转换为向量,并存储这些向量以便于快速检索。
43
- index = VectorStoreIndex.from_documents(documents)
44
- # 创建一个查询引擎,这个引擎可以接收查询并返回相关文档的响应。
45
- query_engine = index.as_query_engine()
46
- response = query_engine.query("特朗普发行了什么加密货币?")
47
-
48
- print(response)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
llamaindex_demo/test_internlm.py DELETED
@@ -1,22 +0,0 @@
1
- from openai import OpenAI
2
-
3
- base_url = "https://internlm-chat.intern-ai.org.cn/puyu/api/v1/"
4
- api_key = "eyJ0eXBlIjoiSldUIiwiYWxnIjoiSFM1MTIifQ.eyJqdGkiOiI4MDAwNDUzMiIsInJvbCI6IlJPTEVfUkVHSVNURVIiLCJpc3MiOiJPcGVuWExhYiIsImlhdCI6MTczNzU1NTczMywiY2xpZW50SWQiOiJlYm1ydm9kNnlvMG5semFlazF5cCIsInBob25lIjoiMTgxNTQ1NzMwNTMiLCJ1dWlkIjoiMTU2ZTVjOGYtYTBkMy00ZmE2LTg4YmEtZjYwZDg0YWIwMWI1IiwiZW1haWwiOiIiLCJleHAiOjE3NTMxMDc3MzN9.CXFRD4GYmpMmqeKawi_NoVqt7LiZ6zDwYGGc-AVh-qmlgiGyAp9SbUrfbUu8YmyOBDSM3bcZ7gc9IUtm0NnHSg"
5
- model="internlm2.5-latest"
6
-
7
- # base_url = "https://api.siliconflow.cn/v1"
8
- # api_key = "sk-请填写准确的 token!"
9
- # model="internlm/internlm2_5-7b-chat"
10
-
11
- client = OpenAI(
12
- api_key=api_key ,
13
- base_url=base_url,
14
- )
15
-
16
- chat_rsp = client.chat.completions.create(
17
- model=model,
18
- messages=[{"role": "user", "content": "特朗普发行了什么加密货币?"}],
19
- )
20
-
21
- for choice in chat_rsp.choices:
22
- print(choice.message.content)