Skip to content

Instantly share code, notes, and snippets.

@RAMitchell
Created May 19, 2020 02:51
Show Gist options
  • Save RAMitchell/097f914da09405d9ac7d97c876c60d1f to your computer and use it in GitHub Desktop.
Save RAMitchell/097f914da09405d9ac7d97c876c60d1f to your computer and use it in GitHub Desktop.
import cupy
import torch
import GPUtil
import xgboost as xgb
from torch.utils.dlpack import to_dlpack
from torch.utils.dlpack import from_dlpack
mem_before = GPUtil.getGPUs()[0].memoryUsed
# Create a PyTorch tensor.
tx1 = torch.randn(1000000, 1000).cuda()
print(GPUtil.getGPUs()[0].memoryUsed - mem_before)
# Convert it into a DLPack tensor.
dx = to_dlpack(tx1)
# Train with xgboost!
dmat = xgb.DeviceQuantileDMatrix(dx)
print(GPUtil.getGPUs()[0].memoryUsed - mem_before)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment