Skip to content

Commit 496c4cd

Browse files
authored
Transformer full procedure ci/ce (#839)
1 parent 0d9f117 commit 496c4cd

File tree

15 files changed

+220
-38
lines changed

15 files changed

+220
-38
lines changed

examples/machine_translation/transformer/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ python train.py --config ./configs/transformer.base.yaml
7777
同样,可以执行如下命令实现八卡训练:
7878

7979
``` sh
80-
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
80+
unset CUDA_VISIBLE_DEVICES
8181
python -m paddle.distributed.launch --gpus "0,1,2,3,4,5,6,7" train.py --config ./configs/transformer.base.yaml
8282
```
8383

@@ -154,7 +154,7 @@ python train.py --config ../configs/transformer.base.yaml
154154
##### fleet 的方式启动单机多卡:
155155
``` shell
156156
cd static/
157-
export CUDA_VISIBLE_DEVICES=0,1,2,3,4,5,6,7
157+
unset CUDA_VISIBLE_DEVICES
158158
python -m paddle.distributed.launch --gpus="0,1,2,3,4,5,6,7" train.py --config ../configs/transformer.base.yaml --distributed
159159
```
160160

examples/machine_translation/transformer/deploy/python/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ python inference.py \
3232
* `--config`: yaml 配置文件,和训练时使用的相同,不过因为模型导出时已经固定了模型结构,因此,模型超参相关配置将不会再起作用,仅有 `reader` 相关配置、`infer_batch_size` 以及 `inference_model_dir` 仍会有效。
3333
* `--batch_size`: 与配置文件中 `infer_batch_size` 意义相同,是指的使用 Paddle Inference 的时候一个 batch 的句子数目。
3434
* `--device`: 使用的设备,可以是 gpu,xpu 或是 cpu。
35-
* `--use_mkl`: 是否使用 mkl,没有设定表示不使用 mkl。
35+
* `--use_mkl`: 是否使用 mkl,没有设定表示不使用 mkl。可以通过 `--use_mkl True` 指定。
3636
* `--threads`: 仅在使用 mkl 的时候起效,用于指定计算 math 库时的线程数。
3737
* `--model_dir`: 导出的 Paddle Inference 可用的模型路径,与配置文件中的 `inference_model_dir` 对应。
3838

examples/machine_translation/transformer/deploy/python/benchmark.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ for batch_size in "1" "2" "4"; do
1717
--config="../../configs/transformer.${model}.yaml" \
1818
--model_dir=${model_dir} \
1919
--device cpu \
20-
--use_mkl \
20+
--use_mkl True \
2121
--threads=${threads} \
2222
--batch_size=${batch_size} \
2323
--profile > ${log_path}/transformer_${model}_cpu_mkl_threads${threads}_bs${batch_size}_inference.log 2>&1

examples/machine_translation/transformer/deploy/python/inference.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ def parse_args():
3333
choices=["gpu", "xpu", "cpu"],
3434
help="Device to use during inference. ")
3535
parser.add_argument(
36-
"--use_mkl", action="store_true", help="Whether to use mkl. ")
36+
"--use_mkl",
37+
default=False,
38+
type=eval,
39+
choices=[True, False],
40+
help="Whether to use mkl. ")
3741
parser.add_argument(
3842
"--threads",
3943
default=1,
@@ -50,6 +54,7 @@ def parse_args():
5054
"--profile", action="store_true", help="Whether to profile. ")
5155
parser.add_argument(
5256
"--test_file",
57+
nargs='+',
5358
default=None,
5459
type=str,
5560
help="The file for testing. Normally, it shouldn't be set and in this case, the default WMT14 dataset will be used to process testing."

examples/machine_translation/transformer/faster_transformer/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ cd PaddleNLP/paddlenlp/ops/
213213
``` sh
214214
mkdir build
215215
cd build/
216-
cmake .. -DSM=xx -DCMAKE_BUILD_TYPE=Release -DPADDLE_LIB=/path/to/paddle_inference_lib/ -DDEMO=./demo/transformer_e2e.cc -DWITH_STATIC_LIB=OFF -DON_INFER=ON
216+
cmake .. -DSM=xx -DCMAKE_BUILD_TYPE=Release -DPADDLE_LIB=/path/to/paddle_inference_lib/ -DDEMO=./demo/transformer_e2e.cc -DWITH_STATIC_LIB=OFF -DON_INFER=ON -DWITH_MKL=ON
217217
make -j
218218
cd ../
219219
```
@@ -233,7 +233,7 @@ cd ../
233233
└── threadpool/
234234
└── version.txt
235235
```
236-
* `-DDEMO` 说明预测库使用 demo 的位置。
236+
* `-DDEMO` 说明预测库使用 demo 的位置。最好使用绝对路径,若使用相对路径,需要是相对于 `PaddleNLP/paddlenlp/ops/faster_transformer/src/` 的相对路径。
237237
* **当使用预测库的自定义 op 的时候,请务必开启 `-DON_INFER=ON` 选项,否则,不会得到预测库的可执行文件。**
238238

239239
编译完成后,在 `build/bin/` 路径下将会看到 `transformer_e2e` 的一个可执行文件。通过设置对应的设置参数完成执行的过程。

examples/machine_translation/transformer/faster_transformer/encoder_decoding_predict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ def parse_args():
6464
help="Whether to profile the performance using newstest2014 dataset. ")
6565
parser.add_argument(
6666
"--test_file",
67+
nargs='+',
6768
default=None,
6869
type=str,
6970
help="The file for testing. Normally, it shouldn't be set and in this case, the default WMT14 dataset will be used to process testing."

examples/machine_translation/transformer/predict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def parse_args():
2626
)
2727
parser.add_argument(
2828
"--test_file",
29+
nargs='+',
2930
default=None,
3031
type=str,
3132
help="The file for testing. Normally, it shouldn't be set and in this case, the default WMT14 dataset will be used to process testing."

examples/machine_translation/transformer/static/predict.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def parse_args():
4646
)
4747
parser.add_argument(
4848
"--test_file",
49+
nargs='+',
4950
default=None,
5051
type=str,
5152
help="The file for testing. Normally, it shouldn't be set and in this case, the default WMT14 dataset will be used to process testing."

examples/machine_translation/transformer/train.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ def do_train(args):
140140
batch_id = 0
141141
batch_start = time.time()
142142
for input_data in train_loader:
143-
#NOTE: Used for benchmark and use None as default.
144-
if args.max_iter and step_idx == args.max_iter:
145-
break
146143
train_reader_cost = time.time() - batch_start
147144
(src_word, trg_word, lbl_word) = input_data
148145

@@ -237,6 +234,9 @@ def do_train(args):
237234
paddle.save(optimizer.state_dict(),
238235
os.path.join(model_dir, "transformer.pdopt"))
239236

237+
#NOTE: Used for benchmark and use None as default.
238+
if args.max_iter and step_idx == args.max_iter:
239+
break
240240
batch_id += 1
241241
step_idx += 1
242242
scheduler.step()

paddlenlp/ops/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ cd PaddleNLP/paddlenlp/ops/
206206
``` sh
207207
mkdir build
208208
cd build/
209-
cmake .. -DSM=xx -DCMAKE_BUILD_TYPE=Release -DPADDLE_LIB=/path/to/paddle_inference_lib/ -DDEMO=./faster_transformer/src/demo/transformer_e2e.cc -DWITH_STATIC_LIB=OFF -DON_INFER=ON -DWITH_MKL=ON
209+
cmake .. -DSM=xx -DCMAKE_BUILD_TYPE=Release -DPADDLE_LIB=/path/to/paddle_inference_lib/ -DDEMO=./demo/transformer_e2e.cc -DWITH_STATIC_LIB=OFF -DON_INFER=ON -DWITH_MKL=ON
210210
make -j
211211
cd ../
212212
```
@@ -226,7 +226,7 @@ cd ../
226226
└── threadpool/
227227
└── version.txt
228228
```
229-
* `-DDEMO` 说明预测库使用 demo 的位置。比如指定 -DDEMO=./faster_transformer/src/demo/transformer_e2e.cc 或是 -DDEMO=./faster_transformer/src/demo/gpt.cc。
229+
* `-DDEMO` 说明预测库使用 demo 的位置。比如指定 -DDEMO=./demo/transformer_e2e.cc 或是 -DDEMO=./demo/gpt.cc。最好使用绝对路径,若使用相对路径,需要是相对于 `PaddleNLP/paddlenlp/ops/faster_transformer/src/` 的相对路径
230230
* `-DWITH_GPT`,如果是编译 GPT 的预测库可执行文件,需要加上 `-DWITH_GPT=ON`
231231
* **当使用预测库的自定义 op 的时候,请务必开启 `-DON_INFER=ON` 选项,否则,不会得到预测库的可执行文件。**
232232

0 commit comments

Comments
 (0)