Skip to content

Support dynamic mhlo.torch_index_select and add test. - #2598

Merged
stellaraccident merged 1 commit into
iree-org:mainfrom
shanshanpt:support_dynamic_torch_index_select
Jul 23, 2020
Merged

stellaraccident merged 1 commit into
iree-org:mainfrom
shanshanpt:support_dynamic_torch_index_select

Conversation

@shanshanpt

Copy link
Copy Markdown
Contributor

Support dynamic mhlo.torch_index_select and add test.

@shanshanpt

Copy link
Copy Markdown
Contributor Author

Add ShapeBuilder of mhlo TorchIndexSelectOp, that support dynamic shape TorchIndexSelectOp.

@stellaraccident stellaraccident left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks! Looks good overall with some small comments.

torchIndexSelectOp.input().getType().cast<RankedTensorType>();
auto indicesType =
torchIndexSelectOp.index().getType().cast<RankedTensorType>();
if (!paramsType || !indicesType) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since you are checking for nullptr, what you want above is dyncast<>, not cast<>. cast will never return nullptr and will assert fail on a mismatched type.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

int64_t indicesRank = indicesType.getRank();

std::vector<int64_t> shape(paramsType.getShape());
int64_t axisValue = *(axis.getRawData());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I think you want axis.getSExtValue() here and on the next line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

GENERATE_RANKED_DIM_OP(paramsShapeValue, i);
}
} else {
if (resultShapeRank != paramsRank + indicesRank - 1 - batchDimValue) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nit: can you add parens around the rhs?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -0,0 +1,58 @@
// RUN: iree-run-mlir %s -iree-hal-target-backends=llvm-ir -input-value="2x2xi32=[6, 7] [8, 9]" -input-value="2x2x2x2xi32=[[[0, 1] [1, 0]] [[0, 0] [1, 1]]] [[[1, 1] [0, 0]] [[0, 1] [1, 0]]]" | IreeFileCheck %s

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can you point me to (or add a test) where we are testing the wrap-around (negative index) behavior?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

In tensorflow, axis and batch_dims can be negative.
But the function TorchIndexSelectOpConversion in HLOToLinalgOnBuffers.cpp disable the nagtive, so modify the code and add the negative case.

@shanshanpt
shanshanpt force-pushed the support_dynamic_torch_index_select branch from c4caf57 to 97eb1b8 Compare July 22, 2020 03:51
@shanshanpt
shanshanpt force-pushed the support_dynamic_torch_index_select branch from 97eb1b8 to ced3b0d Compare July 22, 2020 03:59
@shanshanpt

Copy link
Copy Markdown
Contributor Author

@googlebot I signed it!

@stellaraccident
stellaraccident merged commit 7a66e64 into iree-org:main Jul 23, 2020
@rsuderman rsuderman mentioned this pull request Jul 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants