[Relax][PyTorch] Simplify tensor args conversion in Dynamo#18726
[Relax][PyTorch] Simplify tensor args conversion in Dynamo#18726mshr-h wants to merge 3 commits intoapache:mainfrom
Conversation
Summary of ChangesHello @mshr-h, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request enhances the integration between PyTorch Dynamo and TVM Relax by optimizing tensor data transfer and improving GPU compilation. It introduces a more efficient mechanism for converting PyTorch tensors to TVM's internal representation and ensures proper scheduling is applied when targeting CUDA devices. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces two key improvements for the PyTorch Dynamo frontend. First, it leverages DLPack for converting PyTorch tensors to TVM tensors, which is a great performance optimization that avoids unnecessary data copies via NumPy, especially for GPU tensors. Second, it adds the DefaultGPUSchedule pass for CUDA targets, which is essential for generating runnable and performant code on GPUs. Both changes are valuable. I have one suggestion to consider generalizing the GPU support for better scalability in the future.
| if device.type == "cuda": | ||
| with target: | ||
| mod = tvm.tir.transform.DefaultGPUSchedule()(mod) |
There was a problem hiding this comment.
This correctly adds the default GPU scheduling pass for CUDA, which is a great step for enabling GPU support.
To make this more scalable for other GPU backends (e.g., ROCm, Metal), it would be beneficial to generalize this check. tvm.tir.transform.DefaultGPUSchedule is not CUDA-specific.
A future improvement could be to check for any GPU device type and apply this pass. This would need to be done in conjunction with updating the device/target creation logic around line 112 to support more GPU types.
|
likely with latest tvm-ffi, we don't need dlpack anymore, just pass in torch.Tensor directly should be fine |
|
thanks. updated as suggested. |
e8e8f7c to
7fadb76
Compare
As per title.