Skip to content

Commit

Permalink
[onnx] handle dynamic padSize tensor onnx.Pad
Browse files Browse the repository at this point in the history
  • Loading branch information
PhaneeshB committed Apr 23, 2024
1 parent c1967b6 commit 897d0f0
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/Conversion/TorchOnnxToTorch/DefaultDomainGtoP.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1319,9 +1319,18 @@ void mlir::torch::onnx_c::populateDefaultDomainGtoP(
"expect 1-d pad tensor");

int64_t padsSize = padsShape[0];
if (padsSize == Torch::kUnknownSize)
return rewriter.notifyMatchFailure(binder.op,
"pad length is unknown");
if (padsSize == Torch::kUnknownSize) {
// As per onnx.Pad documentation, padSize = 2*num_data_axes
// (if axes param not passed). Need to be updated when adding
// support for `axes` param.
auto dataOpTy = data.getType().cast<Torch::ValueTensorType>();
TensorType dataTensor = dataOpTy.toBuiltinTensor();
if (!dataTensor || !dataTensor.hasRank())
return rewriter.notifyMatchFailure(
binder.op, "pad length unknown and data operand unranked");
int64_t dataRank = dataTensor.getRank();
padsSize = 2 * dataRank;
}

Value constantValue;
if (binder.getNumOperands() >= 3) {
Expand Down

0 comments on commit 897d0f0

Please sign in to comment.