README.md 2 KB
Newer Older
ACzhangchao's avatar
ACzhangchao committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# 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
```

### 拉取代码仓

```
git clone https://github.com/tensorflow/nmt.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
```