-
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
[Infer Symbolic Shape No.27][BUAA]edit_distance #67117
Merged
luotao1
merged 17 commits into
PaddlePaddle:develop
from
MufanColin:cinn_edit_distance_latest
Aug 12, 2024
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
09dba7e
Fixd edit_distance op
MufanColin 8f94859
Added one more constraint
MufanColin c374684
Added one more constraint
MufanColin ad305a4
Fixed conflicts
MufanColin 5ceca62
Resolved suggested changes
MufanColin 493fda8
Added symbol:: before DimExpr
MufanColin 8f3361f
Fixed errors
MufanColin a883a89
Removed two unnecessary variables and added .shape()
MufanColin a60fe22
Fixed typos
MufanColin 48e09e9
Revert to a previous version
MufanColin 7f8f1f3
added .shape()
MufanColin ed243fd
added .shape
MufanColin 3d717d8
added .shape()
MufanColin 1c945ac
Try to resolve type conflicts
MufanColin 0a0bbcd
Try to resolve type conflicts
MufanColin 9972525
Try to resolve type conflicts
MufanColin 45d2827
Try to resolve type conflicts
MufanColin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -782,6 +782,67 @@ bool ConcatOpInferSymbolicShape(pir::Operation *op, | |
return true; | ||
} | ||
|
||
bool EditDistanceOpInferSymbolicShape( | ||
pir::Operation *op, pir::InferSymbolicShapeContext *infer_context) { | ||
const auto &hyps_shape_or_data = | ||
infer_context->GetShapeOrDataForValue(op->operand_source(0)); | ||
const auto &refs_shape_or_data = | ||
infer_context->GetShapeOrDataForValue(op->operand_source(1)); | ||
|
||
const auto &hyps_dims = hyps_shape_or_data.shape(); | ||
const auto &refs_dims = refs_shape_or_data.shape(); | ||
|
||
PADDLE_ENFORCE_EQ( | ||
hyps_dims.size(), | ||
2, | ||
phi::errors::InvalidArgument( | ||
"Input(Hyps) must be a 2-D Tensor, but received rank %u.", | ||
hyps_dims.size())); | ||
PADDLE_ENFORCE_EQ( | ||
refs_dims.size(), | ||
2, | ||
phi::errors::InvalidArgument( | ||
"Input(Refs) must be a 2-D Tensor, but received rank %u.", | ||
refs_dims.size())); | ||
|
||
infer_context->AddEqualCstr(hyps_dims[0], refs_dims[0]); | ||
|
||
bool has_lengths = op->operand_source(2) && op->operand_source(3); | ||
if (has_lengths) { | ||
const auto &hypslength_shape_or_data = | ||
infer_context->GetShapeOrDataForValue(op->operand_source(2)); | ||
const auto &refslength_shape_or_data = | ||
infer_context->GetShapeOrDataForValue(op->operand_source(3)); | ||
|
||
infer_context->AddEqualCstr(hypslength_shape_or_data.shape()[0], | ||
hyps_dims[0]); | ||
|
||
infer_context->AddEqualCstr(refslength_shape_or_data.shape()[0], | ||
refs_dims[0]); | ||
|
||
infer_context->AddEqualCstr(hypslength_shape_or_data.shape()[0], | ||
refslength_shape_or_data.shape()[0]); | ||
} else { | ||
symbol::DimExpr one = symbol::DimExpr(1); | ||
|
||
infer_context->AddEqualCstr(hyps_dims[1], one); | ||
infer_context->AddEqualCstr(refs_dims[1], one); | ||
} | ||
|
||
symbol::ShapeOrDataDimExprs refs_shape_or_data_exprs( | ||
symbol::TensorShapeOrDataDimExprs( | ||
std::vector<symbol::DimExpr>{refs_dims})); | ||
infer_context->SetShapeOrDataForValue(op->result(0), | ||
refs_shape_or_data_exprs); | ||
Comment on lines
+832
to
+836
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. 这里命名最好用out_shape_or_data_exprs,out和refs的shape相同,你这里的操作相当于是把refs的shape区取出来给out的符号表达初始化,可以下一个PR顺带修改下 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. 收到,我下一个 PR 改一下。 |
||
|
||
symbol::ShapeOrDataDimExprs single_dim_expr(symbol::TensorShapeOrDataDimExprs( | ||
std::vector<symbol::DimExpr>{symbol::DimExpr(1)})); | ||
infer_context->SetShapeOrDataForValue( | ||
op->result(1), symbol::ShapeOrDataDimExprs({single_dim_expr})); | ||
|
||
return true; | ||
} | ||
|
||
bool FakeQuantizeMovingAverageAbsMaxOpInferSymbolicShape( | ||
pir::Operation *op, pir::InferSymbolicShapeContext *infer_context) { | ||
const symbol::ShapeOrDataDimExprs &x_shape = | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
这个分支里这四个值的0维都是相等的,是不是少了一个约束
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.
我再添加一个
infer_context->AddEqualCstr(hypslength_shape_or_data, refslength_shape_or_data);
吗?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.
可以