CARVIEW |
Navigation Menu
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
[Paddle Inference] support inference in dynamic graph #65962
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
[Paddle Inference] support inference in dynamic graph #65962
Conversation
你的PR提交成功,感谢你对开源项目的贡献! |
|
||
# This is the inner_most decorator, ie. when user invoke the function decorated by @paddle.jit.to_static(backend='inference', ) | ||
# he is actually invoke this internel function. | ||
def innermost_decorator(*args, **kwargs): |
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.
这个是装饰器最内的调用
delete_pass_lists=delete_pass_lists, | ||
) | ||
|
||
# This is the inner_most decorator, ie. when user invoke the function decorated by @paddle.jit.to_static(backend='inference', ) |
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.
# This is the inner_most decorator, ie. when user invoke the function decorated by @paddle.jit.to_static(backend='inference', ) | |
# This is the inner_most decorator, ie. when user invoke the function decorated by @paddle.incubate.jit.inference(mylayer) |
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.
THX
def inference( | ||
function=None, | ||
cache_static_model=False, | ||
save_model_dir=None, | ||
memory_pool_init_size_mb=1000, | ||
precision_mode="float32", | ||
switch_ir_optim=True, | ||
switch_ir_debug=False, | ||
enable_cinn=False, | ||
with_trt=False, | ||
trt_precision_mode="float32", | ||
trt_use_static=False, | ||
collect_shape=False, | ||
enable_new_ir=False, | ||
exp_enable_use_cutlass=False, | ||
delete_pass_lists=None, | ||
): |
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.
公开 API 需要加一下类型注解
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.
公开 API 需要加一下类型注解
done.THX
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
5ce3e7e
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.
类型注解不是很符合我们现在的规范,我来修改下吧
|
||
def inference( | ||
function=None, | ||
cache_static_model: Optional[bool] = 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.
这个不支持传 None 吧?为啥是 Optional
?
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.
改好了
好哦,感谢感谢!
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.
这个不支持传 None 吧?为啥是
Optional
?
none的时候会内部把它认为是默认路径.
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.
LGTM for setup.py.in
…5962) * support inference in dynamic graph * refine annotations --------- Co-authored-by: SigureMo <sigure.qaq@gmail.com>
…5962) * support inference in dynamic graph * refine annotations --------- Co-authored-by: SigureMo <sigure.qaq@gmail.com>
PR Category
Inference
PR Types
New features
Description
Pcard-71500
背景
paddle.jit.save
转换静态图有时存在较高的使用门槛(学习成本)-> 到底有没有必要将整个模型都转为静态图?jit.to_static
基本都可以成功,但是全图jit.save
在一些复杂模型中会遇到报错,需要修改用户代码才能避免。我们拟提出混合动态图和静态图推理的模式,
装饰器方式使用
此特性只支持py动态图推理部署用户
动态图推理时候,当用户意识到某个模块比较费时间,可以将此模块封装成py函数
然后加上装饰器
paddle.incubate.jit.inference()
,即可获得推理加速,用法十分简单。举例
例如 transformer 架构的模型中,绝大部分的耗时应该是这样的语句
代码1
@paddle.incubate.jit.inference
,调用即可获得加速[x,y] = self.transformer_blocks(x,y,c,mask)
即可获得加速model1=paddle.incubate.jit.inference()(model1)
,model2=paddle.incubate.jit.inference(model2)
代替。jit.save
,并将此维度的这个值标记为None,表明此维度可变化,当再次变化的时候则无需再做jit.save