-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add infer predict function for PET #2690
Conversation
add infer predict function for PET
add infer predict function for PET
infer predict example model_dir is the path of infer model exist |
from paddlenlp.data import Stack, Tuple, Pad | ||
from paddlenlp.datasets import load_dataset | ||
from paddlenlp.utils.log import logger | ||
from functools import partial |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个import提前一下,这个属于PE8标准
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
tokenizer = ppnlp.transformers.ErnieTokenizer.from_pretrained('ernie-1.0') | ||
|
||
batchify_test_fn = lambda samples, fn=Tuple( | ||
Pad(axis=0, pad_val=tokenizer.pad_token_id), # src_ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pad这块可以设置一下dtype="int64", 在windows不会出现不兼容的问题
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
parser.add_argument("--pattern_id", default=0, type=int, help="pattern id of pet") | ||
args = parser.parse_args() | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
空行可以去掉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
self.batch_size = batch_size | ||
|
||
model_file = model_dir + "/inference.pdmodel" | ||
params_file = model_dir + "/inference.pdiparams" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这块是不是可以os.path.join这种,在windows的目录层次是 \ 符号
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
self.output_handle = self.predictor.get_output_handle( | ||
self.predictor.get_output_names()[0]) | ||
|
||
if args.benchmark: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
benchmark这块的代码可以去掉,PET这块不需要benchmark监测
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
parser.add_argument('--enable_mkldnn', default=False, type=eval, choices=[True, False], | ||
help='Enable to use mkldnn to speed up when using cpu.') | ||
|
||
parser.add_argument("--benchmark", type=eval, default=False, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
benchmark的args可以去掉
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fix
batchify_fn=batchify_test_fn, | ||
trans_fn=trans_test_func) | ||
p = Predictor(args.model_dir) | ||
y = p.predict(tokenizer, test_data_loader, label_norm_dict) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
整体需要一个文档介绍一下怎么使用,例如TRT的安装,可以拷贝一下其他的文档;同时predict.py怎么使用
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add README.md for how to use predict.py
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add README.md for how to use predict.py
OK,Thank for your contribution!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add README.md for how to use predict.py
OK,Thank for your contribution!
Thanks for your patience while i make these changes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR types
OthersPR changes
Models
Description
add infer predict function for PET