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

Support regex-style matching for Any and Oneof #82853

Closed

Commits on Aug 4, 2022

  1. Supprot regex-style matching for Any and Oneof

    [ghstack-poisoned]
    SherlockNoMad committed Aug 4, 2022
    Configuration menu
    Copy the full SHA
    b0bf069 View commit details
    Browse the repository at this point in the history

Commits on Aug 11, 2022

  1. Update on "Support regex-style matching for Any and Oneof"

    Using following pattern with regex ops
    ```
        def pattern(a):
            y = a.relu()
            z = torch.ops.pseudo.oneof(y, ops=["relu", "sigmoid"])
            return z        
    ```
    
    It will match both of the following functions 
    
    ```
        def forward(x):
            x = x.relu()
            return x.sigmoid()
    
        def forward(y):
            z = y.relu()
            return z.relu()
    ```
    
    
    
    
    [ghstack-poisoned]
    SherlockNoMad committed Aug 11, 2022
    Configuration menu
    Copy the full SHA
    4965784 View commit details
    Browse the repository at this point in the history

Commits on Aug 12, 2022

  1. Update on "Support regex-style matching for Any and Oneof"

    
    pseudo.any is a wildcard node that can be matched with any fx node with arbitrary number of inputs and outputs.
    For example, to match relu followed by one fx node:
    ```
        def pattern(a):
            y = a.relu()
            z = torch.ops.pseudo.any(y)
            return z
    ```
    
    
    pseudo.oneof is a special node that can be matched with a fx node whose target is in the permissible list.
    `targets` must be be a list of qualified name for operators, e.g. ["operator.add", "torch.sigmoid",
    "torch.ops.aten.foo", "torch.ops.prims.bar"]
    
    For example, using following pattern with pseudo.oneof
    ```
        def pattern(a):
            y = a.relu()
            z = torch.ops.pseudo.oneof(y, targets=["relu", "torch.sigmoid", "operator.add"])
            return z
    ```
    
    It will have 3 matches in the following function
    ```
        def forward(y):
            z = y.relu()
            x = z.relu()    # first match
    
            x = x.relu()
            x = torch.sigmoid(x)    # second match
    
            x = x.relu()
            return x + 1    # third match
    ```
    
    [ghstack-poisoned]
    SherlockNoMad committed Aug 12, 2022
    Configuration menu
    Copy the full SHA
    6f28a80 View commit details
    Browse the repository at this point in the history