This is an automated email from the ASF dual-hosted git repository.
yongwww pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new 44d3554d57 Fix Customize Optimization tutorial import error #18584
(#18697)
44d3554d57 is described below
commit 44d3554d57539e7796d796dd7bac7516d3d3a2fb
Author: AshwiniBokka <[email protected]>
AuthorDate: Thu Feb 12 02:09:41 2026 +0530
Fix Customize Optimization tutorial import error #18584 (#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'
---
docs/how_to/tutorials/customize_opt.py | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/docs/how_to/tutorials/customize_opt.py
b/docs/how_to/tutorials/customize_opt.py
index 43ce71343f..c175f43c6f 100644
--- a/docs/how_to/tutorials/customize_opt.py
+++ b/docs/how_to/tutorials/customize_opt.py
@@ -103,7 +103,16 @@ mod.show()
# Import cublas pattern
-import tvm.relax.backend.cuda.cublas as _cublas
+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
# Define a new pass for CUBLAS dispatch