Skip to content
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

[SOT][Faster Guard] add FasterStringifiedExpression #69353

Merged
merged 8 commits into from
Nov 13, 2024

Conversation

zrr1999
Copy link
Member

@zrr1999 zrr1999 commented Nov 13, 2024

PR Category

Execute Infrastructure

PR Types

Performance

Description

  • 添加 ShapeMatchGuard
  • 对 SymbolicVariable 和 TensorDtypeVariable 适配了 faster guard
  • 添加了 test_with_faster_guard 装饰器,对已有单测添加 faster guard 测试

Copy link

paddle-bot bot commented Nov 13, 2024

你的PR提交成功,感谢你对开源项目的贡献!
请关注后续CI自动化测试结果,详情请参考Paddle-CI手册
Your PR has been submitted. Thanks for your contribution!
Please wait for the result of CI firstly. See Paddle CI Manual for details.

@paddle-bot paddle-bot bot added the contributor External developers label Nov 13, 2024
paddle/fluid/pybind/sot/guards.h Outdated Show resolved Hide resolved
for (size_t i = 0; i < shape.size(); ++i) {
if (py::isinstance<py::int_>(shape[i])) {
_expected[i] = std::make_optional(shape[i].cast<int64_t>());
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

else 是 None 是么?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这块主要是针对SombolcInt,现在只要不是整数都被当成动态shape了,没有做其他类型的检查

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

那在构造的时候需要小心传入 -1,会产生奇怪的问题,或者直接不允许 -1(负数)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

self.faster_guard = faster_guard
if ENV_SOT_ENABLE_FASTER_GUARD:
original_expr_template = expr_template
guard_name = f"guard_check_{id(faster_guard)}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

名字里是否可以表明 guard 类型?这样生成的 guard 更具可读性些~

Copy link
Member

@SigureMo SigureMo Nov 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Cache]: Cache miss, Guard is 
lambda frame: (___t_1 := (len((___t_0 := (frame.f_locals['input'])).shape) == 4)) and (___t_2 := (___t_0.shape[0] == 32)) and (___t_3 := (___t_0.shape[1] == 16)) and (___t_4 := (___t_0.shape[2] == 176)) and (___t_5 := (___t_0.shape[3] == 176)) and (___t_6 := (___t_0.dtype == paddle.core.DataType(10))) and (___t_7 := (___t_0.stop_gradient == False)) and (___t_15 := (id(type((___t_14 := ((___t_13 := ((___t_12 := ((___t_11 := ((___t_10 := ((___t_9 := ((___t_8 := (frame.f_locals['self']))._sub_layers))['0'])).__call__)).__globals__['in_to_static_mode'])).__globals__['global_var']))._in_to_static_mode_)))) == 94911584974496)) and (___t_16 := (___t_14 == False)) and (___t_18 := (isinstance((___t_17 := (___t_10._forward_pre_hooks)), dict))) and (___t_19 := (len(___t_17) == 0)) and (___t_21 := (isinstance((___t_20 := (___t_10._forward_post_hooks)), dict))) and (___t_22 := (len(___t_20) == 0)) and (___t_24 := (id(type((___t_23 := (___t_10._built)))) == 94911584974496)) and (___t_25 := (___t_23 == False)) and (___t_28 := (id(type((___t_27 := ((___t_26 := (___t_11.__globals__['in_profiler_mode'])).__globals__['_is_profiler_used'])))) == 94911584974496)) and (___t_29 := (___t_27 == False)) and (___t_32 := (isinstance((___t_31 := ((___t_30 := (___t_10.dw_conv))._forward_pre_hooks)), dict))) and (___t_33 := (len(___t_31) == 0)) and (___t_35 := (isinstance((___t_34 := (___t_30._forward_post_hooks)), dict))) and (___t_36 := (len(___t_34) == 0)) and (___t_38 := (id(type((___t_37 := (___t_30._built)))) == 94911584974496)) and (___t_39 := (___t_37 == False)) and (___t_41 := (id((___t_40 := (___t_30.conv))) == 139643550285056)) and (___t_42 := (___t_40.training == True)) and (___t_44 := (id((___t_43 := (___t_30.bn))) == 139643550284096)) and (___t_45 := (___t_43.training == True)) and (___t_47 := (id((___t_46 := (___t_30.act))) == 139643550285392)) and (___t_48 := (___t_46.training == True)) and (___t_50 := (id(type((___t_49 := (___t_10.use_se)))) == 94911584974496)) and (___t_51 := (___t_49 == False)) and (___t_54 := (isinstance((___t_53 := ((___t_52 := (___t_10.pw_conv))._forward_pre_hooks)), dict))) and (___t_55 := (len(___t_53) == 0)) and (___t_57 := (isinstance((___t_56 := (___t_52._forward_post_hooks)), dict))) and (___t_58 := (len(___t_56) == 0)) and (___t_60 := (id(type((___t_59 := (___t_52._built)))) == 94911584974496)) and (___t_61 := (___t_59 == False)) and (___t_63 := (id((___t_62 := (___t_52.conv))) == 139643550385152)) and (___t_64 := (___t_62.training == True)) and (___t_66 := (id((___t_65 := (___t_52.bn))) == 139643550385728)) and (___t_67 := (___t_65.training == True)) and (___t_69 := (id((___t_68 := (___t_52.act))) == 139643550385248)) and (___t_70 := (___t_68.training == True)) and (___t_71 := (isinstance(___t_9, dict))) and (___t_72 := (len(___t_9) == 1)) and (___t_73 := (id(___t_10) == 139643550283328)) and (___t_74 := (___t_10.training == True))
[Cache]: missed at frame.f_locals['input'].shape[1] == 16

最好 faster guard 仍然能有这样的体验,能够知道是在什么地方 cache miss 了(实现方式可能有所不同)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在是先加上了名字,后面再改进一下把参数也标注出来

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

现在是先加上了名字,后面再改进一下把参数也标注出来

嗯嗯,这个 PR 不用考虑那么完善,后续设计考虑到这点即可(后续 lookup 不一定走这套(Python 端线性查找),在最终态(比如 C++ 端树形查找)实现这一点即可)

Copy link
Member

@SigureMo SigureMo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTMeow 🐾

@SigureMo SigureMo closed this Nov 13, 2024
@SigureMo SigureMo reopened this Nov 13, 2024
@SigureMo SigureMo merged commit 3b0e253 into PaddlePaddle:develop Nov 13, 2024
28 checks passed
@zrr1999 zrr1999 deleted the faster_guard branch November 14, 2024 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor External developers
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants