未验证 提交 fb8ea98c 编写于 作者: X xiaoguoguo626807 提交者: GitHub

【prim】add dygraph error code when close prim flag for op who has composite...

【prim】add dygraph error code when close prim flag for op who has composite implement but no grad kernel (#53610)

* add no prim no gradOp error code

* delete prim_white_list throw error

* delete invoke_forward_api  throw error

* delete invoke_forward_api  throw error

* review

* review
上级 f3393f49
......@@ -1893,12 +1893,29 @@ class DygraphNodeGenerator(DygraphFunctionGeneratorBase):
False if self.composite_func_info == {} else True
)
if is_composite_grad_api and next_grad_node_creation_str != '':
next_grad_node_creation_str = f"""
if is_composite_grad_api:
if next_grad_node_creation_str != '':
next_grad_node_creation_str = f"""
if (!paddle::prim::PrimCommonUtils::IsEagerPrimEnabled()) {{
{next_grad_node_creation_str}
}}
"""
else:
if not (
self.grad_api_contents["backward_op"] in prim_white_list
or is_invoke_forward_api
):
next_grad_node_creation_str = f"""
if (!paddle::prim::PrimCommonUtils::IsEagerPrimEnabled()) {{
if(trace_backward) {{
PADDLE_THROW(phi::errors::Unavailable(
\"The Op {self.backward_api_name} doesn't have any grad\"
\"op. If you don't intend calculating higher order\"
\"derivatives, please set `create_graph`to False.\"));
}}
}}
"""
if next_node_generator is not None:
has_higher_order_node = True
......@@ -1918,6 +1935,7 @@ class DygraphNodeGenerator(DygraphFunctionGeneratorBase):
\"op. If you don't intend calculating higher order\"
\"derivatives, please set `create_graph`to False.\"));
}}"""
return (
has_higher_order_node,
is_invoke_forward_api,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册