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.90,92】Migrate some ops into pir #59801

Merged
merged 8 commits into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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/incubate/operators/graph_khop_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from paddle import _legacy_C_ops
from paddle.base.data_feeder import check_variable_and_dtype
from paddle.base.layer_helper import LayerHelper
from paddle.framework import in_dynamic_mode
from paddle.framework import in_dynamic_or_pir_mode


def graph_khop_sampler(
Expand Down Expand Up @@ -84,7 +84,7 @@ def graph_khop_sampler(

"""

if in_dynamic_mode():
if in_dynamic_or_pir_mode():
if return_eids:
if sorted_eids is None:
raise ValueError(
Expand Down
4 changes: 2 additions & 2 deletions python/paddle/incubate/operators/graph_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from paddle import _C_ops
from paddle.base.data_feeder import check_variable_and_dtype
from paddle.base.layer_helper import LayerHelper
from paddle.framework import in_dynamic_mode
from paddle.framework import in_dynamic_or_pir_mode
from paddle.utils import deprecated


Expand Down Expand Up @@ -130,7 +130,7 @@ def graph_reindex(
"be None if `flag_buffer_hashtable` is True."
)

if in_dynamic_mode():
if in_dynamic_or_pir_mode():
reindex_src, reindex_dst, out_nodes = _C_ops.reindex_graph(
x,
neighbors,
Expand Down
2 changes: 1 addition & 1 deletion python/paddle/vision/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -2122,7 +2122,7 @@ def generate_proposals(
[1, 1])
"""

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

Choose a reason for hiding this comment

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

这里动态图和下面的静态图的逻辑并不统一。静态图还有设置 stop_gradient 的过程,建议新开一个 in_pir_mode 分支,添加设置 stop_gradient 的逻辑

assert (
return_rois_num
), "return_rois_num should be True in dygraph mode."
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_generate_proposals_op.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def set_data(self):

def test_check_output(self):
# NODE(yjjiang11): This op will be deprecated.
self.check_output(check_dygraph=False)
self.check_output(check_dygraph=False, check_pir=True)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
self.check_output(check_dygraph=False, check_pir=True)
self.check_output(check_dygraph=False)

当前 generate_proposals 应该已经废弃,只使用 generate_proposals_v2 了。所以该单测可以不适配


def setUp(self):
self.op_type = "generate_proposals"
Expand Down
2 changes: 1 addition & 1 deletion test/legacy_test/test_generate_proposals_v2_op.py

This comment was marked as resolved.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

这个应该如何进行定位呢?一直不知道如何进行定位

Copy link
Contributor

Choose a reason for hiding this comment

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

这种继承自OpTest 的单测一般用 pdb 等工具在python 端进行单步调试即可。比如这里我是单步调试看运行时ret_tuple和outputs_sig分别是什么值

Copy link
Contributor Author

Choose a reason for hiding this comment

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

懂了,我目前都是CI Debug哈哈

Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ def set_data(self):
}

def test_check_output(self):
self.check_output()
self.check_output(check_pir=True)

def setUp(self):
self.op_type = "generate_proposals_v2"
Expand Down
3 changes: 3 additions & 0 deletions test/legacy_test/test_graph_khop_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import paddle
from paddle import base
from paddle.pir_utils import test_with_pir_api


class TestGraphKhopSampler(unittest.TestCase):
Expand Down Expand Up @@ -146,6 +147,7 @@ def test_uva_sample_result(self):
in_neighbors = np.isin(edge_src_n.numpy(), self.dst_src_dict[n])
self.assertTrue(np.sum(in_neighbors) == in_neighbors.shape[0])

@test_with_pir_api
def test_sample_result_static_with_eids(self):
paddle.enable_static()
with paddle.static.program_guard(paddle.static.Program()):
Expand Down Expand Up @@ -207,6 +209,7 @@ def test_sample_result_static_with_eids(self):
in_neighbors = np.isin(edge_src_n, self.dst_src_dict[n])
self.assertTrue(np.sum(in_neighbors) == in_neighbors.shape[0])

@test_with_pir_api
def test_sample_result_static_without_eids(self):
paddle.enable_static()
with paddle.static.program_guard(paddle.static.Program()):
Expand Down
4 changes: 4 additions & 0 deletions test/legacy_test/test_graph_reindex.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import numpy as np

import paddle
from paddle.pir_utils import test_with_pir_api


class TestGraphReindex(unittest.TestCase):
Expand Down Expand Up @@ -128,6 +129,7 @@ def test_heter_reindex_result_v2(self):
np.testing.assert_allclose(reindex_dst, reindex_dst_, rtol=1e-05)
np.testing.assert_allclose(out_nodes, out_nodes_, rtol=1e-05)

@test_with_pir_api
def test_reindex_result_static(self):
paddle.enable_static()
with paddle.static.program_guard(paddle.static.Program()):
Expand Down Expand Up @@ -369,6 +371,7 @@ def test_heter_reindex_result_v3(self):
np.testing.assert_allclose(reindex_dst, reindex_dst_, rtol=1e-05)
np.testing.assert_allclose(out_nodes, out_nodes_, rtol=1e-05)

@test_with_pir_api
Copy link
Contributor

Choose a reason for hiding this comment

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

当前 pr 适配的是 paddle.incubate.graph_reindex 而非 paddle.geometric.reindex_graph。这个单测取消掉吧

def test_reindex_result_static(self):
paddle.enable_static()
with paddle.static.program_guard(paddle.static.Program()):
Expand Down Expand Up @@ -448,6 +451,7 @@ def test_reindex_result_static(self):
)
np.testing.assert_allclose(self.out_nodes, out_nodes_2, rtol=1e-05)

@test_with_pir_api
Copy link
Contributor

Choose a reason for hiding this comment

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

同上

def test_heter_reindex_result_static(self):
paddle.enable_static()
np_x = np.arange(5).astype("int64")
Expand Down