Repository navigation
Guard the cudatoolkit lib_path() call during startup - #1478
Merged
dfalbel merged 2 commits intoOct 21, 2026
Merged
Conversation
load_cudatoolkit_libs() called the cuda* package's lib_path() unguarded, so any error raised there propagated out of .onLoad and was reported as torch failing to start, naming torch rather than the toolkit package. The dir.exists() check on the following line cannot catch the case it names: cuda*::lib_path() is system.file(..., mustWork = TRUE), which errors rather than returning "" when the directory is missing, so control never reaches the guard with a bad path. Catch it, warn naming the package at fault, and continue without preloading those libraries. Reported at mlverse#1463 (2026-07-05 comment), where the trigger is mlverse/cudatoolkit#5 and R CMD check clears R_DEFAULT_PACKAGES for its whole driver process. For a package that touches torch at load time the cost there is three check WARNINGs and a namespace load failure.
Contributor
Author
…it-lib-path # Conflicts: # NEWS.md
Contributor
Author
|
@sebffischer I merged main and resolved the NEWS.md conflict, and the CI run here needs a maintainer to approve it. The root cause has a fix in mlverse/cudatoolkit#7, which adds the missing utils and stats imports. That should also fix #1463. This PR is the torch-side guard: if a cuda* package's |
dfalbel
approved these changes
Oct 21, 2026
dfalbel
approved these changes
Oct 21, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
load_cudatoolkit_libs()calls thecuda*package'slib_path()unguarded, so any error raised there propagates out of.onLoadand is reported as torch failing to start.On a machine with a
cuda*package installed:The reported fault is torch; the actual fault is in the toolkit package. That particular trigger is mlverse/cudatoolkit#5, and
R CMD checkclearsR_DEFAULT_PACKAGESfor its whole driver process, so it fires there too.Not hypothetical: the same signature is in #1463 (comment, 2026-07-05), where it outlives the symlink workaround that thread is otherwise about. For a package that touches torch at load time the cost is not a NOTE, it is three
R CMD checkWARNINGs and.onLoad failed in loadNamespace().The existing guard cannot fire
cuda*::lib_path()issystem.file("lib", package = ..., mustWork = TRUE), which errors rather than returning""when the directory is missing, so control never arrives atdir.exists()with a bad path.Change
Catch the error, warn naming the toolkit package, and continue without preloading. This matches how the
dyn.load()calls further down are already handled.Verified against the real failing call:
cli::cli_warn()was checked in the sameR_DEFAULT_PACKAGES=NULLenvironment, so the handler does not reintroduce the failure it reports.Startup then continues with whatever libraries remain available. Whether that lands on a working session depends on the build: a CPU build, or one with another usable CUDA source, starts; a CUDA build that needed the skipped libraries still fails, but names the toolkit package rather than torch.
One question
Possibly also upstream of #1463's original symptom.
load_cudatoolkit_libs()exists todyn.load()the toolkit's CUDA libraries beforecpp_lantern_init(), so if it aborts or silently no-ops,liblantern.sohas nothing to resolvelibcudart.so.12against. Not asserting it — the original trace there reachescpp_lantern_init(), so the preload returned rather than errored in that invocation.