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 5 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_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
26 changes: 25 additions & 1 deletion python/paddle/vision/ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@

from ..base import core
from ..base.data_feeder import check_type, check_variable_and_dtype
from ..base.framework import Variable, in_dygraph_mode, in_dynamic_or_pir_mode
from ..base.framework import (
Variable,
in_dygraph_mode,
in_dynamic_or_pir_mode,
in_pir_mode,
)
from ..base.layer_helper import LayerHelper
from ..framework import _current_expected_place
from ..nn import BatchNorm2D, Conv2D, Layer, ReLU, Sequential
Expand Down Expand Up @@ -2138,6 +2143,25 @@ def generate_proposals(
scores, bbox_deltas, img_size, anchors, variances, *attrs
)

return rpn_rois, rpn_roi_probs, rpn_rois_num
elif in_pir_mode():
assert (
return_rois_num
), "return_rois_num should be True in PaddlePaddle inner op mode."
attrs = {
'pre_nms_topN': pre_nms_top_n,
'post_nms_topN': post_nms_top_n,
'nms_thresh': nms_thresh,
'min_size': min_size,
'eta': eta,
'pixel_offset': pixel_offset,
}
rpn_rois, rpn_roi_probs, rpn_rois_num = _C_ops.generate_proposals(
scores, bbox_deltas, img_size, anchors, variances, **attrs
)
Copy link
Contributor

Choose a reason for hiding this comment

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

这里不能以 **args 的形式传递参数。因为 _C_ops.generate_proposals 对应的 static_api_generate_proposals 不会解析关键字参数。需要按顺序来传递位置参数

rpn_rois.stop_gradient = True
rpn_roi_probs.stop_gradient = True
rpn_rois_num.stop_gradient = True
return rpn_rois, rpn_roi_probs, rpn_rois_num
else:
helper = LayerHelper('generate_proposals_v2', **locals())
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
2 changes: 2 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