-
Notifications
You must be signed in to change notification settings - Fork 1
/
README.Rmd
90 lines (67 loc) · 3.13 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r setup, include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>"
)
```
# tidyverse-gpu
A Docker image based on [rocker/tidyverse](https://github.com/rocker-org/rocker-versioned) including GPU support via CUDA. Based on [work](zhttps://github.com/ecohealthalliance/reservoir/blob/master/Dockerfile.gpu) done by [Noam Ross](https://github.com/noamross). The Docker image contains `xgboost` built for GPU's in both R and Python as well as the latest stable release of `h2o`. If you wanted to use a different version of CUDA to the one currently installed then change the relevant environment variables in the `Dockerfile` and rebuild the image.
## Usage
Use as [rocker/tidyverse](https://github.com/rocker-org/rocker-versioned) but replace all `docker` commands with [`nvidia-docker`](https://github.com/NVIDIA/nvidia-docker) commands (must have installed [`nvidia-docker`](https://github.com/NVIDIA/nvidia-docker) on the host system).
* Pull/Build
```{bash, eval = FALSE}
docker pull seabbs/tidyverse-gpu
## Or build
## Clone repo and navigate into the repo in the terminal
docker build . -t tidyverse-gpu
```
* Run
```{bash, eval = FALSE}
nvidia-docker run -d -p 8787:8787 -e USER=tidyverse-gpu -e PASSWORD=tidyverse-gpu --name tidyverse-gpu seabbs/tidyverse-gpu
## Or build
nvidia-docker run -d -p 8787:8787 -e USER=tidyverse-gpu -e PASSWORD=tidyverse-gpu --name tidyverse-gpu tidyverse-gpu
```
* Login: Go to `localhost:8787` and sign in using the password and username given with the `docker run` command
## Nvidia Test
Run `nvidia-smi` in a bash shell. If GPU support is working correctly it should return GPU usage and temperature information.
```{bash, eval = FALSE}
nvidia-smi
```
## Xgboost GPU Test
If the following runs without errors `xgboost` is installed and using the GPU.
```{r, eval = FALSE}
library(xgboost)
# load data
data(agaricus.train, package = 'xgboost')
data(agaricus.test, package = 'xgboost')
train <- agaricus.train
test <- agaricus.test
# fit model
bst <- xgboost(data = train$data, label = train$label, max_depth = 5, eta = 0.001, nrounds = 100,
nthread = 2, objective = "binary:logistic", tree_method = "gpu_hist")
# predict
pred <- predict(bst, test$data)
```
## Xgboost via H2O Test
`h2o` provides a nice interface to `xgboost`, along with some great tools for hyper-parameter tuning. (*Note: This is not an install of `h2o4gpu` so only `h2o.xgboost` supports GPU acceleration.*)
```{r, eval = FALSE}
# Init h2o
library(h2o)
h2o.init()
# Load test data
australia_path <- system.file("extdata", "australia.csv", package = "h2o")
australia <- h2o.uploadFile(path = australia_path)
independent <- c("premax", "salmax","minairtemp", "maxairtemp", "maxsst",
"maxsoilmoist", "Max_czcs")
dependent <- "runoffnew"
# Run xgboost without GPU
h2o.xgboost(y = dependent, x = independent, training_frame = australia,
ntrees = 1000, backend = "cpu")
# Run xgboost with GPU
h2o.xgboost(y = dependent, x = independent, training_frame = australia,
ntrees = 1000, backend = "gpu")
```