Hi hcho3, thanks a lot for the reply.
I have tried:
rm(bst_gpu) and then gc() .
- using the model’s output bst_gpu.call(’_del_’) function
- running the model on a separate process and stopping the thread. This releases the memory but crashes xgboost when I try to run it again.
1 and 2 do not seems to clear the gpu memory as reported in nvtop. 3 crashes xgboost. Let me show you an example code from the package:
# Simulate N x p random matrix with some binomial response dependent on pp columns
N <- 1000000
p <- 50
pp <- 25
X <- matrix(runif(N * p), ncol = p)
betas <- 2 * runif(pp) - 1
sel <- sort(sample(p, pp))
m <- X[, sel] %*% betas - 1 + rnorm(N)
y <- rbinom(N, 1, plogis(m))
tr <- sample.int(N, N * 0.75)
dtrain <- xgb.DMatrix(X[tr, ], label = y[tr])
dtest <- xgb.DMatrix(X[-tr, ], label = y[-tr])
wl <- list(train = dtrain, test = dtest)
param <- list(objective = 'reg:logistic', eval_metric = 'auc', subsample = 0.5, nthread = 4,
max_bin = 64, tree_method = 'gpu_hist')
pt <- proc.time()
bst_gpu <- xgb.train(param, dtrain, watchlist = wl, nrounds = 50)
proc.time() - pt
rm(bst_gpu) # Does not clear gpu memory...