#4377·TensorRT

onnx_graphsurgeon.GraphPattern():The order in which the nodes are added affects the success of the match.

Author: peanutPodCreated Mar 6, 2025Updated Sep 13, 2026

`

def get_plugin_pattern(self):

    pattern = gs.GraphPattern()
    input0=pattern.variable()
    

    def check_clip_node(node):
        if "min" in node.attrs or "max" in node.attrs:
            return True
        if len(node.inputs) >1:
            return True
        return False

    clip01_min=pattern.constant()
    clip01_max=pattern.variable()
    clip01=pattern.add(
        "clip01",
        op="Clip",
        inputs=[input0,clip01_min,clip01_max],
        check_func=check_clip_node,
        num_output_tensors=1)
    
    clip02_min=pattern.variable()
    clip02_max=pattern.constant()
    clip02=pattern.add(
        "clip02",
        op="Clip",
        inputs=[clip01,clip02_min,clip02_max],
        check_func=check_clip_node,
        num_output_tensors=1)
    
    clip04_min=pattern.constant()
    clip04_max=pattern.variable()
    clip04=pattern.add(
        "clip04",
        op="Clip",
        inputs=[clip02,clip04_min,clip04_max],
        check_func=check_clip_node,
        num_output_tensors=1)
    
    sub01_constant=pattern.constant()
    sub01=pattern.add(
        "sub01",
        op="Sub",
        inputs=[sub01_constant,clip02])
    
    clip03_min=pattern.constant()
    clip03_max=pattern.variable()
    clip03=pattern.add(
        "clip03",
        op="Clip",
        inputs=[sub01,clip03_min,clip03_max],
        check_func=check_clip_node,
        num_output_tensors=1)
    
    # clip04_min=pattern.constant()  #Putting the pattern here will match fail
    # clip04_max=pattern.variable()
    # clip04=pattern.add(
    #     "clip04",
    #     op="Clip",
    #     inputs=[clip02,clip04_min,clip04_max],
    #     check_func=check_clip_node,
    #     num_output_tensors=1)

    
    div01=pattern.add(
        "div01",
        op="Div",
        inputs=[clip04,clip03])
    
    log01=pattern.add(
        "log01",
        op="Log",
        inputs=[div01])        

    pattern.set_output_tensors([log01])

    return pattern`

if I move "clip04" to # clip04_min,I can not find pattern,else i will find pattern,who can tell me why?

onnx graph:

Image