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

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

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions paddle/fluid/eager/auto_code_generator/generator/eager_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,12 +1893,29 @@ def GenerateHigherOrderNodeCreationCode(self):
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
Expand All @@ -1918,6 +1935,7 @@ def GenerateHigherOrderNodeCreationCode(self):
\"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,
Expand Down