-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Fix Customize Optimization tutorial import error #18584 #18697
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
base: main
Are you sure you want to change the base?
Conversation
- Add prerequisite note about building TVM with CUDA support - Add error handling for 'tvm_ffi' import failure - Print helpful error messages to stderr - Provide link to build instructions Fixes apache#18584
Summary of ChangesHello @AshwiniBokka, 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 addresses a common 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. 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code Review
This pull request addresses an import error in the 'Customize Optimization' tutorial that occurs when TVM is not built with CUDA support. The changes include adding a note about the CUDA dependency and implementing a try-except block to catch the ImportError and provide a user-friendly error message. The changes are well-aligned with the problem description. My review includes a critical fix for a Byte Order Mark (BOM) character that was introduced, and a suggestion to make the error handling more robust by checking for CUDA feature availability directly instead of parsing the exception message.
| @@ -1,4 +1,4 @@ | |||
| # Licensed to the Apache Software Foundation (ASF) under one | |||
| # Licensed to the Apache Software Foundation (ASF) under one | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| try: | ||
| import tvm.relax.backend.cuda.cublas as _cublas | ||
| except ImportError as e: | ||
| if "tvm_ffi" in str(e): | ||
| import sys | ||
| print("Error: TVM needs to be built with CUDA support.", file=sys.stderr) | ||
| print("Please build TVM from source with CUDA enabled.", file=sys.stderr) | ||
| print("See: https://tvm.apache.org/docs/install/from_source.html", file=sys.stderr) | ||
| sys.exit(1) | ||
| else: | ||
| raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Checking the exception string for "tvm_ffi" is a bit brittle, as the error message could change in future TVM versions. A more robust approach is to use tvm.runtime.enabled("cuda") to check if CUDA support is compiled in. This directly checks for the feature availability rather than relying on a specific error message string.
| try: | |
| import tvm.relax.backend.cuda.cublas as _cublas | |
| except ImportError as e: | |
| if "tvm_ffi" in str(e): | |
| import sys | |
| print("Error: TVM needs to be built with CUDA support.", file=sys.stderr) | |
| print("Please build TVM from source with CUDA enabled.", file=sys.stderr) | |
| print("See: https://tvm.apache.org/docs/install/from_source.html", file=sys.stderr) | |
| sys.exit(1) | |
| else: | |
| raise | |
| try: | |
| import tvm.relax.backend.cuda.cublas as _cublas | |
| except ImportError: | |
| import tvm.runtime | |
| if not tvm.runtime.enabled("cuda"): | |
| import sys | |
| print("Error: This tutorial requires TVM to be built with CUDA support.", file=sys.stderr) | |
| print("Please build TVM from source with CUDA enabled.", file=sys.stderr) | |
| print("See: https://tvm.apache.org/docs/install/from_source.html", file=sys.stderr) | |
| sys.exit(1) | |
| else: | |
| raise |
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
| https://www.apache.org/licenses/LICENSE-2.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why do we need to update license here?
| from tvm.relax.frontend import nn | ||
|
|
||
| # Note: This tutorial requires TVM to be built with CUDA support. | ||
| # If you encounter 'No module named ''tvm_ffi''' error, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The statement might not be correct, tvm_ffi is now a independent repo (and 3rdparty in tvm), I think we just need to pip install tvm-ffi if we find the No module named tvm_ffi error.
Fixes #18584
Problem
The tutorial
docs/how_to/tutorials/customize_opt.pyfails with "No module named 'tvm_ffi'" when TVM is not built. This happens because the tutorial importstvm.relax.backend.cuda.cublaswhich requires TVM to be built with CUDA support.Solution
Changes
Testing
Before