Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
peanutPod opened this issue Mar 6, 2025 · 0 comments

Comments

@peanutPod
Copy link

peanutPod commented Mar 6, 2025

`

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

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

No branches or pull requests

1 participant