-
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
[Hackathon NO.76] 为 Paddle-TRT 添加elementwise_mod 算子 #50974
Changes from all commits
d3435c3
85b4a21
317cc38
ccc5007
9cb533a
17ebc47
1e88442
4ed8697
08f4992
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,6 +36,10 @@ def generate_input(shape, op_type): | |
return np.random.randint( | ||
low=1, high=10000, size=shape, dtype=np.int32 | ||
) | ||
elif op_type == "elementwise_mod": | ||
return np.random.uniform(low=0.1, high=1.0, size=shape).astype( | ||
np.float32 | ||
) | ||
else: | ||
return np.random.random(shape).astype(np.float32) | ||
|
||
|
@@ -44,6 +48,10 @@ def generate_weight(op_type): | |
return np.random.randint( | ||
low=1, high=10000, size=[1, 32, 1, 1], dtype=np.int32 | ||
) | ||
elif op_type == "elementwise_mod": | ||
return np.random.uniform( | ||
low=0.1, high=1.0, size=[1, 32, 1, 1] | ||
).astype(np.float32) | ||
else: | ||
return np.random.randn(1, 32, 1, 1).astype(np.float32) | ||
|
||
|
@@ -58,6 +66,7 @@ def generate_weight(op_type): | |
"elementwise_min", | ||
"elementwise_max", | ||
"elementwise_floordiv", | ||
"elementwise_mod", | ||
]: | ||
for axis in [-1]: | ||
self.dims = len(shape) | ||
|
@@ -169,6 +178,10 @@ def generate_input(shape, op_type): | |
return np.random.randint( | ||
low=1, high=10000, size=shape, dtype=np.int32 | ||
) | ||
if op_type == "elementwise_mod": | ||
return np.random.uniform(low=0.1, high=1.0, size=shape).astype( | ||
np.float32 | ||
) | ||
else: | ||
return np.random.random(shape).astype(np.float32) | ||
|
||
|
@@ -178,6 +191,10 @@ def generate_weight(op_type): | |
return np.random.randint( | ||
low=1, high=10000, size=[1], dtype=np.int32 | ||
) | ||
elif op_type == "elementwise_mod": | ||
return np.random.uniform(low=0.1, high=1.0, size=[1]).astype( | ||
np.float32 | ||
) | ||
else: | ||
return np.random.randn(1).astype(np.float32) | ||
|
||
|
@@ -191,6 +208,7 @@ def generate_weight(op_type): | |
"elementwise_min", | ||
"elementwise_max", | ||
"elementwise_floordiv", | ||
"elementwise_mod", | ||
]: | ||
for axis in [-1]: | ||
self.dims = len(shape) | ||
|
@@ -290,6 +308,10 @@ def generate_input(shape, op_type): | |
return np.random.randint( | ||
low=1, high=10000, size=shape, dtype=np.int32 | ||
) | ||
elif op_type == "elementwise_mod": | ||
return np.random.uniform(low=0.1, high=1.0, size=shape).astype( | ||
np.float32 | ||
) | ||
else: | ||
return np.random.random(shape).astype(np.float32) | ||
|
||
|
@@ -299,6 +321,10 @@ def generate_weight(op_type): | |
return np.random.randint( | ||
low=1, high=10000, size=[32], dtype=np.int32 | ||
) | ||
elif op_type == "elementwise_mod": | ||
return np.random.uniform(low=0.1, high=1.0, size=[32]).astype( | ||
np.float32 | ||
) | ||
else: | ||
return np.random.randn(32).astype(np.float32) | ||
|
||
|
@@ -318,6 +344,7 @@ def generate_weight(op_type): | |
"elementwise_min", | ||
"elementwise_max", | ||
"elementwise_floordiv", | ||
"elementwise_mod", | ||
]: | ||
for axis in [-1 if len(shape) == 1 else 1]: | ||
self.dims = len(shape) | ||
|
@@ -442,6 +469,10 @@ def generate_input(shape, op_type): | |
return np.random.randint( | ||
low=1, high=10000, size=shape, dtype=np.int32 | ||
) | ||
elif op_type == "elementwise_mod": | ||
return np.random.uniform(low=0.1, high=1.0, size=shape).astype( | ||
np.float32 | ||
) | ||
else: | ||
return np.random.random(shape).astype(np.float32) | ||
|
||
|
@@ -455,6 +486,7 @@ def generate_input(shape, op_type): | |
"elementwise_min", | ||
"elementwise_max", | ||
"elementwise_floordiv", | ||
"elementwise_mod", | ||
]: | ||
for axis in [0, -1]: | ||
self.dims = len(shape) | ||
|
@@ -605,6 +637,10 @@ def generate_input(shape, op_type): | |
return np.random.randint( | ||
low=1, high=10000, size=shape, dtype=np.int32 | ||
) | ||
elif op_type == "elementwise_mod": | ||
return np.random.uniform(low=0.1, high=1.0, size=shape).astype( | ||
np.float32 | ||
) | ||
else: | ||
return np.random.random(shape).astype(np.float32) | ||
|
||
|
@@ -651,6 +687,7 @@ def generate_input(shape, op_type): | |
"elementwise_min", | ||
"elementwise_max", | ||
"elementwise_floordiv", | ||
"elementwise_mod", | ||
]: | ||
for axis in axis_list[j][i]: | ||
self.shape1 = input1_shape | ||
|
@@ -763,6 +800,10 @@ def generate_input(shape, op_type): | |
return np.random.randint( | ||
low=1, high=10000, size=shape, dtype=np.int32 | ||
) | ||
elif op_type == "elementwise_mod": | ||
return np.random.uniform(low=0.1, high=1.0, size=shape).astype( | ||
np.float32 | ||
) | ||
else: | ||
return np.random.random(shape).astype(np.float32) | ||
|
||
|
@@ -772,6 +813,10 @@ def generate_weight(op_type): | |
return np.random.randint( | ||
low=1, high=10000, size=[32], dtype=np.int32 | ||
) | ||
elif op_type == "elementwise_mod": | ||
return np.random.uniform(low=0.1, high=1.0, size=[32]).astype( | ||
np.float32 | ||
) | ||
else: | ||
return np.random.rand(32).astype(np.float32) | ||
|
||
|
@@ -791,6 +836,7 @@ def generate_weight(op_type): | |
"elementwise_min", | ||
"elementwise_max", | ||
"elementwise_floordiv", | ||
"elementwise_mod", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 目前单测精度上有问题,coverage ci无法通过。可能是因为包含有floordiv,需要对对应的输入做修改,如generate_input或者generate_weight,由于np.random.random范围为[0,1.0), 需将np.random.random替换为np.random.uniform。
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. 按照您说的修改后 coverage ci 还是无法通过 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
看着还是有精度diff 是不是所有的generate_input或者generate_weight都需要修改,可以本地环境验证下(CUDA 10.2, TensorRT 7.2.3.4) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
本地 cuda11.7 tensorrt 8.4 的环境可以吗 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
11.7可以作为辅助 建议在https://hub.docker.com/r/paddlepaddle/paddle下拉取10.2环境,当前未通过ci是10.2 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 现在本地的单测已经不报错了,线上的也没有出现上面的精度问题,但是报了一个本地没有出现过的错误 |
||
]: | ||
self.op_type = op_type | ||
for axis in [-1 if len(shape) == 1 else 1]: | ||
|
@@ -840,8 +886,8 @@ def generate_dynamic_shape(attrs): | |
# The input.dims[1] must be equal to the weight's length. | ||
if self.dims == 1: | ||
self.dynamic_shape.min_input_shape = {"input_data": [4]} | ||
self.dynamic_shape.max_input_shape = {"input_data": [256]} | ||
self.dynamic_shape.opt_input_shape = {"input_data": [16]} | ||
self.dynamic_shape.max_input_shape = {"input_data": [64]} | ||
self.dynamic_shape.opt_input_shape = {"input_data": [32]} | ||
elif self.dims == 2: | ||
self.dynamic_shape.min_input_shape = {"input_data": [1, 32]} | ||
self.dynamic_shape.max_input_shape = {"input_data": [4, 32]} | ||
|
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.
elementwise_mod_weight也添加上
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.
已添加