XXX has been blocked by CORS policy: The request client is not a secure context and the resource is in more-private address space private

处理方法:

1.在google浏览器地址栏输入chrome://flags/#block-insecure-private-network-requests回车,并设置block-insecure-private-network-requests为“disabled”,重启浏览器。
2.检查调用资源的域名DNS是否为内网地址,添加本地解析。

chromium启动报如下错误:
[W:pyppeteer.chromium_downloader] chromium extracted to: /root/.local/share/pyppeteer/local-chromium/494755
LaunchProcess: failed to execvp:
/root/.local/share/pyppeteer/local-chromium/494755/chrome-linux/nacl_helper
[62381:62381:0612/152237.227605:ERROR:nacl_fork_delegate_linux.cc(315)] Bad NaCl helper startup ack (0 bytes)

(chrome:62378): Gtk-WARNING **: 15:22:37.231: cannot open display:

经过网上查询驱动、chromium版本、使用--no-sandbox参数、创建非root用户启动等都无效,修改headless参数为true。

出现的问题:mp4视频在Chrome正常播放,但是Safari无法播放。

可能的原因:1.mp4视频编码问题,Safari上可播放的mp4视频编码最好是H.264,音频AAC编码。

                    2.服务器响应头缺失

测试环境:Nginx/1.13.5

解决办法:

1.视频编码的问题,使用ffmpeg进行转码

    ffmpeg -i 源视频.mp4 -c copy 转码视频名称.mp4

2.经测试得知Mac和IOS播放mp4视频文件服务器响应头必须包括Content-Range和Content-Length,其他的Content-Type: "video/mp4"、Accept-Ranges: bytes响应头可有可无。

3.其中如果开启了gzip on配置可能导致Content-Length无法获取,进而Content-Range无法正常返回。可将gzip配置关闭或者压缩类型中去掉video/mp4类型。

4.另外其他网上方法添加响应头add_header Accept-Ranges bytes;和chunked_transfer_encoding off;配置,测试了没有效果。


系统环境:CentOS 7

  1. 安装openssl 1.1.1+版本,使用下载器要求openssl1.1.1+版本

  2. 安装Python3环境,使用openssl 1.1.1+编译安装

./configure --prefix=安装目录 --with-openssl=/path/of/openssl

   3.python3安装requests、huggingface_hub模块

pip3 install requests

pip3 install huggingface_hub

   4.下载脚本

wget https://aliendao.cn/model_download.py

   5.以https://aliendao.cn/models/THUDM/chatglm2-6b为例

python3 model_download.py --repo_id THUDM/chatglm2-6b --mirror


一、克隆项目到本地

项目地址:

git clone https://github.com/THUDM/ChatGLM2-6B.git
cd ChatGLM2-6B
pip install -r requirements.txt


二、下载模型

模型下载地址:

https://huggingface.co/THUDM/chatglm2-6b/tree/main

模型中几个较大的文件可以通过云盘下载:

清华云盘地址 https://cloud.tsinghua.edu.cn/d/674208019e314311ab5c/

阿里云盘地址 https://www.aliyundrive.com/s/G7j8vZmZG5C/folder/649d4dd40731a785e362486595c62b50f56cc120


量化模型下载地址:

https://huggingface.co/THUDM/chatglm2-6b-int4/tree/main


使用CPU运行可以下载量化模型

下载所有文件后放到ChatGLM2-6B/THUDM/chatglm2-6b-int4/文件夹下,然后修改web_demo.py:

tokenizer = AutoTokenizer.from_pretrained("C:\\ChatGLM2-6B\\THUDM\\chatglm2-6b-int4", trust_remote_code=True)

model = AutoModel.from_pretrained("C:\ChatGLM2-6B\THUDM\chatglm2-6b-int4", trust_remote_code=True).float()

三、windows系统使用量化后的模型还需要安装gcc环境

下载tdm-gcc-10.3.0.exe
下载地址 
安装时勾选openmp

四、运行

python web_demo.py

   

错误处理方式如下:

错误1.ModuleNotFoundError: No module named 'transformers_modules.THUDM/chatglm2-6b

问题原因:
transformers==4.30.2版本原因,卸载后安装低一点的版本
解决方法:
1.卸载transformers
pip uninstall transformers
2.安装低版本transformers
pip install transformers==4.26.0

错误2.RuntimeError: Internal: D:\a\sentencepiece\sentencepiece\src\sentencepiece_processor.cc(1102) [model_proto->ParseFromArray(serialized.data(), serialized.size())]

问题原因:模型配置文件等下载不全
解决方法:重新下载tokenizer.model

错误3.AssertionError: Torch not compiled with CUDA enabled

问题原因:没有GPU或没有安装CUDA-Toolkit驱动
解决方法:
方法1.安装CUDA-Toolkit驱动
方法2.使用CPU运行,修改web_demo.py中AutoModel.from_pretrained("C:\ChatGLM2-6B\THUDM\chatglm2-6b", trust_remote_code=True).cuda()
改为AutoModel.from_pretrained("C:\ChatGLM2-6B\THUDM\chatglm2-6b", trust_remote_code=True).float()