Describe the bug
Describe the bug
In tpu-mlir/lib/Dialect/Top/Canonicalize/Relu.cpp, the conversion pattern TopMoveReluAheadConcatPattern moves the Relu operation ahead of Concat.
However, during this optimization pass, when a new ReluOp is created inside the loop, the original relu_limit attribute is lost. This causes unexpected behavior or bugs when the model relies on a specific relu_limit.
Source Code Location
- File:
tpu-mlir/lib/Dialect/Top/Canonicalize/Relu.cpp
- Pattern:
TopMoveReluAheadConcatPattern::matchAndRewriteImpl
At line 72, the relu_limit is fetched:
auto relu_limit = op.getReluLimit();
But at line 90, the new ReluOp is created without passing this attribute:
auto newOp = rewriter.create<ReluOp>(
NameLoc::get(nameAttr), formerOp->getOperand(i).getType(),
ArrayRef<Value>{formerOp->getOperand(i)});
Suggested Fix
The relu_limit should be forwarded when creating the new ReluOp. It should be updated to something like:
auto newOp = rewriter.create<ReluOp>(
NameLoc::get(nameAttr), formerOp->getOperand(i).getType(),
ArrayRef<Value>{formerOp->getOperand(i)},
relu_limit); // Pass the original relu_limit here
Steps to reproduce
1. Run model conversion pipeline with a model containing a Relu layer that has a specific `relu_limit` value.
2. The `TopMoveReluAheadConcatPattern` canonicalization pass is triggered.
3. The newly created `ReluOp` loses its original `relu_limit` attribute.
Expected behavior
The TopMoveReluAheadConcatPattern optimization pass should preserve and forward the original relu_limit attribute when recreating the ReluOp ahead of Concat.
Error logs / stack trace
No specific crash log, but a logic bug in `tpu-mlir/lib/Dialect/Top/Canonicalize/Relu.cpp`:
At line 72, the `relu_limit` is fetched:
auto relu_limit = op.getReluLimit();
But at line 90, the new `ReluOp` is created without passing this attribute:
auto newOp = rewriter.create<ReluOp>(
NameLoc::get(nameAttr), formerOp->getOperand(i).getType(),
ArrayRef<Value>{formerOp->getOperand(i)});
TPU-MLIR version
commit 18c49f9
Target chip
bm1684x
Source framework / model
No response
OS / Docker image
No response
Describe the bug
Describe the bug
In
tpu-mlir/lib/Dialect/Top/Canonicalize/Relu.cpp, the conversion patternTopMoveReluAheadConcatPatternmoves theReluoperation ahead ofConcat.However, during this optimization pass, when a new
ReluOpis created inside the loop, the originalrelu_limitattribute is lost. This causes unexpected behavior or bugs when the model relies on a specificrelu_limit.Source Code Location
tpu-mlir/lib/Dialect/Top/Canonicalize/Relu.cppTopMoveReluAheadConcatPattern::matchAndRewriteImplAt line 72, the
relu_limitis fetched:auto relu_limit = op.getReluLimit();But at line 90, the new
ReluOpis created without passing this attribute:Suggested Fix
The
relu_limitshould be forwarded when creating the newReluOp. It should be updated to something like:Steps to reproduce
Expected behavior
The
TopMoveReluAheadConcatPatternoptimization pass should preserve and forward the originalrelu_limitattribute when recreating theReluOpahead ofConcat.Error logs / stack trace
TPU-MLIR version
commit 18c49f9
Target chip
bm1684x
Source framework / model
No response
OS / Docker image
No response