仓库提供对AI生成的文本进行检测的两个模型的推理。
swr.cn-southwest-2.myhuaweicloud.com/tomy/deploy-detectgpt:v0.3.2swr.cn-southwest-2.myhuaweicloud.com/tomy/deploy-detectgpt:910b_1.0swr.cn-southwest-2.myhuaweicloud.com/tomy/deploy-detectgpt:310p_1.0注:拉取镜像需要先获得镜像仓库权限
启动
docker pull swr.cn-southwest-2.myhuaweicloud.com/tomy/deploy-detectgpt:910b_1.0
docker stop detectgpt && docker rm detectgpt
docker run -itd -u 0 --ipc=host --network host \
--name detectgpt \
--privileged \
--device=/dev/davinci_manager \
--device=/dev/devmm_svm \
--device=/dev/hisi_hdc \
-v /usr/local/sbin/:/usr/local/sbin/ \
-v /usr/local/Ascend/driver:/usr/local/Ascend/driver \
swr.cn-southwest-2.myhuaweicloud.com/tomy/deploy-detectgpt:910b_1.0 查看日志
docker logs -f detectgpt接口
{"lang": "en","text":"hello..."}{
"code": 200,
"msg": "inference successs",
"machine_written": false
}{"lang": "zh","text":"你好..."}{
"code": 200,
"msg": "inference successs",
"machine_written": false
}curl -X GET 127.0.0.1:8080/health
curl -X POST -H "Content-Type: application/json" --data '{"lang": "en","text":"They are not colored . Just as white paint is usually made from minerals found in clay . The crystals in white paint"}' 127.0.0.1:8080/detecttext
curl -X POST -H "Content-Type: application/json" --data '{"lang": "zh","text":"程序流程图又称程序框图,是用统一规定的标准符号描述程序运行具体步骤的图形表示。"}' 127.0.0.1:8080/detecttext如果部署到华为云ModelArts上,参考以下步骤调用服务。
1、 先获取华为云IAM的token
curl -ik -X POST -H 'Content-Type=application/json;charset=utf8' -d '{"auth":{"identity":{"methods":["password"],"password":{"user":{"domain":{"name":"IAM用户所属账号名"},"name":"IAM用户名","password":"IAM用户密码"}}},"scope":{"project":{"name":"项目名称"}}}}' https://iam.cn-southwest-2.myhuaweicloud.com/v3/auth/tokens响应Header参数X-Subject-Token为获取到的Token, 详细参考:https://support.huaweicloud.com/api-iam/iam_30_0001.html
2、用获取到的IAM token鉴权调用ModelArts API
curl -kv -d '{"lang": "en","text":"They are not colored . Just as white paint is usually made from minerals found in clay . The crystals in white paint"}' -H 'X-Auth-Token:MIIOcgYJKoZI...(IAM token)' -H 'Content-type: application/json' -X POST https://ModelArts API的地址/detecttext如
curl -kv -d '{"lang": "en","text":"They are not colored . Just as white paint is usually made from minerals found in clay . The crystals in white paint"}' -H 'X-Auth-Token:MIIOcgYJKoZI...(IAM token)' -H 'Content-type: application/json' -X POST https://infer-modelarts-cn-southwest-2.myhuaweicloud.com/v1/infers/545fd95a-5e6d-4d21-812d-97825e4338d1/detecttext详细参考: https://support.huaweicloud.com/usermanual-standard-modelarts/inference-modelarts-0023.html
本仓库代码需将 safetensors 或 pytorch的bin 权重格式转换为 mindspore的ckpt格式。 权重转换代码参考 ckpt_convert_pt2ms.py
使用方法如下
cd detectGPT
python ckpt_convert_pt2ms.py --pt_path pytorch权重路径将 ckpt 目录某个版本的全部文件都复制到 detectGPT\examples\detect_chatgpt 目录下,使用detectGPT目录下文件进行测试调测:
* class_txt.py # 代码方式推理中英文
* class_en.py # 代码方式推理英文
* class_zh.py # 代码方式推理中文
* detect_aigc_txt.ipynb # notebook 方式推理中英文
* service.py # gunicorn方式启动推理服务,支持多进程
* service_flask.py # flask方式启动推理服务,仅支持单进程