Skip to content

[ExecuTorch] Cannot Use Dynamic Index to Select #2189

Open

Description

@YifanShenSZ

This toy model fails in ExecuTorch

        class M(torch.nn.Module):
            def forward(self, float_arr, int_arr):
                dynamic_index = int_arr[1]
                float_arr[dynamic_index] = 12.95
                return float_arr

due to

E               torch._dynamo.exc.UserError: Consider annotating your code using torch._constrain_as_*(). Could not guard on data-dependent expression u0 (unhinted: u0).  (Size-like symbols: none)
E               
E               Potential framework code culprit (scroll up for full backtrace):
E                 File "<eval_with_key>.223", line 8, in forward
E                   l_float_arr_[dynamic_index] = 12.95;  setitem = l_float_arr_;  dynamic_index = None
E               
E               For more information, run with TORCH_LOGS="dynamic"
E               For extended logs when we create symbols, also add TORCHDYNAMO_EXTENDED_DEBUG_CREATE_SYMBOL="u0"
E               If you suspect the guard was triggered from C++, add TORCHDYNAMO_EXTENDED_DEBUG_CPP=1
E               For more debugging help, see https://docs.google.com/document/d/1HSuTTVvYH1pTew89Rtpeu84Ht3nQEFTYhAX3Ypa_xJs/edit?usp=sharing
E               
E               For C++ stack trace, run with TORCHDYNAMO_EXTENDED_DEBUG_CPP=1
E               For more information about this error, see: https://pytorch.org/docs/main/generated/exportdb/index.html#constrain-as-size-example

But some other dynamic indexing models are fine, e.g.

        class IndexPutModel(torch.nn.Module):
            def forward(self, x, position, val):
                y = x.clone()
                y[:, position] = val
                return y

Activity

  1. added
    bug
    on Apr 5, 2024
  2. YifanShenSZ commented on Apr 16, 2024

    @YifanShenSZ
    ContributorAuthor

    Similarly, dynamic slice would also fail

            class DynamicSlicer(torch.nn.Module):
                def forward(self, x, context_length):
                    return x[context_length:, :, :]
    

    due to

    torch._dynamo.exc.Unsupported: Dynamic slicing on data-dependent value is not supported
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions