快速体验
环境准备
获取代码
- 远程登录开发者套件,进入“/usr/local”目录运行脚本拉取代码。
cd /usr/local
- 运行脚本拉取代码。
bash E2E_samples_download_tool.sh -d download_destination_path -s source_repository -b branch target_path
参数说明:- -d:指定代码的下载路径。
- -s:指定开源仓库的clone url。
- -b:指定开源仓库分支名称及待下载的项目目录。
- -f:强制更新下载路径中的目录。当样例目录已删除,但重新下载时提示“Already up to date”时可使用此参数。
命令示例:
bash E2E_samples_download_tool.sh -d /home/HwHiAiUser/E2ESamples -s https://gitee.com/HUAWEI-ASCEND/ascend-devkit.git -b master src/E2E-Sample/ChatBot/
回显如下:
Download E2E samples successfully!
执行完成后,会在“/home/HwHiAiUser/E2Esamples”目录下生成“src/E2E-Sample/ChatBot/”目录。
- 准备文件。
- 单击链接下载chatbot前端相关文件,将解压后目录中文件上传至服务器“/home/HwHiAiUser/E2ESamples/src/E2E-Sample/ChatBot/Demo_V1/dist_chatbot_standalone”目录下。
- 单击链接下载模型文件并解压,将解压后目录中文件上传至服务器“/home/HwHiAiUser/E2ESamples/src/E2E-Sample/ChatBot/Demo_V1/models”目录下。
- 单击链接下载chabot配置文件并解压,将解压后目录中的文件上传至服务器“/home/HwHiAiUser/E2ESamples/src/E2E-Sample/ChatBot/Demo_V1/tokenizer_file”目录下
- 进入智能ChatBot代码目录。
cd /home/HwHiAiUser/E2ESamples/src/E2E-Sample/ChatBot/Demo_V1
智能ChatBot应用工程目录文件详细介绍请参见代码实现。
- 安装依赖。
pip3 install -r requirements.txt
关闭OOM Killer与图形桌面
使用swap分区时如果开启了OOM Killer,内存将会在占用3.01G时进行swap分区交换,此时ChatBot的推理预热将会失效。请参见以下步骤关闭OOM Killer
- 执行以下命令关闭OOM Killer服务。
- 分别将/root/.bashrc与/home/HwHiAiUser/.bashrc文件中代码注释。
- 打开/root/.bashrc文件。
vi /root/.bashrc
- 打开/home/HwHiAiUser/.bashrc
vi /home/HwHiAiUser/.bashrc
注释以下代码:
echo $$ > /sys/fs/cgroup/memory/usermemory.tasks
- 打开/root/.bashrc文件。
- 执行以下命令关闭图形桌面。
systemctl disable toggle_graphical_desktop
- 执行命令重启开发者套件。
reboot
运行智能ChatBot应用
- 进入智能ChatBot应用工程目录。
cd /home/HwHiAiUser/E2ESamples/src/E2E-Sample/ChatBot/Demo_V1
- 清除缓存并运行推理进程脚本。
free -h && sudo sysctl -w vm.drop_caches=3 && sudo sync && echo 3 | sudo tee /proc/sys/vm/drop_caches && free -h
在当前窗口执行命令运行推理进程脚本。
python3 generate.py
回显如下:
[INFO] acl init success [INFO] open device 0 success [INFO] load model ./models/encoder.om success [INFO] create model description success [INFO]The encoder has been initialized. Initializing the first decoder in progress. 2023-08-22 09:55:55.884550298 [E:onnxruntime:Default, env.cc:251 ThreadMain] pthread_setaffinity_np failed for thread: 55417, index: 2, mask: {3, }, error code: 22 error msg: Invalid argument. Specify the number of threads explicitly so the affinity is not set. [INFO]The first decoder has been initialized. Initializing the second decoder in progress. 2023-08-22 09:56:03.641827137 [E:onnxruntime:Default, env.cc:251 ThreadMain] pthread_setaffinity_np failed for thread: 55422, index: 2, mask: {3, }, error code: 22 error msg: Invalid argument. Specify the number of threads explicitly so the affinity is not set. [INFO]init finished [INFO]ChatBot Ready
- 重新打开远程链接窗口,进入对应目录运行智能ChatBot应用。
cd /home/HwHiAiUser/E2ESamples/src/E2E-Sample/ChatBot/Demo_V1 python3 main.py
回显如下:
* Serving Flask app 'main' * Debug mode: off WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead. * Running on all addresses (0.0.0.0) * Running on http://127.0.0.1:5000 * Running on http://192.168.137.100:5000
- 在计算机中打开Chrome浏览器,输入3回显中加粗部分的URL地址进入页面,即可实现与聊天机器人进行对话。