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

【PIR API adaptor No.257】Migrate paddle.Tensor.gcd into pir #59452

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions python/paddle/tensor/math.py
Original file line number Diff line number Diff line change
Expand Up @@ -5657,7 +5657,7 @@ def _gcd_body_fn(x, y):
)
return (paddle.where(x < y, y, x), paddle.where(x < y, x, y))

if in_dynamic_mode():
if in_dynamic_or_pir_mode():
Copy link
Contributor

@MarioLulab MarioLulab Dec 7, 2023

Choose a reason for hiding this comment

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

因为 pir 下与控制流相关的算子适配了静态图专用 api (比如下面的 paddle.static.nn.while_loop ),所以涉及控制流 api 可以复用旧静态图构图分支。这里可以复原

Suggested change
if in_dynamic_or_pir_mode():
if in_dynamic_mode():

while _gcd_cond_fn(x, y):
x, y = _gcd_body_fn(x, y)

Expand Down Expand Up @@ -5707,7 +5707,7 @@ def _gcd_body_fn(x, y):
paddle.where_(x >= y, x, y),
)

if in_dynamic_mode():
if in_dynamic_or_pir_mode():
while _gcd_cond_fn(x, y):
y, x = _gcd_body_fn(x, y)

Expand Down
2 changes: 2 additions & 0 deletions test/legacy_test/test_gcd.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import paddle
from paddle import base
from paddle.base import core
from paddle.pir_utils import test_with_pir_api

paddle.enable_static()

Expand All @@ -30,6 +31,7 @@ def setUp(self):
self.x_shape = [1]
self.y_shape = [1]

@test_with_pir_api
def test_static_graph(self):
startup_program = base.Program()
train_program = base.Program()
Expand Down