Merge pull request #1356 from alphaply/update-for-qwen
修复了qwen使用本地模型时候的报错
This commit is contained in:
commit
647d9f88db
10
config.py
10
config.py
@ -15,13 +15,13 @@ API_KEY = "此处填API密钥" # 可同时填写多个API-KEY,用英文逗
|
|||||||
USE_PROXY = False
|
USE_PROXY = False
|
||||||
if USE_PROXY:
|
if USE_PROXY:
|
||||||
"""
|
"""
|
||||||
|
代理网络的地址,打开你的代理软件查看代理协议(socks5h / http)、地址(localhost)和端口(11284)
|
||||||
填写格式是 [协议]:// [地址] :[端口],填写之前不要忘记把USE_PROXY改成True,如果直接在海外服务器部署,此处不修改
|
填写格式是 [协议]:// [地址] :[端口],填写之前不要忘记把USE_PROXY改成True,如果直接在海外服务器部署,此处不修改
|
||||||
<配置教程&视频教程> https://github.com/binary-husky/gpt_academic/issues/1>
|
<配置教程&视频教程> https://github.com/binary-husky/gpt_academic/issues/1>
|
||||||
[协议] 常见协议无非socks5h/http; 例如 v2**y 和 ss* 的默认本地协议是socks5h; 而cl**h 的默认本地协议是http
|
[协议] 常见协议无非socks5h/http; 例如 v2**y 和 ss* 的默认本地协议是socks5h; 而cl**h 的默认本地协议是http
|
||||||
[地址] 懂的都懂,不懂就填localhost或者127.0.0.1肯定错不了(localhost意思是代理软件安装在本机上)
|
[地址] 填localhost或者127.0.0.1(localhost意思是代理软件安装在本机上)
|
||||||
[端口] 在代理软件的设置里找。虽然不同的代理软件界面不一样,但端口号都应该在最显眼的位置上
|
[端口] 在代理软件的设置里找。虽然不同的代理软件界面不一样,但端口号都应该在最显眼的位置上
|
||||||
"""
|
"""
|
||||||
# 代理网络的地址,打开你的*学*网软件查看代理的协议(socks5h / http)、地址(localhost)和端口(11284)
|
|
||||||
proxies = {
|
proxies = {
|
||||||
# [协议]:// [地址] :[端口]
|
# [协议]:// [地址] :[端口]
|
||||||
"http": "socks5h://localhost:11284", # 再例如 "http": "http://127.0.0.1:7890",
|
"http": "socks5h://localhost:11284", # 再例如 "http": "http://127.0.0.1:7890",
|
||||||
@ -100,6 +100,12 @@ AVAIL_LLM_MODELS = ["gpt-3.5-turbo-1106","gpt-4-1106-preview","gpt-4-vision-prev
|
|||||||
MULTI_QUERY_LLM_MODELS = "gpt-3.5-turbo&chatglm3"
|
MULTI_QUERY_LLM_MODELS = "gpt-3.5-turbo&chatglm3"
|
||||||
|
|
||||||
|
|
||||||
|
# 选择本地模型变体(只有当AVAIL_LLM_MODELS包含了对应本地模型时,才会起作用)
|
||||||
|
# 如果你选择Qwen系列的模型,那么请在下面的QWEN_MODEL_SELECTION中指定具体的模型
|
||||||
|
# 也可以是具体的模型路径
|
||||||
|
QWEN_MODEL_SELECTION = "Qwen/Qwen-1_8B-Chat-Int8"
|
||||||
|
|
||||||
|
|
||||||
# 百度千帆(LLM_MODEL="qianfan")
|
# 百度千帆(LLM_MODEL="qianfan")
|
||||||
BAIDU_CLOUD_API_KEY = ''
|
BAIDU_CLOUD_API_KEY = ''
|
||||||
BAIDU_CLOUD_SECRET_KEY = ''
|
BAIDU_CLOUD_SECRET_KEY = ''
|
||||||
|
@ -1,13 +1,7 @@
|
|||||||
model_name = "Qwen"
|
model_name = "Qwen"
|
||||||
cmd_to_install = "`pip install -r request_llms/requirements_qwen.txt`"
|
cmd_to_install = "`pip install -r request_llms/requirements_qwen.txt`"
|
||||||
|
|
||||||
|
from toolbox import ProxyNetworkActivate, get_conf
|
||||||
from transformers import AutoModel, AutoTokenizer
|
|
||||||
import time
|
|
||||||
import threading
|
|
||||||
import importlib
|
|
||||||
from toolbox import update_ui, get_conf, ProxyNetworkActivate
|
|
||||||
from multiprocessing import Process, Pipe
|
|
||||||
from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns
|
from .local_llm_class import LocalLLMHandle, get_local_llm_predict_fns
|
||||||
|
|
||||||
|
|
||||||
@ -24,16 +18,14 @@ class GetQwenLMHandle(LocalLLMHandle):
|
|||||||
|
|
||||||
def load_model_and_tokenizer(self):
|
def load_model_and_tokenizer(self):
|
||||||
# 🏃♂️🏃♂️🏃♂️ 子进程执行
|
# 🏃♂️🏃♂️🏃♂️ 子进程执行
|
||||||
import os, glob
|
# from modelscope import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
||||||
import os
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
||||||
import platform
|
from transformers.generation import GenerationConfig
|
||||||
from modelscope import AutoModelForCausalLM, AutoTokenizer, GenerationConfig
|
|
||||||
|
|
||||||
with ProxyNetworkActivate('Download_LLM'):
|
with ProxyNetworkActivate('Download_LLM'):
|
||||||
model_id = 'qwen/Qwen-7B-Chat'
|
model_id = get_conf('QWEN_MODEL_SELECTION')
|
||||||
self._tokenizer = AutoTokenizer.from_pretrained('Qwen/Qwen-7B-Chat', trust_remote_code=True, resume_download=True)
|
self._tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True, resume_download=True)
|
||||||
# use fp16
|
# use fp16
|
||||||
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", trust_remote_code=True, fp16=True).eval()
|
model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto", trust_remote_code=True).eval()
|
||||||
model.generation_config = GenerationConfig.from_pretrained(model_id, trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参
|
model.generation_config = GenerationConfig.from_pretrained(model_id, trust_remote_code=True) # 可指定不同的生成长度、top_p等相关超参
|
||||||
self._model = model
|
self._model = model
|
||||||
|
|
||||||
@ -51,7 +43,7 @@ class GetQwenLMHandle(LocalLLMHandle):
|
|||||||
|
|
||||||
query, max_length, top_p, temperature, history = adaptor(kwargs)
|
query, max_length, top_p, temperature, history = adaptor(kwargs)
|
||||||
|
|
||||||
for response in self._model.chat(self._tokenizer, query, history=history, stream=True):
|
for response in self._model.chat_stream(self._tokenizer, query, history=history):
|
||||||
yield response
|
yield response
|
||||||
|
|
||||||
def try_to_import_special_deps(self, **kwargs):
|
def try_to_import_special_deps(self, **kwargs):
|
||||||
|
@ -1,2 +1,4 @@
|
|||||||
modelscope
|
modelscope
|
||||||
transformers_stream_generator
|
transformers_stream_generator
|
||||||
|
auto-gptq
|
||||||
|
optimum
|
@ -16,8 +16,9 @@ if __name__ == "__main__":
|
|||||||
# from request_llms.bridge_jittorllms_llama import predict_no_ui_long_connection
|
# from request_llms.bridge_jittorllms_llama import predict_no_ui_long_connection
|
||||||
# from request_llms.bridge_claude import predict_no_ui_long_connection
|
# from request_llms.bridge_claude import predict_no_ui_long_connection
|
||||||
# from request_llms.bridge_internlm import predict_no_ui_long_connection
|
# from request_llms.bridge_internlm import predict_no_ui_long_connection
|
||||||
from request_llms.bridge_deepseekcoder import predict_no_ui_long_connection
|
# from request_llms.bridge_deepseekcoder import predict_no_ui_long_connection
|
||||||
# from request_llms.bridge_qwen import predict_no_ui_long_connection
|
# from request_llms.bridge_qwen_7B import predict_no_ui_long_connection
|
||||||
|
from request_llms.bridge_qwen import predict_no_ui_long_connection
|
||||||
# from request_llms.bridge_spark import predict_no_ui_long_connection
|
# from request_llms.bridge_spark import predict_no_ui_long_connection
|
||||||
# from request_llms.bridge_zhipu import predict_no_ui_long_connection
|
# from request_llms.bridge_zhipu import predict_no_ui_long_connection
|
||||||
# from request_llms.bridge_chatglm3 import predict_no_ui_long_connection
|
# from request_llms.bridge_chatglm3 import predict_no_ui_long_connection
|
||||||
|
Loading…
x
Reference in New Issue
Block a user