Skip to content

Conversation

@mshr-h
Copy link
Contributor

@mshr-h mshr-h commented Sep 27, 2025

As per title.

repro:

mkdir -p ~/tmp
cd ~/tmp
git clone https://github.com/apache/tvm --recursive
cd tvm
uv venv && source .venv/bin/activate
uv pip install ninja
uv pip install . --config-settings=cmake.args="-G Ninja"
rm -rf build/
python -c "import tvm"

we get

Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/ubuntu/tmp/tvm/.venv/lib/python3.11/site-packages/tvm/__init__.py", line 27, in <module>
    from .base import TVMError, __version__, _RUNTIME_ONLY
  File "/home/ubuntu/tmp/tvm/.venv/lib/python3.11/site-packages/tvm/base.py", line 58, in <module>
    _LIB, _LIB_NAME = _load_lib()
                      ^^^^^^^^^^^
  File "/home/ubuntu/tmp/tvm/.venv/lib/python3.11/site-packages/tvm/base.py", line 40, in _load_lib
    lib_path = libinfo.find_lib_path()
               ^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/ubuntu/tmp/tvm/.venv/lib/python3.11/site-packages/tvm/libinfo.py", line 173, in find_lib_path
    raise RuntimeError(message)
RuntimeError: Cannot find libraries: ['libtvm.so', 'libtvm_runtime.so', '3rdparty/cutlass_fpA_intB_gemm/cutlass_kernels/libfpA_intB_gemm.so', '3rdparty/libflash_attn/src/libflash_attn.so']
List of candidates:
/home/ubuntu/tmp/tvm/.venv/bin/libtvm.so
/usr/local/cuda-12.8/bin/libtvm.so
/home/ubuntu/.cargo/bin/libtvm.so
/usr/local/sbin/libtvm.so
/usr/local/bin/libtvm.so
/usr/sbin/libtvm.so
/usr/bin/libtvm.so
/usr/sbin/libtvm.so
/usr/bin/libtvm.so
/usr/games/libtvm.so
/usr/local/games/libtvm.so
/snap/bin/libtvm.so
/home/ubuntu/.fzf/bin/libtvm.so
/home/ubuntu/tmp/tvm/.venv/lib/python3.11/site-packages/tvm/libtvm.so
/home/ubuntu/tmp/tvm/.venv/lib/libtvm.so
/home/ubuntu/tmp/tvm/.venv/bin/libtvm_runtime.so
/usr/local/cuda-12.8/bin/libtvm_runtime.so
/home/ubuntu/.cargo/bin/libtvm_runtime.so
/usr/local/sbin/libtvm_runtime.so
/usr/local/bin/libtvm_runtime.so
/usr/sbin/libtvm_runtime.so
/usr/bin/libtvm_runtime.so
/usr/sbin/libtvm_runtime.so
/usr/bin/libtvm_runtime.so
/usr/games/libtvm_runtime.so
/usr/local/games/libtvm_runtime.so
/snap/bin/libtvm_runtime.so
/home/ubuntu/.fzf/bin/libtvm_runtime.so
/home/ubuntu/tmp/tvm/.venv/lib/python3.11/site-packages/tvm/libtvm_runtime.so
/home/ubuntu/tmp/tvm/.venv/lib/libtvm_runtime.so

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @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 addresses a critical issue preventing the TVM Python package from functioning correctly after installation. Previously, when TVM was installed as a package, it failed to locate its necessary shared libraries, leading to a RuntimeError upon import. The change introduces an additional lookup path for these libraries, specifically targeting a lib subdirectory within the package's installation, thereby enabling successful package import and usage.

Highlights

  • Library Lookup Fix: Resolved a RuntimeError that occurred when the TVM Python package was installed, preventing it from finding essential shared libraries like libtvm.so and libtvm_runtime.so.
  • Enhanced Path Discovery: Modified the library search mechanism to include a common lib subdirectory within the installed TVM package's location, ensuring that dynamically linked libraries are correctly discovered.
Using Gemini Code Assist

The 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 /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.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 adds a library search path to address an issue with importing tvm when it's installed as a Python package. The change is a functional fix for the described problem. My review includes one comment that, while the change is effective, it may be a workaround for an underlying inconsistency in the build and installation process defined in CMake. Addressing the root cause in the CMake configuration would be a more robust long-term solution for better maintainability.


# Pip lib directory
dll_path.append(ffi_dir)
dll_path.append(os.path.join(ffi_dir, "lib"))
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

This change effectively resolves the library loading issue. However, it appears to be a workaround for an underlying inconsistency in the installation process. It seems CMakeLists.txt has duplicate install directives for the tvm and tvm_runtime libraries, which can lead to them being placed in different directories based on the build context (e.g., pip install vs. a manual make install).

For better long-term maintainability, we should consider addressing the root cause in the CMake setup to ensure libraries are always installed to a single, predictable location. This would simplify the library discovery logic and make the packaging more robust.

@tlopex tlopex merged commit 2c7ef94 into apache:main Sep 27, 2025
13 of 14 checks passed
@mshr-h mshr-h deleted the fix-lib-lookup branch October 6, 2025 09:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants