Skip to content

preseg optimization pass - merge neighboring PadOp#2490

Merged
jjsjann123 merged 0 commit intopreseg_propagate_padfrom
preseg_propagate_pad_merge_pad
Jul 25, 2024
Merged

preseg optimization pass - merge neighboring PadOp#2490
jjsjann123 merged 0 commit intopreseg_propagate_padfrom
preseg_propagate_pad_merge_pad

Conversation

@jjsjann123
Copy link
Collaborator

@jjsjann123 jjsjann123 commented Jun 28, 2024

multiple cat would ended up having their PadOp being pushed to the same spot giving us a chain of PadOp. The added fusion ir pass tries to merge neighboring PadOp as one.

@jjsjann123 jjsjann123 changed the title Preseg propagate pad merge pad [WIP] Preseg propagate pad merge pad Jun 28, 2024
Base automatically changed from preseg_propagate_pad_binary_op to preseg_propagate_pad July 1, 2024 16:43
@jjsjann123 jjsjann123 force-pushed the preseg_propagate_pad_merge_pad branch from f27a1b5 to b2fca30 Compare July 3, 2024 09:25
@jjsjann123 jjsjann123 changed the title [WIP] Preseg propagate pad merge pad preseg optimization pass - merge neighboring PadOp Jul 3, 2024
@jjsjann123 jjsjann123 marked this pull request as ready for review July 3, 2024 09:44
Comment on lines +459 to +461
if (pad_out->uses().size() != 1 || !pad_out->uses()[0]->isA<PadOp>()) {
break;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think we might also need to prove that each pad width has the same sign in producer and consumer, or at least that the producer sign is positive. Otherwise, we might have something like the following:

auto tv1 = pad(tv0, {0, -1}, 0);
auto tv2 = pad(tv1, {0, 1}, 0); // same as tv0 with last element replaced by 0

If we're not careful here we would replace this with a pad by {0, 0}. This simple example could sneak by us when using symbolic pad widths.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Thanks for pointing this out (as well as the comment here). I was fooled by the comment #2373 (comment).

auto tv1 = pad(tv0, {0, -1}, 0);
auto tv2 = pad(tv1, {0, 1}, 0); // same as tv0 with last element replaced by 0

I'm wondering if we can still merge the two pads even with symbolic pad widths. i.e. shouldn't concretization have already inserted logic to ensure that runtime value isn't going to change the semantics? I'll try to chat with you offline on this one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Hmm, but we don't have a single op that can set just the last element to 0, so what would the merged case be in this case? I agree that we can handle symbolic pad widths I think, it just might need some help. You're right that this could potentially become a concretization thing, similar to #511 .

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

but we don't have a single op that can set just the last element to 0

oh sorry I misread that earlier. It's the shrink then pad which alters the value in the output. Yeah we cannot do that. But we would be able to merge the other direction. I'll fix it up.

Thanks a ton for the example. 🙇

@jjsjann123 jjsjann123 merged commit 37578eb into preseg_propagate_pad Jul 25, 2024
@jjsjann123 jjsjann123 deleted the preseg_propagate_pad_merge_pad branch July 25, 2024 09:30
@jjsjann123
Copy link
Collaborator Author

in the later refactor, it no longer makes sense to keep this PR separate.

But I did address @jacobhinkle's comment in the original PR.

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.

2 participants