DFPatternCallback match not complete

Hello,I am using DFPatternCallback to match some pattern in my module and rewriting its callback function to modify some value in it, but it doesn’t work as I presumed.

My network is from pytorch and look like this:

No nodes are added or deleted, so the architecture won’t change after my callback function.

and i am matching a pattern ,codes are:

self.input=wildcard()
self.weight=is_constant()
self.conv=is_op("nn.conv2d")
self.conv_result = self.conv(self.input,self.weight)
self.bias = is_constant()
self.add = is_op("add")
self.add_result = self.add(self.conv_result, self.bias)
self.relu = is_op("nn.relu")
self.relu_result = self.relu(self.add_result)
self.weight2 = is_constant()
self.conv2 = is_op("nn.conv2d")
self.pattern = self.conv2(self.relu_result,self.weight2)

I am imagine the 1st,2nd,3rd add node would be matched; but it turns out that only 1st and 3rd one is modified.

So my question is why is this pattern match not complete? and how can i do to make it work?

Thank you!

well, since you have two conv2d in your pattern, I think it makes sense that the pattern matches against the 1st and and the 3rd conv2d. Since the second conv2d would be matched as part of the first match, it should be gone after the first rewriting.

Thank you for replying. So after a node is matched, it won’t be able to be matched again? My rewriting doesn’t change its architecture, so the 2nd conv2d would still be there after the rewriting

I see what you mean. Yeah, I think if a node is matched, it won’t be considered for another match, even if the rewrite callback returns the same node as is. I’m not 100% sure if that’s how it works, but if that’s what you are seeing, that makes sense to me.

Otherwise, the behavior of the next matching is affected by what the rewrite callback of the first match would return, which doesn’t sound right.

That sounds reasonable to me now~ I guess I’ll have to find another way to do it. Thank you.