Skip to content

Survive torch installed without lantern - #52

Merged
TroyHernandez merged 1 commit into
mainfrom
fix/lantern-absent
Aug 3, 2026
Merged

Survive torch installed without lantern#52
TroyHernandez merged 1 commit into
mainfrom
fix/lantern-absent

Conversation

@TroyHernandez

Copy link
Copy Markdown
Contributor

win-builder R-devel failed 0.2.2 with two errors, both "Lantern is not
loaded"
: the auto-detect branch of the auto_devices() example, and
test_resident.R.

One line caused both

.detect_vram() falls back to torch::cuda_is_available() when nvidia-smi
is absent — and that call errors rather than returning FALSE when torch
is installed without its lantern binaries. That is exactly the state
win-builder and CRAN are in, and exactly the branch they land in, since
those machines have no nvidia-smi either.

is_blackwell_gpu() has guarded this since it was written, and its comment
says why. .detect_vram() never did. It now probes through tryCatch() the
same way, which fixes auto_devices(), sdxl_memory_profile() and
recommend() together, since all three route through it.

test_resident.R built real nn_modules at top level with no lantern guard.
The torch-dependent sections (component discovery, dtype table, CUDA round
trip) now sit behind one; the pure-R sections — state machine, transition
guards, status, print, unload — still run on CRAN, where they are the parts
that can run.

Why the local Windows check passed

torch_is_installed() cuda_is_available()
windows-hr, R-devel TRUE returns FALSE cleanly
win-builder, R-devel FALSE errors

windows-hr has lantern installed on both R 4.6.0 and R-devel, so the
fallback behaved. cran-comments.md claimed that machine ran "without its
lantern backend" — untrue, and corrected here. It is not a proxy for CRAN on
this axis.

Reproducible locally now, which is the durable fix

TORCH_HOME=$(mktemp -d) Rscript --vanilla -e \
  'library(diffuseR); library(tinytest); run_test_dir("inst/tinytest")'

An empty TORCH_HOME makes torch_is_installed() FALSE and
cuda_is_available() throw, matching win-builder exactly. Under it the five
previously-failing examples pass and 271 assertions run green, the rest
skipping as intended.

win-builder R-devel failed 0.2.2 with two errors, both
"Lantern is not loaded":

  * the auto-detect branch of the auto_devices() example
  * test_resident.R

Root cause is one line in .detect_vram(). When nvidia-smi is absent it
falls back to torch::cuda_is_available(), which ERRORS rather than
returning FALSE when torch is installed without its lantern binaries.
That is exactly the state win-builder and CRAN are in, and exactly the
branch they land in, since those machines have no nvidia-smi either.
is_blackwell_gpu() has guarded this since it was written, and the
comment there says why; .detect_vram() never did. It now probes through
tryCatch() the same way, which fixes auto_devices(), sdxl_memory_profile()
and recommend() together, since all three route through it.

test_resident.R built real nn_modules at top level with no lantern
guard. The torch-dependent sections (component discovery, the dtype
table, the CUDA round trip) now sit behind one, and the pure-R sections
-- state machine, transition guards, status, print, unload -- still run
on CRAN, where they are the parts that can run.

Why the local Windows check missed it: windows-hr has lantern installed
on both R 4.6.0 and R-devel, so cuda_is_available() returns FALSE there
cleanly and the fallback behaved. cran-comments.md claimed that box ran
"without its lantern backend", which was simply untrue and is corrected
here. The box is not a proxy for CRAN on this axis.

It is reproducible locally, which is the durable fix:

  TORCH_HOME=$(mktemp -d) Rscript --vanilla -e \
    'library(diffuseR); library(tinytest); run_test_dir("inst/tinytest")'

An empty TORCH_HOME makes torch_is_installed() FALSE and
cuda_is_available() throw, matching win-builder. Under it the five
previously-failing examples pass and 271 assertions run green, the rest
skipping as intended.
@TroyHernandez
TroyHernandez merged commit 026b5b5 into main Aug 3, 2026
0 of 2 checks passed
@TroyHernandez
TroyHernandez deleted the fix/lantern-absent branch August 3, 2026 04:57
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.

1 participant