# GNMT ## 论文 https://arxiv.org/abs/1609.08144 ## 环境配置 ### Docker 拉取镜像,启动并进入容器 ``` dockerfile docker pull image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10 docker run -it --shm-size 80g --network=host --name=nmt --privileged --device /dev/m--device=/dev/kfd --device=/dev/dri --group-add video --cap-add=SYS_PTRACE --security-opt seccomp=unconfined -v /opt/hyhal/:/opt/hyhal/:ro image.sourcefind.cn:5000/dcu/admin/base/pytorch:2.1.0-ubuntu20.04-dtk24.04.1-py3.10 /bin/bash ``` ### 拉取代码仓 ``` http://developer.hpccube.com/codes/ACzhangchao/gnmt.git ``` ### Conda(推荐) 创建虚拟环境 ``` bash Anaconda3-2024.02-1-Linux-x86_64.sh source ~/.bashrc conda create -n gnmt python=3.7 # 此处选择py3.7是为了能够和tensorflow1.15兼容 conda activate gnmt ``` 安装tensorflow ``` unset PYTHONPATH pip install tensorflow-1.15.1+git06e2e8aa.dtk2404-cp37-cp37m-linux_x86_64.whl ``` ### 数据集准备 ``` cd nmt/nmt/scripts bash download_iwslt15.sh /tmp/nmt_data mkdir /tmp/nmt_model ``` ## 基础NMT模型 ### 单卡训练 ``` cd /nmt/nmt bash run_single.sh ``` ### 多卡训练 ``` bash run_multi.sh ``` ### 模型推理 ```python cat > /tmp/my_infer_file.vi # (从/tmp/nmt_data/tst2013.vi中复制并粘贴一些句子) python -m nmt.nmt \ --out_dir=/tmp/nmt_model \ --inference_input_file=/tmp/my_infer_file.vi \ --inference_output_file=/tmp/nmt_model/output_infer cat /tmp/nmt_model/output_infer # 查看推理结果 ``` ## 基于注意力机制的NMT模型 ### 单卡训练 ``` bash run_single_nmt.sh ``` ### 多卡训练 ``` bash run_multi_nmt.sh ``` ### 模型推理 ```python # 使用相同的推断命令,只需使用新的out_dir进行推断: python -m nmt.nmt \ --out_dir=/tmp/nmt_attention_model \ --inference_input_file=/tmp/my_infer_file.vi \ --inference_output_file=/tmp/nmt_attention_model/output_infer ``` ## 源码仓库及问题反馈 ``` https://github.com/tensorflow/nmt/tree/master ```