未验证 提交 3a7caf48 编写于 作者: Z Zeng Jinle 提交者: GitHub

add grad maker assert, test=develop (#21564)

上级 b241c732
......@@ -282,6 +282,30 @@ static void inline CreateVariableIfNotExit(
return;
}
static void AssertStaticGraphAndDygraphGradMakerNoDiff() {
std::set<std::string> ops;
for (auto &pair : framework::OpInfoMap::Instance().map()) {
bool has_static_grad_maker = (pair.second.grad_op_maker_ != nullptr);
bool has_dygraph_grad_maker =
(pair.second.dygraph_grad_op_maker_ != nullptr);
if (has_static_grad_maker ^ has_dygraph_grad_maker) {
bool has_kernel =
(framework::OperatorWithKernel::AllOpKernels().count(pair.first) > 0);
if (has_kernel) {
ops.insert(pair.first);
} else {
VLOG(5) << pair.first << " has no kernels, skip";
}
}
}
PADDLE_ENFORCE_EQ(ops.empty(), true,
platform::errors::Unimplemented(
"OperatorWithKernel [%s] have only static graph grad "
"maker or have only dygraph grad maker, which is not "
"allowed",
string::join_strings(ops, ',')));
}
#ifdef PADDLE_WITH_AVX
PYBIND11_MODULE(core_avx, m) {
#else
......@@ -293,6 +317,8 @@ PYBIND11_MODULE(core_noavx, m) {
paddle::memory::allocation::UseAllocatorStrategyGFlag();
AssertStaticGraphAndDygraphGradMakerNoDiff();
m.doc() = "C++ core of PaddlePaddle";
// using framework in this function. Since it is inside a function, it will
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册