赞
踩
Web UI的部署如下:
pip install -r requirements.txt
pip install -r requirements_web_demo.txt
python web_demo.py
命令行的部署如下:
pip install -r requirements.txt
python cli_demo.py
阿里通义千问完整技术报告:https://zhuanlan.zhihu.com/p/685633623
先用lora微调,保存lora微调后的额外参数
bash finetune/finetune_ds.sh
运行下列代码获得原参数+微调参数的完整模型
# lora微调后的模型与原模型混合 from peft import AutoPeftModelForCausalLM path_to_adapter = "model/T_LoRa_model_14B_10E_30" # lora参数的保存地址 new_model_directory = "./model/T_LoRa_14B_10E_30_merged" # 完整模型的保存地址 model = AutoPeftModelForCausalLM.from_pretrained( path_to_adapter, # path to the output directory device_map="auto", trust_remote_code=True ).eval() merged_model = model.merge_and_unload() # max_shard_size and safe serialization are not necessary. # They respectively work for sharding checkpoint and save the model to safetensors merged_model.save_pretrained(new_model_directory, max_shard_size="2048MB", safe_serialization=True) from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained( path_to_adapter, # path to the output directory trust_remote_code=True ) tokenizer.save_pretrained(new_model_directory)
训练时长(funtune.py->merge.py->web_demo.py):50min
训练时长(funtune.py->merge.py->web_demo.py):45min
merge.py加载模型:14:03-14:10
web_demo.py加载模型:14:12-14:21
训练时长(funtune.py->merge.py->web_demo.py):45min
训练时长(funtune.py->merge.py->web_demo.py): 40min
(无法正确回答数据集)
训练时长(funtune.py->merge.py->web_demo.py): 40min
第一次问:
(你的名字叫通义千问对吗?是的)
第二次问:
训练时长(funtune.py->merge.py->web_demo.py): 40min
数据集大小为40时,开始时而回答“小义”,时而回答“通义千问”
小于40时,回答“通义千问”
执行下述命令
python openai_api.py
默认的Ip地址是127.0.0.1
端口是8000
使用API示例
import openai # 使用本地部署的qwen,运行本文件前需要先运行openai_api.py openai.api_base = "http://localhost:8000/v1" openai.api_key = "none" # 使用流式回复的请求 for chunk in openai.ChatCompletion.create( model="Qwen", messages=[ {"role": "user", "content": "西红柿炒鸡蛋怎么做"} ], stream=True # 流式输出的自定义stopwords功能尚未支持,正在开发中 ): if hasattr(chunk.choices[0].delta, "content"): print(chunk.choices[0].delta.content, end="", flush=True) # 不使用流式回复的请求 response = openai.ChatCompletion.create( model="Qwen", messages=[ {"role": "user", "content": "你好"} ], stream=False, stop=[] # 在此处添加自定义的stop words 例如ReAct prompting时需要增加: stop=["Observation:"]。 ) print(response.choices[0].message.content)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。