Ascend-SACT/AIGC_txt_detect_infer
模型介绍文件和版本Pull Requests讨论分析
下载使用量0

AI生成文本检测模型-推理

仓库提供对AI生成的文本进行检测的两个模型的推理。

模型与镜像

模型

  • 检测英文模型: roberta_18plus, 权重下载
  • 检测中文模型:bert_18plus, 权重下载

镜像

  • 910A推理镜像
    • 版本配套:EulerOS 2.0 + CANN6.0.RC1 + MindSpore1.9.0
    • 获取镜像
      • 拉取镜像: swr.cn-southwest-2.myhuaweicloud.com/tomy/deploy-detectgpt:v0.3.2
      • zip下载
  • 910B推理镜像
    • 版本配套:Ubuntu22.04.4TLS + CANN8.0.RC3 + MindSpore2.4.0
    • 获取镜像
      • 拉取镜像: swr.cn-southwest-2.myhuaweicloud.com/tomy/deploy-detectgpt:910b_1.0
      • zip下载
  • 310P推理镜像
    • 版本配套:Ubuntu22.04.4TLS + CANN8.0.RC3 + MindSpore2.4.0
    • 获取镜像
      • 拉取镜像: swr.cn-southwest-2.myhuaweicloud.com/tomy/deploy-detectgpt:310p_1.0
      • zip下载

注:拉取镜像需要先获得镜像仓库权限

快速体验

部署

启动

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

服务化接口测试

接口

  • 服务健康检查:/health GET
  • 文本检测推理:/detecttext POST
    • 英文
      • 输入 {"lang": "en","text":"hello..."}
      • 返回
        {
            "code": 200,
            "msg": "inference successs",
            "machine_written": false
        }
    • 中文输入
      • {"lang": "zh","text":"你好..."}
      • 返回
        {
            "code": 200,
            "msg": "inference successs",
            "machine_written": false
        }

本地Curl调用API

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 API

如果部署到华为云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

开发调测

模型训练

参考 AIGC_text_detector

权重转换

本仓库代码需将 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方式启动推理服务,仅支持单进程