Repository navigation
[TRTLLM-17241][fix] Start trtllm-render on a host with no GPU driver #20842
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
Merged
+161
−1
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ffaf8ed
[TRTLLM-16711][fix] Start trtllm-render on a host with no GPU driver
hchings 4adfe3a
[TRTLLM-17241][fix] Try each CUDA stub in order and test the installe…
hchings 74eaa35
[TRTLLM-17241][fix] Log the trtllm-render CUDA stub fallback with the…
hchings e966cd2
[TRTLLM-17241][fix] Stage trtllm-render in the serving schema packagi…
hchings File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/usr/bin/env python3 | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
| """``trtllm-render`` entry point. | ||
|
|
||
| ``import tensorrt_llm`` links ``libcuda.so.1``, which a container with no GPU does not have. When it cannot | ||
| be loaded, this loads the CUDA toolkit stub in its place so the renderer starts on a CPU-only host. It is a | ||
| script outside the package so that importing ``tensorrt_llm`` anywhere else is unchanged. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import ctypes | ||
| import glob | ||
| import os | ||
| import re | ||
| import sys | ||
| import warnings | ||
|
|
||
|
|
||
| def _version(path: str) -> list: | ||
| return [int(part) for part in re.findall(r"\d+", path)] | ||
|
|
||
|
|
||
| def _stub_candidates() -> list: | ||
| """Toolkit stubs, most preferred first: ``$CUDA_HOME``, ``/usr/local/cuda``, then the newest versioned.""" | ||
| roots = [os.environ["CUDA_HOME"]] if os.environ.get("CUDA_HOME") else [] | ||
| roots.append("/usr/local/cuda") | ||
| roots += sorted(glob.glob("/usr/local/cuda-*"), key=_version, reverse=True) | ||
| candidates, seen = [], set() | ||
| for root in roots: | ||
| for pattern in ("lib64/stubs/libcuda.so", "targets/*/lib/stubs/libcuda.so"): | ||
| for stub in sorted(glob.glob(os.path.join(root, pattern))): | ||
| if os.path.realpath(stub) not in seen: | ||
| seen.add(os.path.realpath(stub)) | ||
| candidates.append(stub) | ||
| return candidates | ||
|
|
||
|
|
||
| def _load_cuda_stub_if_needed() -> str | None: | ||
| """Load a toolkit stub when ``libcuda.so.1`` is missing; return its path, or None if not needed.""" | ||
| try: | ||
| ctypes.CDLL("libcuda.so.1") | ||
| return None | ||
| except OSError: | ||
| pass | ||
| failures = [] | ||
| for stub in _stub_candidates(): | ||
| try: | ||
| ctypes.CDLL(stub, mode=ctypes.RTLD_GLOBAL) | ||
| except OSError as error: | ||
| failures.append(f"{stub}: {error}") | ||
| continue | ||
| warnings.filterwarnings("ignore", message="CUDA initialization:", category=UserWarning) | ||
| return stub | ||
| sys.exit( | ||
| "trtllm-render: libcuda.so.1 not found and no usable CUDA toolkit stub under $CUDA_HOME or " | ||
| "/usr/local/cuda*; install the CUDA toolkit stubs or expose a GPU driver" | ||
| + "".join(f"\n tried {failure}" for failure in failures) | ||
| ) | ||
|
|
||
|
|
||
| def main() -> None: | ||
| stub = _load_cuda_stub_if_needed() | ||
| from tensorrt_llm.logger import logger | ||
| from tensorrt_llm.serve.render.__main__ import main as render_main | ||
|
|
||
| if stub: | ||
| logger.info( | ||
| f"trtllm-render: no GPU driver found; running CPU-only with the CUDA stub {stub}" | ||
| ) | ||
| render_main() | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| main() | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.