-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
[Paddle TensorRT No.9-10] Add pd_op.(argmin,argsort)
converter
#69261
[Paddle TensorRT No.9-10] Add pd_op.(argmin,argsort)
converter
#69261
Conversation
… add_pirtensort_converter_argmin_argsort
你的PR提交成功,感谢你对开源项目的贡献! |
pd_op.(argmin,argsort)
converter
pd_op.(argmin,argsort)
converterpd_op.(argmin,argsort)
converter
return false; | ||
} | ||
auto x = op.x(); | ||
auto x_tensor_type = x.type().dyn_cast<paddle::dialect::DenseTensorType>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
获取dtype使用pir::GetDataTypeFromValue(x),可参考ScaleOpPattern
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你有如流账号吗,或者加vx,方便沟通下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
有如流的账号,但是不知道怎么加,手机vx是 18268023940
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
没查到
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已修改
data_type == phi::DataType::FLOAT64)) { | ||
return false; | ||
} | ||
int axis = static_cast<int>(op.axis() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里首先判断下,pir::GetDefiningOpForInput(op,1)->isapaddle:::dialect::FullOp,然后再去做下面的限制
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
前面已经判断过了,如果不是,就返回 false
phi::DataType dtype = | ||
op.attribute<paddle::dialect::DataTypeAttribute>("dtype").data(); | ||
if (axis == 0 || flatten || | ||
(dtype != phi::DataType::INT32 && dtype != phi::DataType::INT64)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里面加一个VLOG(3)的打印,pd_op.argmin因为什么条件不能进入trt
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已添加
op->set_attribute(kCanRunTrtAttr, rewriter.bool_attr(true)); | ||
return true; | ||
} | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同理把argmax改一下吧
const std::vector<std::string> required_attrs = {"axis", "descending"}; | ||
for (const auto &attr : required_attrs) { | ||
if (!op->HasAttribute(attr)) { | ||
VLOG(3) << "Argsort " << attr << " attribute does not exist"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pd_op.argsort
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
axis += x_shape.size(); | ||
} | ||
if (x_shape[axis] > 3840 || x_shape[axis] < 0) { | ||
VLOG(3) << "The axis dim of input should be less than 3840 and greater " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加一个pd_op.argsort吧vlog里面
x = inputs[0] | ||
input_dims = x.shape | ||
rank = len(input_dims) | ||
axis = int( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里还需要支持axis为pir::value的输入,也需要进入trt,同理可以把pd_op.argmax补充一下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marker Pass 除了 full op 产生的 Value 情况会不进入 Tensorrt
descending = paddle_op.attrs().get("descending", False) | ||
if axis < 0: | ||
axis += len(input_shape) | ||
topk_op = trt.TopKOperation.MAX if descending else trt.TopKOperation.MIN |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里converter可以参考argsort_op.cc,这里应该是少了很多情况
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
已完善
@@ -51,6 +63,64 @@ def test_trt_result(self): | |||
self.check_trt_result() | |||
|
|||
|
|||
class TestArgminCase2TRTPattern(TensorRTBaseTest): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这里再补充一下axis为pir::value的场景,使用np.array([1]),feed_list中加入axis,但是min_shape,和max_shape不需要写
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Marker Pass 除了 full op 产生的 Value 情况会不进入 Tensorrt
def setUp(self): | ||
self.python_api = paddle.argsort | ||
self.api_args = { | ||
"x": np.random.randn(2, 3).astype(np.float32), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
单测里面改成"float32",其余的同理
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
需要追加单测,完善一下c++和python代码覆盖率,可以参考单测TestMulticlassNMS3Marker内容写法,完善一下marker代码的覆盖率,具体覆盖率可以打开看一下ci-coverage的情况,覆盖率要达到90%以上才行
self.check_trt_result() | ||
|
||
|
||
class TestArgsortCase4TRTPattern(TensorRTBaseTest): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个其实不用再加一个吧,能不能把self.check_marker(expected_result=False)放在前面某个单测里面检查下
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
前面的 chekc_marker 应该都是 True 的吧,False 可以放在前面吗
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
哦对,也是
PR Category
Inference
PR Types
New features
Description
新增了 pd_op.argmix Marker 和 Converter
新增了 pd_op.argsort Marker 和 Converter
links: 【开源任务】PIR-TensorRT converter推全升级 #69178