You are viewing a plain text version of this content. The canonical link for it is here.
Posted to discuss-archive@tvm.apache.org by "AshwiniBokka (via GitHub)" <gi...@apache.org> on 2026/01/29 14:30:57 UTC
[PR] Fix Customize Optimization tutorial import error #18584 [tvm]
AshwiniBokka opened a new pull request, #18697:
URL: https://github.com/apache/tvm/pull/18697
Fixes #18584
## Problem
The tutorial `docs/how_to/tutorials/customize_opt.py` fails with "No module named 'tvm_ffi'" when TVM is not built. This happens because the tutorial imports `tvm.relax.backend.cuda.cublas` which requires TVM to be built with CUDA support.
## Solution
1. Add clear prerequisite note about building TVM with CUDA
2. Add helpful error handling with guidance when import fails
## Changes
- Added note after imports explaining build requirements
- Wrapped problematic import with try/except
- Provides clear error message pointing to build instructions
- Follows Python best practices (stderr, proper indentation)
## Testing
- File compiles without syntax errors
- Error message clearly guides users to solution
## Before
```python
import tvm.relax.backend.cuda.cublas as _cublas
# Users get: No module named 'tvm_ffi'
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on PR #18697:
URL: https://github.com/apache/tvm/pull/18697#issuecomment-3880497781
LGTM. cc @yongwww
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "AshwiniBokka (via GitHub)" <gi...@apache.org>.
AshwiniBokka commented on PR #18697:
URL: https://github.com/apache/tvm/pull/18697#issuecomment-3831249455
Thank you @yongwww @tqchen for the guidance. This PR is now ready for merge:
1. All CI checks passed
2. Better user experience for missing CUDA
3. Clean error handling without breaking tutorial flow
4. Fixed existing bugs in tutorial
The tutorial now:
1. Helpfully guides users to install tvm-ffi first
2. Falls back to full TVM build if needed
3. Exits early with clear instructions if CUDA missing
4. Maintains all original functionality when CUDA available
Ready for final review/merge! 🙏
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww merged PR #18697:
URL: https://github.com/apache/tvm/pull/18697
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on code in PR #18697:
URL: https://github.com/apache/tvm/pull/18697#discussion_r2741960942
##########
docs/how_to/tutorials/customize_opt.py:
##########
@@ -1,4 +1,4 @@
-# Licensed to the Apache Software Foundation (ASF) under one
+# Licensed to the Apache Software Foundation (ASF) under one
Review Comment:

The file starts with a UTF-8 Byte Order Mark (BOM), which can cause issues with script execution in some environments. It should be removed.
```suggestion
# Licensed to the Apache Software Foundation (ASF) under one
```
##########
docs/how_to/tutorials/customize_opt.py:
##########
@@ -103,9 +109,17 @@ def forward(self, x):
# Import cublas pattern
-import tvm.relax.backend.cuda.cublas as _cublas
-
-
+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
Review Comment:

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.
```suggestion
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
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "AshwiniBokka (via GitHub)" <gi...@apache.org>.
AshwiniBokka commented on PR #18697:
URL: https://github.com/apache/tvm/pull/18697#issuecomment-3823311327
@yongwww Thanks for the insights! Updated to:
1. Suggest pip install tvm-ffi first
2. Only fall back to full TVM build
3. Clearer error message with options
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on code in PR #18697:
URL: https://github.com/apache/tvm/pull/18697#discussion_r2742660652
##########
LICENSE:
##########
@@ -192,7 +192,7 @@
you may not use this file except in compliance with the License.
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
Review Comment:
why do we need to update license here?
##########
docs/how_to/tutorials/customize_opt.py:
##########
@@ -55,6 +55,12 @@
from tvm import IRModule, relax
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,
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "AshwiniBokka (via GitHub)" <gi...@apache.org>.
AshwiniBokka commented on PR #18697:
URL: https://github.com/apache/tvm/pull/18697#issuecomment-3869536654
@tlopex @yongwww Update: The PR now contains **only** the tutorial fix as requested.
**Changes:**
- Better error handling for CUDA import in `customize_opt.py`
- Helpful guidance for users (`pip install tvm-ffi` or build TVM)
- No LICENSE/README modifications
- All CI checks pass
Ready for final review! 🙏
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "AshwiniBokka (via GitHub)" <gi...@apache.org>.
AshwiniBokka commented on PR #18697:
URL: https://github.com/apache/tvm/pull/18697#issuecomment-3882927113
@yongwww Applied your exact code suggestion. Thank You!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "tlopex (via GitHub)" <gi...@apache.org>.
tlopex commented on code in PR #18697:
URL: https://github.com/apache/tvm/pull/18697#discussion_r2779927745
##########
LICENSE:
##########
@@ -1,6 +1,6 @@
Apache License
Version 2.0, January 2004
- http://www.apache.org/licenses/
+ https://www.apache.org/licenses/
Review Comment:
The same question, why should we update it?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "gemini-code-assist[bot] (via GitHub)" <gi...@apache.org>.
gemini-code-assist[bot] commented on PR #18697:
URL: https://github.com/apache/tvm/pull/18697#issuecomment-3818060708
## Summary of Changes
Hello @AshwiniBokka, I'm Gemini Code Assist[^1]! 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 `ImportError` encountered by users of the `customize_opt.py` tutorial when TVM is not built with CUDA. The changes improve the user experience by adding clear documentation about the CUDA build requirement and implementing a `try-except` block to gracefully handle the missing module, providing actionable guidance. Additionally, it updates license-related URLs to use HTTPS.
### Highlights
* **Enhanced Tutorial Robustness**: The `customize_opt.py` tutorial now includes explicit prerequisites and robust error handling for the `tvm.relax.backend.cuda.cublas` import, guiding users if TVM is not built with CUDA support.
* **Improved Error Messaging**: A `try-except` block has been added to catch `ImportError` related to `tvm_ffi`, providing a clear error message to `stderr` with instructions on how to build TVM with CUDA.
* **URL Protocol Update**: Several `http` links to Apache licenses in `LICENSE` and `README.md` files have been updated to `https` for improved security and consistency.
🧠 **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](https://codeassist.google/code-review/login) to enable Memory in your admin console.**
<details>
<summary><b>Using Gemini Code Assist</b></summary>
<br>
The full guide for Gemini Code Assist can be found on our [documentation page](https://developers.google.com/gemini-code-assist/docs/review-github-code), here are some quick tips.
<b>Invoking Gemini</b>
You can request assistance from Gemini at any point by creating a comment using either `/gemini <command>` or `@gemini-code-assist <command>`. Below is a summary of the supported commands on the current page.
Feature | Command | Description
--- | --- | ---
Code Review | `/gemini review` | Performs a code review for the current pull request in its current state.
Pull Request Summary | `/gemini summary` | Provides a summary of the current pull request in its current state.
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help | `/gemini help` | Displays a list of available commands.
<b>Customization</b>
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 `.gemini/` folder in the base of the repository. Detailed instructions can be found [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github).
<b>Limitations & Feedback</b>
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with :thumbsup: and :thumbsdown: 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](https://google.qualtrics.com/jfe/form/SV_2cyuGuTWsEw84yG).
<b>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](https://cloud.google.com/products/gemini/code-assist).</b>
</details>
[^1]: Review the [Privacy Notices](https://policies.google.com/privacy), [Generative AI Prohibited Use Policy](https://policies.google.com/terms/generative-ai/use-policy), [Terms of Service](https://policies.google.com/terms), and learn how to configure Gemini Code Assist in GitHub [here](https://developers.google.com/gemini-code-assist/docs/customize-gemini-behavior-github). Gemini can make mistakes, so double check it and [use code with caution](https://support.google.com/legal/answer/13505487).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on code in PR #18697:
URL: https://github.com/apache/tvm/pull/18697#discussion_r2790850936
##########
docs/how_to/tutorials/customize_opt.py:
##########
@@ -55,6 +55,31 @@
from tvm import IRModule, relax
from tvm.relax.frontend import nn
+# Note: This tutorial requires TVM CUDA support.
+# If you encounter import errors:
+# 1. First try: pip install tvm-ffi (from 3rdparty/tvm-ffi)
Review Comment:
the package is `apache-tvm-ffi`
##########
docs/how_to/tutorials/customize_opt.py:
##########
@@ -55,6 +55,31 @@
from tvm import IRModule, relax
from tvm.relax.frontend import nn
+# Note: This tutorial requires TVM CUDA support.
+# If you encounter import errors:
+# 1. First try: pip install tvm-ffi (from 3rdparty/tvm-ffi)
+# 2. If that fails: Build TVM from source with CUDA enabled
+# Build instructions: https://tvm.apache.org/docs/install/from_source.html
+
+try:
+ import tvm.relax.backend.cuda.cublas as _cublas
+except ImportError as e:
+ import sys
+
+ print("Error: TVM CUDA support required for this tutorial.", file=sys.stderr)
Review Comment:
we can consider something like:
```
try:
import tvm.relax.backend.cuda.cublas as _cublas
except ImportError as e:
raise ImportError(
"This tutorial requires TVM built with CUDA support.\n"
"If you hit missing 'tvm_ffi', try: pip install apache-tvm-ffi\n"
"Otherwise build TVM with CUDA enabled:\n"
" https://tvm.apache.org/docs/install/from_source.html\n"
f"Original error: {e}"
) from e
```
##########
docs/how_to/tutorials/customize_opt.py:
##########
@@ -55,6 +55,31 @@
from tvm import IRModule, relax
from tvm.relax.frontend import nn
+# Note: This tutorial requires TVM CUDA support.
+# If you encounter import errors:
+# 1. First try: pip install tvm-ffi (from 3rdparty/tvm-ffi)
+# 2. If that fails: Build TVM from source with CUDA enabled
+# Build instructions: https://tvm.apache.org/docs/install/from_source.html
+
+try:
+ import tvm.relax.backend.cuda.cublas as _cublas
+except ImportError as e:
+ import sys
+
+ print("Error: TVM CUDA support required for this tutorial.", file=sys.stderr)
+ print("Solutions:", file=sys.stderr)
+ print(" 1. Install tvm-ffi: pip install tvm-ffi", file=sys.stderr)
+ print(
+ " 2. Build TVM with CUDA: https://tvm.apache.org/docs/install/from_source.html",
+ file=sys.stderr,
+ )
+ sys.exit(1)
Review Comment:
let's remove the sys.exit and raise the exception here
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org
Re: [PR] Fix Customize Optimization tutorial import error #18584 [tvm]
Posted by "yongwww (via GitHub)" <gi...@apache.org>.
yongwww commented on PR #18697:
URL: https://github.com/apache/tvm/pull/18697#issuecomment-3887063219
thanks, @AshwiniBokka! It was landed.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: discuss-archive-unsubscribe@tvm.apache.org
For additional commands, e-mail: discuss-archive-help@tvm.apache.org