Skip to content

Allow qnn to use the IR from torch.export.export#4942

Merged
facebook-github-bot merged 18 commits intopytorch:mainfrom
cccclai:migrate_to_export
Sep 6, 2024
Merged

Allow qnn to use the IR from torch.export.export#4942
facebook-github-bot merged 18 commits intopytorch:mainfrom
cccclai:migrate_to_export

Conversation

@cccclai
Copy link
Copy Markdown
Contributor

@cccclai cccclai commented Aug 28, 2024

It is a workaround for #4627

@pytorch-bot
Copy link
Copy Markdown

pytorch-bot Bot commented Aug 28, 2024

🔗 Helpful Links

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

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

✅ No Failures

As of commit 8ec839f with merge base f55ce1f (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 Aug 28, 2024
@cccclai cccclai requested review from chiwwang and shewu-quic August 29, 2024 09:24
@cccclai cccclai changed the title migrate to torch.export.export Allow qnn to use the IR from torch.export.export Aug 29, 2024
@cccclai
Copy link
Copy Markdown
Contributor Author

cccclai commented Aug 29, 2024

Hi @shewu-quic @chiwwang, could you let me know if this change meets the need? Thanks.

@chiwwang
Copy link
Copy Markdown
Contributor

Thank you! This looks ok. We will give it a try.

Copy link
Copy Markdown
Collaborator

@shewu-quic shewu-quic left a comment

Choose a reason for hiding this comment

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

Thanks for your effort.
It works well for me.

Comment thread examples/models/llama2/export_llama_lib.py Outdated
Comment thread extension/llm/export/builder.py Outdated
@cccclai
Copy link
Copy Markdown
Contributor Author

cccclai commented Aug 30, 2024

Great. Just apply suggestion

@cccclai cccclai requested a review from kimishpatel August 30, 2024 10:09
@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Comment thread extension/llm/export/builder.py Outdated
Comment on lines +169 to +179
if self.export_fn == torch.export.export:
self.pre_autograd_graph_module = self.export_fn(
self.model,
self.example_inputs,
dynamic_shapes=dynamic_shape,
strict=True,
).module()
else:
self.pre_autograd_graph_module = self.export_fn(
self.model, self.example_inputs, dynamic_shapes=dynamic_shape
)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Why do you need this if you already patch export_fn

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

And if this is because of differing APIs then I would rather check for qnn backend here instead of using export_fn

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

Comment thread extension/llm/export/builder.py Outdated
self.pre_autograd_graph_module = capture_pre_autograd_graph(
self.model, self.example_inputs, dynamic_shapes=dynamic_shape
)
if self.args.qnn:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nit: do we need to pass entire set of args? Can we not just pass in backend information? or is_qnn?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

So I'm not sure it's qnn specific and I feel like maybe coreml/mps might run into similar issue if they use pt2e flow....

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The current backend information is args.qnn, args.coreml and args.mps...We can refactor it to make it cleaner.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

So I'm not sure it's qnn specific and I feel like maybe coreml/mps might run into similar issue if they use pt2e flow....

Yes... agreed on this 😮
Is there any other backend trying the pt2e flow? (i.e., going through convert_pt2e())

Copy link
Copy Markdown
Contributor

@kimishpatel kimishpatel left a comment

Choose a reason for hiding this comment

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

So i dont really like the kind of spaghetti this code has become, but that no the fault of the author and we need to unblock qnn delegate. So stamping

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot
Copy link
Copy Markdown
Contributor

@cccclai has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator.

@facebook-github-bot facebook-github-bot merged commit 1cc8503 into pytorch:main Sep 6, 2024
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants