I try to add GPUCacheFeature in dgl’s graphbolt tutorials. I use the link prediction code.
first, load the dataset, both graph and data are on cpu
dataset = gb.BuiltinDataset("cora").load()
device="cpu"
graph = dataset.graph.to(device)
feature = dataset.feature.to(device)
train_set = dataset.tasks[1].train_set
test_set = dataset.tasks[1].test_set
task_name = dataset.tasks[1].metadata["name"]
then define the datapipe, i put the copy_to at last to do sampling on cpu.
from functools import partial
def create_train_dataloader():
datapipe = gb.ItemSampler(train_set, batch_size=256, shuffle=True)
datapipe = datapipe.sample_uniform_negative(graph, 5)
datapipe = datapipe.sample_neighbor(graph, [5, 5])
datapipe = datapipe.transform(partial(gb.exclude_seed_edges, include_reverse_edges=True))
datapipe = datapipe.fetch_feature(feature, node_feature_keys=["feat"])
datapipe = datapipe.copy_to("cuda:0")
return gb.DataLoader(datapipe)
create GPUCacheFeature
feature._features[('node',None,'feat')] = gb.GPUCachedFeature(feature._features[('node',None,'feat')], 512)
define model and start train
class SAGE:
# same as tutorial, skipped
in_size = feature.size("node", None, "feat")[0]
model = SAGE(in_size, 128).to("cuda:0") # move model to cuda
optimizer = torch.optim.Adam(model.parameters(), lr=0.001)
for epoch in range(3):
# train code
when i run the train code, it reports
RuntimeError: Keys should be on a CUDA device.
This exception is thrown by __iter__ of FeatureFetcher(datapipe=MultiprocessingWrapper, edge_feature_keys=None, feature_store=TorchBasedFeatureStore(
{(<OnDiskFeatureDataDomain.NODE: 'node'>, None, 'feat'): <dgl.graphbolt.impl.gpu_cached_feature.GPUCachedFeature object at 0x7f6bfda4e4a0>}
), node_feature_keys=['feat'])
It seems keys to read cache should be also on gpu, but where can I move the keys to in gpu in the datapipe, which datapipe op should i use?