Skip to content

Commit 7d2f50e

Browse files
authored
Refine cpp demo flags vocab_dir to vocab_file (#1150)
1 parent 0f2d8a6 commit 7d2f50e

File tree

7 files changed

+36
-36
lines changed

7 files changed

+36
-36
lines changed

docs/advanced_guide/fastertransformer.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,7 @@ PaddleNLP 准备
292292
.. code-block::
293293
294294
cd bin/
295-
./transformer_e2e -batch_size <batch_size> -gpu_id <gpu_id> -model_dir <model_directory> -vocab_dir <dict_directory> -data_dir <input_data>
295+
./transformer_e2e -batch_size <batch_size> -gpu_id <gpu_id> -model_dir <model_directory> -vocab_file <dict_file> -data_file <input_data>
296296
297297
举例说明:
298298

@@ -301,7 +301,7 @@ PaddleNLP 准备
301301
cd bin/
302302
# 执行 decoding_gemm 目的是基于当前环境、配置,提前确定一个性能最佳的矩阵乘算法,不是必要的步骤
303303
../third-party/build/fastertransformer/bin/decoding_gemm 8 5 8 64 38512 256 512 0
304-
./transformer_e2e -batch_size 8 -gpu_id 0 -model_dir ./infer_model/ -vocab_dir DATA_HOME/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/vocab_all.bpe.33708 -data_dir DATA_HOME/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/newstest2014.tok.bpe.33708.en
304+
./transformer_e2e -batch_size 8 -gpu_id 0 -model_dir ./infer_model/ -vocab_file DATA_HOME/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/vocab_all.bpe.33708 -data_file DATA_HOME/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/newstest2014.tok.bpe.33708.en
305305
306306
其中:
307307

@@ -344,4 +344,4 @@ PaddleNLP 准备
344344
.. code-block::
345345
346346
cd bin/
347-
./gpt -batch_size 1 -gpu_id 0 -model_dir path/to/model -vocab_dir path/to/vocab -start_token "<|endoftext|>" -end_token "<|endoftext|>"
347+
./gpt -batch_size 1 -gpu_id 0 -model_dir path/to/model -vocab_file path/to/vocab -start_token "<|endoftext|>" -end_token "<|endoftext|>"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ bash run.sh
6262

6363
``` sh
6464
export CUDA_VISIBLE_DEVICES=0
65-
./build/bin/transformer_e2e -batch_size 8 -device gpu -gpu_id 0 -model_dir ./infer_model/ -vocab_dir /root/.paddlenlp/datasets/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/vocab_all.bpe.33708 -data_dir /root/.paddlenlp/datasets/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/newstest2014.tok.bpe.33708.en
65+
./build/bin/transformer_e2e -batch_size 8 -device gpu -gpu_id 0 -model_dir ./infer_model/ -vocab_file /root/.paddlenlp/datasets/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/vocab_all.bpe.33708 -data_file /root/.paddlenlp/datasets/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/newstest2014.tok.bpe.33708.en
6666
```
6767

6868
各个参数解释如下:
@@ -72,8 +72,8 @@ export CUDA_VISIBLE_DEVICES=0
7272
* `-use_mkl`: 是否使用 mkl,设置代表使用 mkl,不设置则不使用 mkl。仅在使用 cpu 进行预测的时候有效。
7373
* `-threads`: 仅在使用 mkl 的时候起效,用于指定计算 math 库时的线程数。
7474
* `-model_dir`: 导出的模型的位置。
75-
* `-vocab_dir`: 词表的位置
76-
* `-data_dir`: 推理用的数据的位置。
75+
* `-vocab_file`: 词表文件的位置
76+
* `-data_file`: 推理用的数据的位置。
7777

7878
英德翻译的结果会保存到 `predict.txt` 文件中。
7979

examples/machine_translation/transformer/deploy/cpp/run_impl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ cmake .. -DPADDLE_LIB=${LIB_DIR} \
3030

3131
make -j
3232

33-
./${DEMO_NAME} -batch_size 8 -device ${DEVICE} -gpu_id 0 -model_dir ${MODEL_FILE_DIR} -vocab_dir ${VOCAB_DIR} -data_dir ${DATA_DIR}
33+
./${DEMO_NAME} -batch_size 8 -device ${DEVICE} -gpu_id 0 -model_dir ${MODEL_FILE_DIR} -vocab_file ${VOCAB_DIR} -data_file ${DATA_DIR}

examples/machine_translation/transformer/deploy/cpp/transformer_e2e.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ DEFINE_int32(threads,
3030
DEFINE_string(model_dir,
3131
"./infer_model/",
3232
"The directory to the inference model. ");
33-
DEFINE_string(vocab_dir,
33+
DEFINE_string(vocab_file,
3434
"./vocab_all.bpe.33708",
35-
"The directory to the vocabulary file. ");
36-
DEFINE_string(data_dir,
35+
"The path to the vocabulary file. ");
36+
DEFINE_string(data_file,
3737
"./newstest2014.tok.bpe.33708.en",
38-
"The directory to the input data. ");
38+
"The path to the input data file. ");
3939

4040
using namespace paddle_infer;
4141

4242
std::string model_dir = "";
43-
std::string vocab_dir = "";
44-
std::string data_dir = "";
43+
std::string vocab_file = "";
44+
std::string data_file = "";
4545

4646
const int EOS_IDX = 1;
4747
const int PAD_IDX = 0;
@@ -140,7 +140,7 @@ class DataReader {
140140
}
141141

142142
bool GetWordDict() {
143-
std::ifstream fin(vocab_dir);
143+
std::ifstream fin(vocab_file);
144144
std::string line;
145145
int k = 0;
146146
while (std::getline(fin, line)) {
@@ -239,7 +239,7 @@ void Main(
239239
// can turn off the IR optimization for same results as following:
240240
// config.SwitchIrOptim(false);
241241
auto predictor = CreatePredictor(config);
242-
DataReader reader(data_dir);
242+
DataReader reader(data_file);
243243
reader.GetWordDict();
244244

245245
double whole_time = 0;
@@ -281,8 +281,8 @@ int main(int argc, char** argv) {
281281
gpu_id = FLAGS_gpu_id;
282282

283283
model_dir = FLAGS_model_dir;
284-
vocab_dir = FLAGS_vocab_dir;
285-
data_dir = FLAGS_data_dir;
284+
vocab_file = FLAGS_vocab_file;
285+
data_file = FLAGS_data_file;
286286

287287
paddle::inference::Main(
288288
batch_size, FLAGS_device, gpu_id, FLAGS_use_mkl, FLAGS_threads);

paddlenlp/ops/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ cd ../
277277

278278
``` sh
279279
cd bin/
280-
./transformer_e2e -batch_size <batch_size> -gpu_id <gpu_id> -model_dir <model_directory> -vocab_dir <dict_directory> -data_dir <input_data>
280+
./transformer_e2e -batch_size <batch_size> -gpu_id <gpu_id> -model_dir <model_directory> -vocab_file <dict_file> -data_file <input_data>
281281
```
282282

283283
举例说明:
@@ -286,7 +286,7 @@ cd bin/
286286
cd bin/
287287
# 执行 decoding_gemm 目的是基于当前环境、配置,提前确定一个性能最佳的矩阵乘算法,不是必要的步骤
288288
../third-party/build/fastertransformer/bin/decoding_gemm 8 5 8 64 38512 256 512 0
289-
./transformer_e2e -batch_size 8 -gpu_id 0 -model_dir ./infer_model/ -vocab_dir DATA_HOME/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/vocab_all.bpe.33708 -data_dir DATA_HOME/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/newstest2014.tok.bpe.33708.en
289+
./transformer_e2e -batch_size 8 -gpu_id 0 -model_dir ./infer_model/ -vocab_file DATA_HOME/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/vocab_all.bpe.33708 -data_file DATA_HOME/WMT14ende/WMT14.en-de/wmt14_ende_data_bpe/newstest2014.tok.bpe.33708.en
290290
```
291291

292292
其中:
@@ -326,5 +326,5 @@ python ./faster_transformer/sample/gpt_export_model_sample.py --model_name_or_pa
326326

327327
``` sh
328328
cd bin/
329-
./gpt -batch_size 1 -gpu_id 0 -model_dir path/to/model -vocab_dir path/to/vocab -start_token "<|endoftext|>" -end_token "<|endoftext|>"
329+
./gpt -batch_size 1 -gpu_id 0 -model_dir path/to/model -vocab_file path/to/vocab -start_token "<|endoftext|>" -end_token "<|endoftext|>"
330330
```

paddlenlp/ops/faster_transformer/src/demo/gpt.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ DEFINE_int32(gpu_id, 0, "The gpu id to do inference. ");
2929
DEFINE_string(model_dir,
3030
"./infer_model/",
3131
"The directory to the inference model. ");
32-
DEFINE_string(vocab_dir,
33-
"./infer_model/",
34-
"The directory to the vocabulary file. ");
32+
DEFINE_string(vocab_file,
33+
"./infer_model/vocab.txt",
34+
"The path to the vocabulary file. ");
3535
DEFINE_string(start_token, "<|endoftext|>", "The start token of GPT.");
3636
DEFINE_string(end_token, "<|endoftext|>", "The end token of GPT.");
3737

3838
using namespace paddle_infer;
3939

4040
std::string model_dir = "";
41-
std::string vocab_dir = "";
41+
std::string vocab_file = "";
4242

4343
const int BOS_IDX = 50256;
4444
const int EOS_IDX = 50256;
@@ -168,7 +168,7 @@ class DataReader {
168168
}
169169

170170
bool GetWordDict() {
171-
std::ifstream fin(vocab_dir);
171+
std::ifstream fin(vocab_file);
172172
std::string line;
173173
int k = 0;
174174
while (std::getline(fin, line)) {
@@ -296,7 +296,7 @@ int main(int argc, char** argv) {
296296
gpu_id = FLAGS_gpu_id;
297297

298298
model_dir = FLAGS_model_dir;
299-
vocab_dir = FLAGS_vocab_dir;
299+
vocab_file = FLAGS_vocab_file;
300300

301301
paddle::inference::Main(batch_size,
302302
gpu_id,

paddlenlp/ops/faster_transformer/src/demo/transformer_e2e.cc

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,16 @@ DEFINE_int32(gpu_id, 0, "The gpu id to do inference. ");
3838
DEFINE_string(model_dir,
3939
"./infer_model/",
4040
"The directory to the inference model. ");
41-
DEFINE_string(vocab_dir,
41+
DEFINE_string(vocab_file,
4242
"./vocab_all.bpe.33708",
43-
"The directory to the vocabulary file. ");
44-
DEFINE_string(data_dir,
43+
"The path to the vocabulary file. ");
44+
DEFINE_string(data_file,
4545
"./newstest2014.tok.bpe.33708.en",
46-
"The directory to the input data. ");
46+
"The path to the input data file. ");
4747

4848
std::string model_dir = "";
49-
std::string vocab_dir = "";
50-
std::string data_dir = "";
49+
std::string vocab_file = "";
50+
std::string data_file = "";
5151

5252
const int EOS_IDX = 1;
5353
const int PAD_IDX = 0;
@@ -145,7 +145,7 @@ class DataReader {
145145
}
146146

147147
bool GetWordDict() {
148-
std::ifstream fin(vocab_dir);
148+
std::ifstream fin(vocab_file);
149149
std::string line;
150150
int k = 0;
151151
while (std::getline(fin, line)) {
@@ -219,7 +219,7 @@ void Main(int batch_size, int gpu_id) {
219219
// can turn off the IR optimization for same results as following:
220220
// config.SwitchIrOptim(false);
221221
auto predictor = CreatePredictor(config);
222-
DataReader reader(data_dir);
222+
DataReader reader(data_file);
223223
reader.GetWordDict();
224224

225225
double whole_time = 0;
@@ -263,8 +263,8 @@ int main(int argc, char** argv) {
263263
gpu_id = FLAGS_gpu_id;
264264

265265
model_dir = FLAGS_model_dir;
266-
vocab_dir = FLAGS_vocab_dir;
267-
data_dir = FLAGS_data_dir;
266+
vocab_file = FLAGS_vocab_file;
267+
data_file = FLAGS_data_file;
268268

269269
paddle::inference::Main(batch_size, gpu_id);
270270

0 commit comments

Comments
 (0)