Make torch installation robust to install_torch() exit-time segfault - #397
Make torch installation robust to install_torch() exit-time segfault#397AntoineSoetewey wants to merge 1 commit into
Conversation
Follow-up to ropensci-review-tools#393 and ropensci/software-review#784: tolerate a crash of the install_torch() process so a completed installation is kept, record install_torch_sitrep() in the build log, and set TORCH_INSTALL=1 as a runtime fallback.
Docker-build repro matrix ran 2026-08-02 (run 30748491813): 4/4 negative, install_torch() exits 0 in all variants (one transient r2u mirror timeout rerun, unrelated to torch). Follow-up posted to ropensci/software-review#784 and cross-referenced in kindling#34; robustness PR opened as ropensci-review-tools/pkgcheck#397. Workflow paths narrowed to docker/** so documentation edits no longer trigger rebuilds.
There was a problem hiding this comment.
Pull request overview
This PR hardens the Docker image build against an observed torch::install_torch() exit-time segfault (exit 139) on the rOpenSci build server so that a completed LibTorch install is retained in the Docker layer and torch availability is visible in build logs, with a runtime fallback if files are missing.
Changes:
- Makes the
torch::install_torch()build step non-fatal (currently for any non-zero exit) to avoid discarding a successful install due to an exit-time crash. - Adds a
torch::install_torch_sitrep()step to record the installed state in build logs. - Sets
ENV TORCH_INSTALL "1"to allow torch to self-install on first load as a last-resort fallback.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| RUN Rscript -e 'torch::install_torch()' \ | ||
| || echo "WARNING: install_torch() exited non-zero; relying on TORCH_INSTALL=1 fallback" |
|
Thanks for the attempts here! I'm going to close this PR because it is too Claude-verbose. The problem appears to be that With those two additional packages, everything is then fine, and checks run perfectly. So we just need to skip what seems in current form to be a hard-coded interactive step after initial (And just speculating here, but those downloads are clearly in response to hardware probing, which suggests to me that |
add 'TORCH_INSTALL' envvar for #397
Follow-up to #393 and to the segfault @mpadge reported in ropensci/software-review#784: on the rOpenSci build server,
RUN Rscript -e 'torch::install_torch()'dies with a segfault, apparently after the installation itself completes ("failed somewhere in the cleanup process"). When that happens duringdocker build, the RUN step returns 139 and the layer -- including the completed installation -- is discarded, so the weekly server rebuild loses torch entirely.Notably, this repo's own
docker.yamlCI has built the identical Dockerfile successfully three times since #393 (runs 29487664312, 29712935423, 30232503908), withinstall_torch()executing in ~10 s and exiting 0. We also could not reproduce the crash in a four-variantdocker buildbisection fromeddelbuettel/r2u:24.04(runs + logs, details). The crash appears specific to the server environment; we are pursuing the root cause separately (a never-failing diagnostic build for the affected host is ready, and we will report upstream to mlverse/torch once a backtrace exists).This PR makes the image build robust to it regardless of cause:
|| echo ...on the install step -- an exit-time segfault no longer fails the build, so an installation that completed before the crash is kept in the layer instead of thrown away. On hosts where the step is healthy (like CI here) nothing changes.torch::install_torch_sitrep()layer -- the build log always records whether libtorch/lantern actually landed, so a broken torch state is visible instead of silent.ENV TORCH_INSTALL "1"-- the mechanism @mpadge already used as a manual patch on the server, now permanent as a last-resort fallback: if the files really are missing at check time, torch installs itself on first load rather than hard-failing the checked package.Alternative considered: dropping the RUN step and relying on
TORCH_INSTALL=1alone (the manual patch). That works, but moves the 170 MB libtorch download from image-build time to first use inside review containers; keeping the baked install as the primary path avoids that, with the envvar as safety net.(
ENV key valuelegacy form kept for consistency with the rest of the file, e.g.ENV ARROW_S3 "ON".)🤖 Generated with Claude Code