Skip to content

Conversation

@cptspacemanspiff
Copy link
Contributor

@cptspacemanspiff cptspacemanspiff commented Jan 28, 2025

Summary

As I have been using executorch, I have run into issues with dtypes conflict during export, I end up with dtype mismatch during the to_edge process in exir. Unfortunately the current error message is less than clear, this change adds the stack trace from the nodes that have the issues, making it easier to find in your code where the type mismatch is.

Original Error Message:

    raise SpecViolationError(
torch._export.verifier.SpecViolationError: These operators are taking Tensor inputs with mismatched dtypes: defaultdict(<class 'dict'>, {<EdgeOpOverload: aten.cat.default>: schema = aten::cat(Tensor[] tensors, int dim=0) -> Tensor: {'tensors': torch.int32, '__ret_0': torch.int64}})Please make sure the dtypes of the Tensor inputs are the same as the dtypes of the corresponding 

New Error Message:

    raise SpecViolationError(
torch._export.verifier.SpecViolationError: These operators are taking Tensor inputs with mismatched dtypes:

Operator: <EdgeOpOverload: aten.cat.default>: schema = aten::cat(Tensor[] tensors, int dim=0) -> Tensor with args: {'tensors': torch.int32, '__ret_0': torch.int64}
stack trace:   File "/home/nlong/execu-tools/python/execu_tools/encoder_decoder_export.py", line 280, in reset_encode_prefill
    new_tokens = torch.cat((past_decoder_outputs, next_tokens), dim=1)

Please make sure the dtypes of the Tensor inputs are the same as the dtypes of the corresponding outputs.

Changes:

Internally the validator is collecting the errors as they come up into a list, then later if that list is not empty an exception is made.

The only change is that during the collection process I also collect self.node, which happens to be the current node we are evaluating, and add that to the list (as the second item of a tuple). Then when raising the exception we have access to not just the op/args but also the node that was being evaluated.

Makes tracking these down much easier.

Test plan

No testing, aside from being able to use it to fix my problems, it should not have any issues.
self.node is already used to access the "meta" field, needed for the arg validation.

@pytorch-bot
Copy link

pytorch-bot bot commented Jan 28, 2025

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/executorch/7999

Note: Links to docs will display an error until the docs builds have been completed.

⏳ No Failures, 8 Pending

As of commit 777c710 with merge base 9bd18f6 (image):
💚 Looks good so far! There are no failures yet. 💚

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@facebook-github-bot facebook-github-bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jan 28, 2025
@swolchok swolchok added the release notes: exir Changes to any dialects and passes on these dialects, such as memory planning label Jan 28, 2025
Copy link
Contributor

@swolchok swolchok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

Copy link
Contributor

@swolchok swolchok left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks like this broke test_edge_dialect_fails in the linux unittest, please fix and ping me for re-review

@cptspacemanspiff
Copy link
Contributor Author

@swolchok fixed the unit test (it now checks the contents of the first element of the new pair.)

@swolchok swolchok force-pushed the add-better-error-messages-for-type-exir-validators branch from f3519e9 to ad81488 Compare January 28, 2025 21:05
@swolchok swolchok force-pushed the add-better-error-messages-for-type-exir-validators branch from ad81488 to 777c710 Compare January 28, 2025 22:29
@swolchok swolchok merged commit 3be1c5e into pytorch:main Jan 28, 2025
42 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. release notes: exir Changes to any dialects and passes on these dialects, such as memory planning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants