Skip to content

Commit ffd7c60

Browse files
authored
1 parent 70fe9f2 commit ffd7c60

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

gpu.Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,4 +72,8 @@ RUN apt-get install -y --no-install-recommends ocl-icd-opencl-dev && \
7272
RUN CPATH=/usr/local/cuda/targets/x86_64-linux/include install2.r --error --ncpus $ncpus --repo http://cran.rstudio.com \
7373
h2o4gpu
7474

75+
# Torch: install the full package upfront otherwise it will be installed on loading the package which doesn't work for kernels
76+
# without internet (competitions for example). It will detect CUDA and install the proper version.
77+
RUN R -e 'library(torch); install_torch(reinstall = TRUE)'
78+
7579
CMD ["R"]

package_installs.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,8 @@ install_github("thomasp85/patchwork")
4040
install.packages("topicmodels")
4141

4242
install.packages("tesseract")
43+
44+
# Torch: install the full package upfront otherwise it will be installed on loading the package which doesn't work for kernels
45+
# without internet (competitions for example).
46+
library(torch)
47+
install_torch(reinstall = TRUE)

tests/test_torch.R

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
context("torch")
2+
3+
test_that("cpu imports", {
4+
library(torch)
5+
x <- array(runif(8), dim = c(2, 2, 2))
6+
y <- torch_tensor(x, dtype = torch_float64())
7+
expect_identical(x, as_array(y))
8+
})
9+
10+
test_that("gpu imports", {
11+
check_gpu()
12+
13+
library(torch)
14+
x <- array(runif(8), dim = c(2, 2, 2))
15+
y <- torch_tensor(x, dtype = torch_float64(), device = "cuda")
16+
expect_identical(x, as_array(y$cpu()))
17+
})
18+

0 commit comments

Comments
 (0)