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 some basic guard #69313

Merged
merged 6 commits into from
Nov 13, 2024

Conversation

zrr1999
Copy link
Member

@zrr1999 zrr1999 commented Nov 12, 2024

PR Category

Execute Infrastructure

PR Types

Performance

Description

在C++端添加了一些基础的 guard并添加了一些单元测试

Copy link

paddle-bot bot commented Nov 12, 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 12, 2024
Comment on lines 113 to 146
py::class_<GuardBase, std::shared_ptr<GuardBase>>(
*m, "GuardBase", R"DOC(GuardBase Class.)DOC")
.def("check", &GuardBase::check_pybind);
py::class_<LambdaGuard, GuardBase, std::shared_ptr<LambdaGuard>>(
*m, "LambdaGuard", R"DOC(LambdaGuard Class.)DOC")
.def(py::init<const py::function &>(), py::arg("guard_check_fn"));
py::class_<GuardGroup, GuardBase, std::shared_ptr<GuardGroup>>(
*m, "GuardGroup", R"DOC(GuardGroup Class.)DOC")
.def(py::init<std::vector<std::shared_ptr<GuardBase>>>(),
py::arg("guards"));
py::class_<TypeMatchGuard, GuardBase, std::shared_ptr<TypeMatchGuard>>(
*m, "TypeMatchGuard", R"DOC(TypeMatchGuard Class.)DOC")
.def(py::init<const py::type &>(), py::arg("py_type"));
py::class_<LengthMatchGuard, GuardBase, std::shared_ptr<LengthMatchGuard>>(
*m, "LengthMatchGuard", R"DOC(LengthMatchGuard Class.)DOC")
.def(py::init<Py_ssize_t>(), py::arg("length"));
py::class_<ValueMatchGuard, GuardBase, std::shared_ptr<ValueMatchGuard>>(
*m, "ValueMatchGuard", R"DOC(ValueMatchGuard Class.)DOC")
.def(py::init<const py::object &>(), py::arg("py_value"));
py::class_<DtypeMatchGuard, GuardBase, std::shared_ptr<DtypeMatchGuard>>(
*m, "DtypeMatchGuard", R"DOC(DtypeMatchGuard Class.)DOC")
.def(py::init<const paddle::framework::proto::VarType &>(),
py::arg("dtype"))
.def(py::init<const phi::DataType &>(), py::arg("dtype"));
py::class_<LayerMatchGuard, GuardBase, std::shared_ptr<LayerMatchGuard>>(
*m, "LayerMatchGuard", R"DOC(LayerMatchGuard Class.)DOC")
.def(py::init<const py::object &>(), py::arg("layer_obj"));

m->def(
"merge_guard",
[](const std::vector<std::shared_ptr<GuardBase>> &py_guards) {
return GuardGroup(py_guards);
},
py::arg("py_guards"));
Copy link
Member

Choose a reason for hiding this comment

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

这块可以抽一个函数叫 BindGuard,这里直接调用下就好了

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

@@ -61,6 +61,43 @@ void BindJit(pybind11::module *m) {
});
}

void BindGuard(pybind11::module *m) {
Copy link
Member

@SigureMo SigureMo Nov 12, 2024

Choose a reason for hiding this comment

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

这块也要放到 SOT_IS_SUPPORTED 里,不然编译 Python 3.14 GuardGroup 等会找不到

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

@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 🐾

后续可以在 tracking issue 里记录下开发进度,比如这个 PR 完成了基础 guard 的哪些(是全完成了吗?)

然后后续还有哪些已知的开发工作,记录下整体进展即可,可以没有具体排期

@SigureMo
Copy link
Member

相关 PR 链接下 #69264

@SigureMo SigureMo merged commit bf0e51c into PaddlePaddle:develop Nov 13, 2024
28 checks passed
@zrr1999 zrr1999 deleted the faster_guard branch November 13, 2024 06:23
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