Skip to content

Negative pad decomposition#7017

Open
djstefanovicTT wants to merge 4 commits intomainfrom
djstefanovic/negativepad
Open

Negative pad decomposition#7017
djstefanovicTT wants to merge 4 commits intomainfrom
djstefanovic/negativepad

Conversation

@djstefanovicTT
Copy link
Contributor

Ticket

closes #6959

Problem description

PyTorch supports negative padding in pad op as cropping. TTNN padOp does not allow this and causes errors.

What's changed

Added decomposition to ttir.slice_static op if there is negative padding.

Checklist

  • New/Existing tests provide coverage for changes

@codecov-commenter
Copy link

codecov-commenter commented Feb 12, 2026

Codecov Report

❌ Patch coverage is 95.74468% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 69.27%. Comparing base (b679ac5) to head (a99f9d2).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...TIRToTTIRDecomposition/TTIRToTTIRDecomposition.cpp 97.56% 1 Missing ⚠️
lib/Dialect/TTNN/IR/TTNNOps.cpp 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #7017      +/-   ##
==========================================
+ Coverage   69.26%   69.27%   +0.01%     
==========================================
  Files         384      384              
  Lines       67207    67254      +47     
==========================================
+ Hits        46550    46593      +43     
- Misses      20657    20661       +4     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@azecevicTT azecevicTT left a comment

Choose a reason for hiding this comment

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

If metal isn't going to support negative padding, it makes more sense to have this as a canonicalization pattern.

Comment on lines 2612 to 2625
// Compute the slice result type.
RankedTensorType sliceResultType;
if (needPad) {
// Intermediate type: sliced shape.
SmallVector<int64_t> slicedShape;
for (size_t i = 0; i < inputShape.size(); i++) {
slicedShape.push_back(sliceEnds[i] - sliceBegins[i]);
}
sliceResultType =
RankedTensorType::get(slicedShape, inputType.getElementType());
} else {
// Final output type when only slicing is needed.
sliceResultType = cast<RankedTensorType>(op.getType());
}
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO you don't have to optimize the case for the case when padding is not needed, you can put the calculation of the shape in the previous loop, that way it's much more obvious what the intention is.

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.

[TTIR] Decompose TTIR.Pad with negative padding with TTIR_Slice

3 participants