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

[inference Zero-Dim][trt]Unary operation support 0d #53506

Merged
merged 5 commits into from
May 8, 2023
Merged
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
19 changes: 17 additions & 2 deletions paddle/fluid/inference/tensorrt/op_teller.cc
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,16 @@ struct SimpleOpTypeSetTeller : public Teller {
"atanh", "ceil", "celu",
"erf", "floor", "round",
"sign", "silu", "logical_not",
"reciprocal", "tanh_shrink", "logsigmoid"};
"reciprocal", "tanh_shrink", "logsigmoid",
"rsqrt"};
std::unordered_set<std::string> unary_list = {
"exp", "log", "sqrt", "abs", "sin",
"cos", "tan", "tanh", "sinh", "cosh",
"asin", "acos", "atan", "asinh", "acosh",
"atanh", "ceil", "celu", "floor", "round",
"sign", "silu", "logical_not", "reciprocal", "tanh_shrink",
"logsigmoid", "erf", "bitwise_not", "equal", "not_equal",
"rsqrt"};
if (act_op_list.find(op_type) != act_op_list.end()) {
auto* block = desc.Block();
if (block == nullptr) {
Expand All @@ -127,9 +136,15 @@ struct SimpleOpTypeSetTeller : public Teller {
VLOG(3) << op_type << " op does not support tensorrt.";
return false;
}
#endif
#if !IS_TRT_VERSION_GE(8600)
if (x_shape.size() == 0 && unary_list.find(op_type) != unary_list.end()) {
VLOG(3) << op_type
<< " op does not support 0 dim input when TensorRT < 8.6.";
return false;
}
#endif
}

// In static shape in Paddle-TRT, we can't allow that one op has a
// 1D intermediate tensor as input.
if (!with_dynamic_shape) {
Expand Down
10 changes: 9 additions & 1 deletion test/ir/inference/test_trt_convert_activation.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ def generate_input1(dims, batch, attrs: List[Dict[str, Any]]):
for op_type in [
"relu",
"sigmoid",
"tanh",
"relu6",
"elu",
"selu",
Expand Down Expand Up @@ -146,6 +145,15 @@ def clear_dynamic_shape():
def generate_trt_nodes_num(attrs, dynamic_shape):
if not dynamic_shape and (self.dims == 1 or self.dims == 0):
return 0, 3
runtime_version = paddle_infer.get_trt_runtime_version()
if (
runtime_version[0] * 1000
+ runtime_version[1] * 100
+ runtime_version[2] * 10
< 8600
and self.dims == 0
) and program_config.ops[0].type in ["celu", "logsigmoid"]:
return 0, 3
return 1, 2

attrs = [
Expand Down
16 changes: 15 additions & 1 deletion test/ir/inference/test_trt_convert_unary.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ def sample_program_configs(self):
self.trt_param.workspace_size = 1073741824

def generate_input1(dims, batch, attrs: List[Dict[str, Any]]):
if dims == 0:
return np.random.random([]).astype(np.float32)
if dims == 2:
return np.random.random([3, 32]).astype(np.float32)
elif dims == 3:
Expand All @@ -43,14 +45,16 @@ def generate_input1(dims, batch, attrs: List[Dict[str, Any]]):
return np.random.random([batch, 3, 32, 32]).astype(np.float32)

def generate_int_input(dims, batch, attrs: List[Dict[str, Any]]):
if dims == 0:
return np.random.random([]).astype(np.int32)
if dims == 2:
return np.random.random([3, 32]).astype(np.int32)
elif dims == 3:
return np.random.random([3, 32, 32]).astype(np.int32)
else:
return np.random.random([batch, 3, 32, 32]).astype(np.int32)

for dims in [2, 3, 4]:
for dims in [0, 2, 3, 4]:
for batch in [1, 4]:
for op_type in [
"exp",
Expand All @@ -60,6 +64,7 @@ def generate_int_input(dims, batch, attrs: List[Dict[str, Any]]):
"sin",
"cos",
"tan",
"tanh",
Copy link
Contributor

Choose a reason for hiding this comment

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

If remove tanh, where to test it?

Copy link
Contributor Author

@zhangjun zhangjun May 5, 2023

Choose a reason for hiding this comment

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

If remove tanh, where to test it?

move tanhfrom test_trt_convert_activation.py to test_trt_convert_unary.py.

"sinh",
"cosh",
"asin",
Expand Down Expand Up @@ -179,6 +184,15 @@ def generate_trt_nodes_num(attrs, dynamic_shape):
)
):
return 0, 3
runtime_version = paddle_infer.get_trt_runtime_version()
if (
runtime_version[0] * 1000
+ runtime_version[1] * 100
+ runtime_version[2] * 10
< 8600
and self.dims == 0
):
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. A common function can be extracted to calculate TensorRT version number
  2. In line 174, use ver = paddle_infer.get_trt_compile_version() to get version

Copy link
Contributor Author

Choose a reason for hiding this comment

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

  1. A common function can be extracted to calculate TensorRT version number
  2. In line 174, use ver = paddle_infer.get_trt_compile_version() to get version

When the OP behavior is inconsistent among different TensorRT versions, using the runtime version is more appropriate than the compiled version, making it easier to test multiple versions.

return 0, 3
return 1, 2

attrs = [
Expand Down