Skip to content

Commit

Permalink
Fix PReluOp weight mapping bug in CodeGen.
Browse files Browse the repository at this point in the history
1. The backend of PReluOp uses stride descriptions to represent data, so we
   should not align with the EU number. (loc: nodechip_prelu_local.c:36)

Change-Id: I18e903acaebaf35e5762c76df973d7e1e978f8f9
  • Loading branch information
luluman committed Jan 9, 2023
1 parent 2ae259b commit 93d89e3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
3 changes: 2 additions & 1 deletion lib/Dialect/Tpu/Transforms/LayerGroup/LayerGroupUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,8 @@ bool is_eu_align(Value opd) {
// Eu align rule may be different in different platforms
auto op = *opd.getUsers().begin();
if (isWeightValue(opd)) {
if (isa<tpu::Conv1DOp, tpu::Conv2DOp, tpu::Conv3DOp, tpu::DeconvOp>(op) &&
if (isa<tpu::Conv1DOp, tpu::Conv2DOp, tpu::Conv3DOp, tpu::DeconvOp,
tpu::PReluOp>(op) &&
(opd == op->getOperand(1) || opd == op->getOperand(2))) {
return false;
}
Expand Down
17 changes: 9 additions & 8 deletions python/test/test_onnx.py
Original file line number Diff line number Diff line change
Expand Up @@ -2401,14 +2401,15 @@ def test_Reciprocal(self, case_name):
self.onnx_and_test(graph_def, input_data={"input": input_data})

def test_PRelu(self, case_name):
input_shape = [3, 5, 100, 100]
slope_shape = [1, 5, 1, 1]
output_shape = [3, 5, 100, 100]
slope = helper.make_tensor(name='slope',
data_type=onnx.TensorProto.FLOAT,
dims=slope_shape,
vals=[0.40, 0.37, 0.31, 0.19, 0.11])

input_shape = [3, 128, 100, 100]
slope_shape = [1, 128, 1, 1]
output_shape = [3, 128, 100, 100]
slope = helper.make_tensor(
name="slope",
data_type=onnx.TensorProto.FLOAT,
dims=slope_shape,
vals=np.random.rand(*slope_shape).astype(np.float32),
)
inputs = [helper.make_tensor_value_info("input", TensorProto.FLOAT, input_shape)]
outputs = [helper.make_tensor_value_info('output', TensorProto.FLOAT, output_shape)]
prelu_def = helper.make_node("PRelu", ["input", "slope"], ["output"])
Expand Down
2 changes: 0 additions & 2 deletions python/transform/CaffeConverter.py
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,6 @@ def convert_scale_op(self, layer):
output_shape = input_shape
attrs = {'name': self.get_loc(layer.top[0])}
assert (num_dims == 4 or num_dims == 2)
if num_dims == 2:
raise RuntimeError("Not support now, shape {}".format(input_shape))
if len(layer.bottom) == 2:
op1 = self.getOperand(layer.bottom[1])
input_shape1 = self.getShape(layer.bottom[1])
Expand Down

0 comments on commit 93d89e3

Please sign in to comment.