From a70df98825a83c6f29e64df65e5eacfb992de79b Mon Sep 17 00:00:00 2001 From: Zhi-guo Huang Date: Wed, 14 Jun 2023 21:31:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0FAQ,model=5Fconfig.py,bing=5F?= =?UTF-8?q?search.py=E6=96=87=E4=BB=B6=EF=BC=8C=E5=A2=9E=E5=8A=A0bing?= =?UTF-8?q?=E6=90=9C=E7=B4=A2=E9=97=AE=E7=AD=94=E7=9B=B8=E5=85=B3=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E7=9A=84=E5=8E=9F=E5=9B=A0=E5=92=8C=E5=8F=AF=E8=83=BD?= =?UTF-8?q?=E8=A7=A3=E5=86=B3=E6=96=B9=E6=A1=88=EF=BC=8C=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E4=BA=86=E4=B8=80=E4=BA=9Btypo;=E4=BF=AE=E6=94=B9loader.py?= =?UTF-8?q?=E4=B8=ADload=5Fin=5F8bit=E5=A4=B1=E8=B4=A5=E7=9A=84=E5=8E=9F?= =?UTF-8?q?=E5=9B=A0=E5=92=8C=E8=AF=A6=E7=BB=86=E8=A7=A3=E5=86=B3=E6=96=B9?= =?UTF-8?q?=E6=A1=88=20(#610)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 修复 bing_search.py的typo;更新model_config.py中Bing Subscription Key申请方式及注意事项 * 更新FAQ,增加了[Errno 110] Connection timed out的原因与解决方案 * 修改loader.py中load_in_8bit失败的原因和详细解决方案 * update loader.py --- agent/bing_search.py | 2 +- configs/model_config.py | 11 +++++++++-- docs/FAQ.md | 5 ++++- models/loader/loader.py | 12 ++++++++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/agent/bing_search.py b/agent/bing_search.py index 2ff7749..962090c 100644 --- a/agent/bing_search.py +++ b/agent/bing_search.py @@ -7,7 +7,7 @@ from configs.model_config import BING_SEARCH_URL, BING_SUBSCRIPTION_KEY def bing_search(text, result_len=3): if not (BING_SEARCH_URL and BING_SUBSCRIPTION_KEY): return [{"snippet": "please set BING_SUBSCRIPTION_KEY and BING_SEARCH_URL in os ENV", - "title": "env inof not fould", + "title": "env info is not found", "link": "https://python.langchain.com/en/latest/modules/agents/tools/examples/bing_search.html"}] search = BingSearchAPIWrapper(bing_subscription_key=BING_SUBSCRIPTION_KEY, bing_search_url=BING_SEARCH_URL) diff --git a/configs/model_config.py b/configs/model_config.py index 086bfe0..6604fc5 100644 --- a/configs/model_config.py +++ b/configs/model_config.py @@ -163,7 +163,14 @@ flagging username: {FLAG_USER_NAME} OPEN_CROSS_DOMAIN = False # Bing 搜索必备变量 -# 使用 Bing 搜索需要使用 Bing Subscription Key -# 具体申请方式请见 https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/quickstarts/rest/python +# 使用 Bing 搜索需要使用 Bing Subscription Key,需要在azure port中申请试用bing search +# 具体申请方式请见 +# https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/create-bing-search-service-resource +# 使用python创建bing api 搜索实例详见: +# https://learn.microsoft.com/en-us/bing/search-apis/bing-web-search/quickstarts/rest/python BING_SEARCH_URL = "https://api.bing.microsoft.com/v7.0/search" +# 注意不是bing Webmaster Tools的api key, + +# 此外,如果是在服务器上,报Failed to establish a new connection: [Errno 110] Connection timed out +# 是因为服务器加了防火墙,需要联系管理员加白名单,如果公司的服务器的话,就别想了GG BING_SUBSCRIPTION_KEY = "" \ No newline at end of file diff --git a/docs/FAQ.md b/docs/FAQ.md index b43483b..f712477 100644 --- a/docs/FAQ.md +++ b/docs/FAQ.md @@ -146,7 +146,6 @@ $ pip install -r requirements.txt -i http://mirrors.aliyun.com/pypi/simple/ $ pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple/ ``` - Q12 启动api.py时upload_file接口抛出 `partially initialized module 'charset_normalizer' has no attribute 'md__mypyc' (most likely due to a circular import)` 这是由于 charset_normalizer模块版本过高导致的,需要降低低charset_normalizer的版本,测试在charset_normalizer==2.1.0上可用。 @@ -174,3 +173,7 @@ download_with_progressbar(url, tmp_path) 然后按照给定网址,如"https://paddleocr.bj.bcebos.com/PP-OCRv3/chinese/ch_PP-OCRv3_rec_infer.tar"手动下载文件,上传到对应的文件夹中,如“.paddleocr/whl/rec/ch/ch_PP-OCRv3_rec_infer/ch_PP-OCRv3_rec_infer.tar”. --- + +Q14 调用api中的 `bing_search_chat`接口时,报出 `Failed to establish a new connection: [Errno 110] Connection timed out` + +这是因为服务器加了防火墙,需要联系管理员加白名单,如果公司的服务器的话,就别想了GG--! diff --git a/models/loader/loader.py b/models/loader/loader.py index c68e71a..f315e6c 100644 --- a/models/loader/loader.py +++ b/models/loader/loader.py @@ -30,6 +30,16 @@ class LoaderCheckPoint: ptuning_dir: str = None use_ptuning_v2: bool = False # 如果开启了8bit量化加载,项目无法启动,参考此位置,选择合适的cuda版本,https://github.com/TimDettmers/bitsandbytes/issues/156 + # 另一个原因可能是由于bitsandbytes安装时选择了系统环境变量里不匹配的cuda版本, + # 例如PATH下存在cuda10.2和cuda11.2,bitsandbytes安装时选择了10.2,而torch等安装依赖的版本是11.2 + # 因此主要的解决思路是清理环境变量里PATH下的不匹配的cuda版本,一劳永逸的方法是: + # 0. 在终端执行`pip uninstall bitsandbytes` + # 1. 删除.bashrc文件下关于PATH的条目 + # 2. 在终端执行 `echo $PATH >> .bashrc` + # 3. 删除.bashrc文件下PATH中关于不匹配的cuda版本路径 + # 4. 在终端执行`source .bashrc` + # 5. 再执行`pip install bitsandbytes` + load_in_8bit: bool = False is_llamacpp: bool = False bf16: bool = False @@ -99,6 +109,8 @@ class LoaderCheckPoint: LoaderClass = AutoModelForCausalLM # Load the model in simple 16-bit mode by default + # 如果加载没问题,但在推理时报错RuntimeError: CUDA error: CUBLAS_STATUS_ALLOC_FAILED when calling `cublasCreate(handle)` + # 那还是因为显存不够,此时只能考虑--load-in-8bit,或者配置默认模型为`chatglm-6b-int8` if not any([self.llm_device.lower() == "cpu", self.load_in_8bit, self.is_llamacpp]):