Langchain-Chatchat
Langchain-Chatchat copied to clipboard
[FEATURE] 如何将高效参数微调训练的模型加载起来
功能描述 / Feature Description 比如使用lora进行训练后将微调模型加载起来,没找到在哪里修改
解决的问题 / Problem Solved 就是想自己微调模型能生成符合某种措辞的回答,然后结合langchain文章检索功能生成类似报告的回答
🤖
嘿,@goodmaney!很高兴再次看到你在这里提出问题😜
根据我在Langchain-Chatchat仓库中找到的信息,你可以按照以下步骤加载并使用经过lora微调训练的模型:
-
首先,你需要从
server.utils导入get_ChatOpenAI函数,从configs.model_config导入LLM_MODELS和TEMPERATURE,从langchain.chains导入LLMChain,以及从langchain.prompts.chat导入ChatPromptTemplate和HumanMessagePromptTemplate。 -
然后,你可以使用
get_ChatOpenAI函数和LLM_MODELS的第一个模型以及TEMPERATURE来获取模型。 -
创建一个人类消息模板,使用
HumanMessagePromptTemplate.from_template方法,输入为"{input}"。 -
创建一个聊天提示模板,使用
ChatPromptTemplate.from_messages方法,输入为一个列表,列表中的元素为元组,元组的第一个元素为角色("human"或"ai"),第二个元素为消息。 -
创建一个
LLMChain实例,提示为聊天提示模板,llm为模型,verbose设置为True。 -
最后,你可以使用
chain实例的调用方法,输入为一个字典,字典的键为"input",值为你想要输入的消息。
以下是对应的代码:
from server.utils import get_ChatOpenAI
from configs.model_config import LLM_MODELS, TEMPERATURE
from langchain.chains import LLMChain
from langchain.prompts.chat import (
ChatPromptTemplate,
HumanMessagePromptTemplate,
)
model = get_ChatOpenAI(model_name=LLM_MODELS[0], temperature=TEMPERATURE)
human_prompt = "{input}"
human_message_template = HumanMessagePromptTemplate.from_template(human_prompt)
chat_prompt = ChatPromptTemplate.from_messages(
[("human", "我们来玩成语接龙,我先来,生龙活虎"),
("ai", "虎头虎脑"),
("human", "{input}")])
chain = LLMChain(prompt=chat_prompt, llm=model, verbose=True)
print(chain({"input": "恼羞成怒"}))
这段代码将加载并使用经过lora微调训练的模型,生成符合特定措辞的回答,并结合langchain文章检索功能生成类似报告的回答。
关于你的问题,get_ChatOpenAI函数在加载模型中的具体作用,我在仓库中没有找到相关的信息,可能需要在其他地方寻找答案,或者我可能遗漏了一些信息。
你可以参考这个已解决的问题:请问通过lora训练官方模型得到的微调模型文件该如何加载?,在dev-llmf分支的models/loader/args.py中检查项目启动参数。
如果你有更多的问题,或者需要更详细的解答,欢迎随时提问。
Sources
About Dosu
This response is meant to be useful and save you time. It is not meant to be a precise solution, but rather a starting point for your own research.
Help me be more useful! Please leave a 👍 if this is helpful and 👎 if it is irrelevant.
If you want to continue the conversation, start your reply with @dosu-bot.
查看wiki