update docs

This commit is contained in:
imClumsyPanda 2023-08-12 17:04:38 +08:00
parent bbfb599412
commit e196ef0b17
6 changed files with 30 additions and 1259 deletions

File diff suppressed because it is too large Load Diff

View File

@ -6,21 +6,9 @@ A1: 目前已测试支持 txt、docx、md、pdf 格式文件,更多文件格
---
Q2: 执行 `pip install -r requirements.txt` 过程中,安装 `detectron2` 时发生报错怎么办
Q2: 使用过程中 Python 包 `nltk`发生了 `Resource punkt not found.`报错,该如何解决
A2: 如果不需要对 `pdf` 格式文件读取,可不安装 `detectron2`;如需对 `pdf` 文件进行高精度文本提取,建议按照如下方法安装:
```commandline
$ git clone https://github.com/facebookresearch/detectron2.git
$ cd detectron2
$ pip install -e .
```
---
Q3: 使用过程中 Python 包 `nltk`发生了 `Resource punkt not found.`报错,该如何解决?
A3: 方法一https://github.com/nltk/nltk_data/raw/gh-pages/packages/tokenizers/punkt.zip 中的 `packages/tokenizers` 解压,放到 `nltk_data/tokenizers` 存储路径下。
A2: 方法一https://github.com/nltk/nltk_data/raw/gh-pages/packages/tokenizers/punkt.zip 中的 `packages/tokenizers` 解压,放到 `nltk_data/tokenizers` 存储路径下。
`nltk_data` 存储路径可以通过 `nltk.data.path` 查询。
@ -33,9 +21,9 @@ nltk.download()
---
Q4: 使用过程中 Python 包 `nltk`发生了 `Resource averaged_perceptron_tagger not found.`报错,该如何解决?
Q3: 使用过程中 Python 包 `nltk`发生了 `Resource averaged_perceptron_tagger not found.`报错,该如何解决?
A4: 方法一:将 https://github.com/nltk/nltk_data/blob/gh-pages/packages/taggers/averaged_perceptron_tagger.zip 下载,解压放到 `nltk_data/taggers` 存储路径下。
A3: 方法一:将 https://github.com/nltk/nltk_data/blob/gh-pages/packages/taggers/averaged_perceptron_tagger.zip 下载,解压放到 `nltk_data/taggers` 存储路径下。
`nltk_data` 存储路径可以通过 `nltk.data.path` 查询。
@ -48,21 +36,21 @@ nltk.download()
---
Q5: 本项目可否在 colab 中运行?
Q4: 本项目可否在 colab 中运行?
A5: 可以尝试使用 chatglm-6b-int4 模型在 colab 中运行,需要注意的是,如需在 colab 中运行 Web UI需将 `webui.py``demo.queue(concurrency_count=3).launch( server_name='0.0.0.0', share=False, inbrowser=False)`中参数 `share`设置为 `True`
A4: 可以尝试使用 chatglm-6b-int4 模型在 colab 中运行,需要注意的是,如需在 colab 中运行 Web UI需将 `webui.py``demo.queue(concurrency_count=3).launch( server_name='0.0.0.0', share=False, inbrowser=False)`中参数 `share`设置为 `True`
---
Q6: 在 Anaconda 中使用 pip 安装包无效如何解决?
Q5: 在 Anaconda 中使用 pip 安装包无效如何解决?
A6: 此问题是系统环境问题,详细见 [在Anaconda中使用pip安装包无效问题](在Anaconda中使用pip安装包无效问题.md)
A5: 此问题是系统环境问题,详细见 [在Anaconda中使用pip安装包无效问题](在Anaconda中使用pip安装包无效问题.md)
---
Q7: 本项目中所需模型如何下载至本地?
Q6: 本项目中所需模型如何下载至本地?
A7: 本项目中使用的模型均为 `huggingface.com`中可下载的开源模型,以默认选择的 `chatglm-6b``text2vec-large-chinese`模型为例,下载模型可执行如下代码:
A6: 本项目中使用的模型均为 `huggingface.com`中可下载的开源模型,以默认选择的 `chatglm-6b``text2vec-large-chinese`模型为例,下载模型可执行如下代码:
```shell
# 安装 git lfs
@ -80,9 +68,9 @@ $ git pull
---
Q8: `huggingface.com`中模型下载速度较慢怎么办?
Q7: `huggingface.com`中模型下载速度较慢怎么办?
A8: 可使用本项目用到的模型权重文件百度网盘地址:
A7: 可使用本项目用到的模型权重文件百度网盘地址:
- ernie-3.0-base-zh.zip 链接: https://pan.baidu.com/s/1CIvKnD3qzE-orFouA8qvNQ?pwd=4wih
- ernie-3.0-nano-zh.zip 链接: https://pan.baidu.com/s/1Fh8fgzVdavf5P1omAJJ-Zw?pwd=q6s5
@ -93,9 +81,9 @@ A8: 可使用本项目用到的模型权重文件百度网盘地址:
---
Q9: 下载完模型后,如何修改代码以执行本地模型?
Q8: 下载完模型后,如何修改代码以执行本地模型?
A9: 模型下载完成后,请在 [configs/model_config.py](../configs/model_config.py) 文件中,对 `embedding_model_dict``llm_model_dict`参数进行修改,如把 `llm_model_dict`
A8: 模型下载完成后,请在 [configs/model_config.py](../configs/model_config.py) 文件中,对 `embedding_model_dict``llm_model_dict`参数进行修改,如把 `llm_model_dict`
```python
embedding_model_dict = {
@ -117,15 +105,15 @@ embedding_model_dict = {
---
Q10: 执行 `python cli_demo.py`过程中,显卡内存爆了,提示"OutOfMemoryError: CUDA out of memory"
Q9: 执行 `python cli_demo.py`过程中,显卡内存爆了,提示 "OutOfMemoryError: CUDA out of memory"
A10: 将 `VECTOR_SEARCH_TOP_K``LLM_HISTORY_LEN` 的值调低,比如 `VECTOR_SEARCH_TOP_K = 5``LLM_HISTORY_LEN = 2`,这样由 `query``context` 拼接得到的 `prompt` 会变短,会减少内存的占用。或者打开量化,请在 [configs/model_config.py](../configs/model_config.py) 文件中,对`LOAD_IN_8BIT`参数进行修改
A9: 将 `VECTOR_SEARCH_TOP_K``LLM_HISTORY_LEN` 的值调低,比如 `VECTOR_SEARCH_TOP_K = 5``LLM_HISTORY_LEN = 2`,这样由 `query``context` 拼接得到的 `prompt` 会变短,会减少内存的占用。或者打开量化,请在 [configs/model_config.py](../configs/model_config.py) 文件中,对`LOAD_IN_8BIT`参数进行修改
---
Q11: 执行 `pip install -r requirements.txt` 过程中遇到 python 包,如 langchain 找不到对应版本的问题
Q10: 执行 `pip install -r requirements.txt` 过程中遇到 python 包,如 langchain 找不到对应版本的问题
A11: 更换 pypi 源后重新安装,如阿里源、清华源等,网络条件允许时建议直接使用 pypi.org 源,具体操作命令如下:
A10: 更换 pypi 源后重新安装,如阿里源、清华源等,网络条件允许时建议直接使用 pypi.org 源,具体操作命令如下:
```shell
# 使用 pypi 源
@ -146,43 +134,23 @@ $ 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上可用。
Q11: 启动 api.py 时 upload_file 接口抛出 `partially initialized module 'charset_normalizer' has no attribute 'md__mypyc' (most likely due to a circular import)`
A11: 这是由于 charset_normalizer 模块版本过高导致的,需要降低低 charset_normalizer 的版本,测试在 charset_normalizer==2.1.0 上可用。
---
Q13 启动api.py时upload_file接口上传PDF或图片时抛出OSError: [Errno 101] Network is unreachable
Q12: 调用api中的 `bing_search_chat` 接口时,报出 `Failed to establish a new connection: [Errno 110] Connection timed out`
某些情况下,linux系统上的ip在请求下载ch_PP-OCRv3_rec_infer.tar等文件时可能会抛出OSError: [Errno 101] Network is unreachable此时需要首先修改anaconda3/envs/[虚拟环境名]/lib/[python版本]/site-packages/paddleocr/ppocr/utils/network.py脚本将57行的
```
download_with_progressbar(url, tmp_path)
```
修改为:
```
try:
download_with_progressbar(url, tmp_path)
except Exception as e:
print(f"download {url} error,please download it manually:")
print(e)
```
然后按照给定网址,如"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”.
A12: 这是因为服务器加了防火墙需要联系管理员加白名单如果公司的服务器的话就别想了GG--!
---
Q14 调用api中的 `bing_search_chat`接口时,报出 `Failed to establish a new connection: [Errno 110] Connection timed out`
Q13: 加载 chatglm-6b-int8 或 chatglm-6b-int4 抛出 `RuntimeError: Only Tensors of floating point andcomplex dtype can require gradients`
这是因为服务器加了防火墙需要联系管理员加白名单如果公司的服务器的话就别想了GG--!
---
Q15 加载chatglm-6b-int8或chatglm-6b-int4抛出 `RuntimeError: Only Tensors of floating point andcomplex dtype can require gradients`
疑为chatglm的quantization的问题或torch版本差异问题针对已经变为Parameter的torch.zeros矩阵也执行Parameter操作从而抛出 `RuntimeError: Only Tensors of floating point andcomplex dtype can require gradients`。解决办法是在chatglm-项目的原始文件中的quantization.py文件374行改为
A13: 疑为 chatglm 的 quantization 的问题或 torch 版本差异问题,针对已经变为 Parameter 的 torch.zeros 矩阵也执行 Parameter 操作,从而抛出 `RuntimeError: Only Tensors of floating point andcomplex dtype can require gradients`。解决办法是在 chatglm 项目的原始文件中的 quantization.py 文件 374 行改为:
```
try:
@ -199,12 +167,6 @@ Q15 加载chatglm-6b-int8或chatglm-6b-int4抛出 `RuntimeError: Only Tensors of
---
Q16 修改配置中路径后加载text2vec-large-chinese依然提示`WARNING: No sentence-transformers model found with name text2vec-large-chinese. Creating a new one with MEAN pooling.`
Q14: 修改配置中路径后,加载 text2vec-large-chinese 依然提示 `WARNING: No sentence-transformers model found with name text2vec-large-chinese. Creating a new one with MEAN pooling.`
尝试更换embedding如text2vec-base-chinese请在 [configs/model_config.py](../configs/model_config.py) 文件中,修改 `text2vec-base`参数为本地路径,绝对路径或者相对路径均可
---
Q17 启动webui.py时报错 `you need to set ValueError: If you want to offload some keys to cpu or disk, you need to set llm_int8_enable_fp32_cpu_offload=True.`
疑为GPU相关的问题重新启动服务器即可
A14: 尝试更换 embedding如 text2vec-base-chinese请在 [configs/model_config.py](../configs/model_config.py) 文件中,修改 `text2vec-base`参数为本地路径,绝对路径或者相对路径均可

View File

@ -1,76 +0,0 @@
#### 项目启动选项
```test
usage: langchina-ChatGLM [-h] [--no-remote-model] [--model MODEL] [--lora LORA] [--model-dir MODEL_DIR] [--lora-dir LORA_DIR] [--cpu] [--auto-devices] [--gpu-memory GPU_MEMORY [GPU_MEMORY ...]] [--cpu-memory CPU_MEMORY]
[--load-in-8bit] [--bf16]
基于langchain和chatGML的LLM文档阅读器
options:
-h, --help show this help message and exit
--no-remote-model remote in the model on loader checkpoint, if your load local model to add the ` --no-remote-model`
--model MODEL Name of the model to load by default.
--lora LORA Name of the LoRA to apply to the model by default.
--model-dir MODEL_DIR
Path to directory with all the models
--lora-dir LORA_DIR Path to directory with all the loras
--cpu Use the CPU to generate text. Warning: Training on CPU is extremely slow.
--auto-devices Automatically split the model across the available GPU(s) and CPU.
--gpu-memory GPU_MEMORY [GPU_MEMORY ...]
Maxmimum GPU memory in GiB to be allocated per GPU. Example: --gpu-memory 10 for a single GPU, --gpu-memory 10 5 for two GPUs. You can also set values in MiB like --gpu-memory 3500MiB.
--cpu-memory CPU_MEMORY
Maximum CPU memory in GiB to allocate for offloaded weights. Same as above.
--load-in-8bit Load the model with 8-bit precision.
--bf16 Load the model with bfloat16 precision. Requires NVIDIA Ampere GPU.
```
#### 示例
- 1、加载本地模型
```text
--model-dir 本地checkpoint存放文件夹
--model 模型名称
--no-remote-model 不从远程加载模型
```
```shell
$ python cli_demo.py --model-dir /media/mnt/ --model chatglm-6b --no-remote-model
```
- 2、低精度加载模型
```text
--model-dir 本地checkpoint存放文件夹
--model 模型名称
--no-remote-model 不从远程加载模型
--load-in-8bit 以8位精度加载模型
```
```shell
$ python cli_demo.py --model-dir /media/mnt/ --model chatglm-6b --no-remote-model --load-in-8bit
```
- 3、使用cpu预测模型
```text
--model-dir 本地checkpoint存放文件夹
--model 模型名称
--no-remote-model 不从远程加载模型
--cpu 使用CPU生成文本。警告CPU上的训练非常缓慢。
```
```shell
$ python cli_demo.py --model-dir /media/mnt/ --model chatglm-6b --no-remote-model --cpu
```
- 3、加载lora微调文件
```text
--model-dir 本地checkpoint存放文件夹
--model 模型名称
--no-remote-model 不从远程加载模型
--lora-dir 本地lora存放文件夹
--lora lora名称
```
```shell
$ python cli_demo.py --model-dir /media/mnt/ --model chatglm-6b --no-remote-model --lora-dir /media/mnt/loras --lora chatglm-step100
```

View File

@ -1,49 +0,0 @@
## 命令行工具
windows cli.bat
linux cli.sh
## 命令列表
### llm 管理
llm 支持列表
```shell
cli.bat llm ls
```
### embedding 管理
embedding 支持列表
```shell
cli.bat embedding ls
```
### start 启动管理
查看启动选择
```shell
cli.bat start
```
启动命令行交互
```shell
cli.bat start cli
```
启动Web 交互
```shell
cli.bat start webui
```
启动api服务
```shell
cli.bat start api
```

View File

@ -1,24 +0,0 @@
# fastchat 调用实现教程
langchain-ChatGLM 现已支持通过调用 FastChat API 进行 LLM 调用,支持的 API 形式为 **OpenAI API 形式**
1. 首先请参考 [FastChat 官方文档](https://github.com/lm-sys/FastChat/blob/main/docs/openai_api.md#restful-api-server) 进行 FastChat OpenAI 形式 API 部署
2. 依据 FastChat API 启用时的 `model_name``api_base` 链接,在本项目的 `configs/model_config.py``llm_model_dict` 中增加选项。如:
```python
llm_model_dict = {
# 通过 fastchat 调用的模型请参考如下格式
"fastchat-chatglm-6b": {
"name": "chatglm-6b", # "name"修改为fastchat服务中的"model_name"
"pretrained_model_name": "chatglm-6b",
"local_model_path": None,
"provides": "FastChatOpenAILLM", # 使用fastchat api时需保证"provides"为"FastChatOpenAILLM"
"api_base_url": "http://localhost:8000/v1" # "name"修改为fastchat服务中的"api_base_url"
},
}
```
其中 `api_base_url` 根据 FastChat 部署时的 ip 地址和端口号得到,如 ip 地址设置为 `localhost`,端口号为 `8000`,则应设置的 `api_base_url``http://localhost:8000/v1`
3. 将 `configs/model_config.py` 中的 `LLM_MODEL` 修改为对应模型名。如:
```python
LLM_MODEL = "fastchat-chatglm-6b"
```
4. 根据需求运行 `api.py`, `cli_demo.py``webui.py`

View File

@ -1,6 +1,6 @@
向量库环境docker-compose.yml文件在docs/docker/vector_db中
向量库环境 docker-compose.yml 文件在 docs/docker/vector_db
以milvus为例
milvus 为例
```shell
cd docs/docker/vector_db/milvus
docker-compose up -d