Skip to content

Conversation

nimdrak
Copy link

@nimdrak nimdrak commented Aug 18, 2025

Fixes: #643

What this solves

  • building. imports onnx_tensorrt/init.py just to read version.
  • Because__init__ imports backend, this transitively pulls in GPU-dependent code.
  • As a result, the build appears to “require” GPU access even though it only needs the version string.

Why this matters

  • We shouldn’t need a GPU to build the package (especially in containerized CI).
  • Removing the implicit GPU requirement lets us build anywhere, making it easier and more efficient to produce and distribute container images.

How to test

  • Build the project without a GPU.
  • Use a plain runc runtime (not nvidia-container-runtime) as demonstrated in the linked issue comment.
  • I also verified that inference still works correctly in a GPU environment at my workplace.

Approach

  • There are a few ways to obtain the version without importing heavy modules at build time:
  • My recommendation is 1, this PR.

1. Read the version file directly (no import) ← This PR implements this

  • Pros: Very simple; minimal change to the current layout.
  • Cons: Feels a bit odd to parse Python source; but it’s a common, practical pattern.



2. Use pyproject.toml (PEP 517/518) ← I also implemented here #1036, just for reference.

  • Pros: Standards-based; clean separation of build metadata; no import side effects during build.
  • Cons: Touches more files than (1).



3. importlib.metadata.version or pkg_resources

  • Not suitable here because they assume the distribution is already installed, which isn’t true at build time.
# Not applicable during build:
from importlib.metadata import version
VERSION_NUM = version("InstalledPackageName")

# or
import pkg_resources
version = pkg_resources.require("MyProject")[0].version

Signed-off-by: ByoungUk Lee <nimdrak@gmail.com>
Signed-off-by: ByoungUk Lee <nimdrak@gmail.com>
Signed-off-by: ByoungUk Lee <nimdrak@gmail.com>
Signed-off-by: ByoungUk Lee <nimdrak@gmail.com>
@nimdrak nimdrak changed the title Build without GPU 1 - Simple approach "Build without GPU" approach 1 Aug 18, 2025
@nimdrak nimdrak changed the title "Build without GPU" approach 1 "Build without cuda runtime library" approach 1 Aug 18, 2025
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.

Package can't be installed without cuda runtime libraries available
1 participant