Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions R/vram.R
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,13 @@ is_blackwell_gpu <- function() {
return(mb / 1024)
}

# Fallback: check if CUDA available but can't determine VRAM
if (torch::cuda_is_available()) {
# Fallback: check if CUDA available but can't determine VRAM.
# cuda_is_available() ERRORS (not FALSE) when torch is installed
# without its lantern binaries - fresh installs, win-builder, CRAN -
# and this branch is exactly where those machines land, since they
# have no nvidia-smi either. Probe soft, same as is_blackwell_gpu().
if (isTRUE(tryCatch(torch::cuda_is_available(),
error = function(e) FALSE))) {
# Conservative estimate - assume 8GB if we can't detect
message("Could not detect VRAM via nvidia-smi; assuming 8 GB.")
return(8)
Expand Down
12 changes: 8 additions & 4 deletions cran-comments.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,11 @@ addressed:
## Test environments

* Ubuntu 24.04 (local), R 4.6.x: R CMD check --as-cran
* Windows 10, R 4.6.0 (full test suite against installed torch backend)
* Windows 10, R-devel, torch installed without its lantern backend
(tests skip gracefully)
* Windows 10, R 4.6.0 and R-devel: R CMD check --as-cran, with torch's
lantern backend installed (so the full suite runs)
* Ubuntu, with lantern deliberately absent, to exercise the path
win-builder and CRAN take: examples and tests skip gracefully rather
than erroring
* win-builder, R-devel

## R CMD check results
Expand Down Expand Up @@ -71,4 +73,6 @@ package.
under tools::R_user_dir("diffuseR", "data").
* torch is in Imports; all tests, examples, and vignette code degrade
gracefully when torch's backend (lantern) is not installed, as on
win-builder.
win-builder. Note that `torch::cuda_is_available()` raises an error
rather than returning FALSE in that state, so the package probes it
through `tryCatch()` everywhere it is reachable without a GPU.
15 changes: 14 additions & 1 deletion inst/tinytest/test_resident.R
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,19 @@ fake_pipeline <- function() {
class = "test_pipeline")
}

# Everything from here to the "state machine" section builds real
# nn_modules or torch dtypes, so it needs a working lantern. torch
# installed WITHOUT its lantern binaries is the normal state on
# win-builder and CRAN, and there `torch::nn_linear()` errors rather
# than returning. The state-machine sections below are pure R and run
# everywhere.
have_torch <- requireNamespace("torch", quietly = TRUE) &&
torch::torch_is_installed()

# --- component discovery ----------------------------------------------------------

if (have_torch) {

pipe <- fake_pipeline()
comps <- diffuseR:::.resident_components(pipe)
expect_equal(sort(names(comps)), c("decoder", "text_encoder", "transformer"))
Expand All @@ -40,6 +51,8 @@ expect_equal(diffuseR:::.dtype_bytes(torch::torch_bfloat16()), 2)
expect_equal(diffuseR:::.dtype_bytes(torch::torch_uint8()), 1)
expect_equal(diffuseR:::.dtype_bytes(torch::torch_int64()), 8)

} # end have_torch

# --- byte formatting --------------------------------------------------------------

expect_equal(diffuseR:::.fmt_gb(0), "0 GB")
Expand Down Expand Up @@ -140,7 +153,7 @@ expect_equal(resident_status(u)$state, "unloaded")

# --- CUDA round trip --------------------------------------------------------------

if (at_home() && torch::cuda_is_available()) {
if (have_torch && at_home() && torch::cuda_is_available()) {
pipe <- fake_pipeline()
staging <- diffuseR:::.resident_pin(pipe, verbose = FALSE)
expect_equal(sort(names(staging)),
Expand Down
Loading