I’m using pinsage model with custom data which is a bipartite graph. Following is the graph structure which is a heterogenous graph
- Image node with features of dimensions 2048
- Text node with features of dimensions 500
- Edge between Image node and text node and vice versa. The edge weight is 1 for all the edges.
g = dataset['train-graph']
item_texts = dataset['item-texts']
user_ntype = 'tag'
item_ntype = 'image'
user_to_item_etype = dataset['user-to-item-type']
device = torch.device(args.device)
# Assign user and movie IDs and use them as features (to learn an individual trainable
# embedding for each entity)
img_features = torch.from_numpy(np.load('f200k/data/graph/img_features.npy'))
txt_features = torch.from_numpy(np.load('f200k/data/graph/txt_features.npy'))
g.nodes[user_ntype].data['id'] = txt_features
g.nodes[item_ntype].data['id'] = img_features
g.edges['has'].data['weights'] = torch.ones(g.edges(etype='has')[0].shape[0], dtype=torch.int64)
g.edges['in'].data['weights'] = torch.ones(g.edges(etype='in')[0].shape[0], dtype=torch.int64)
# Sampler
batch_sampler = sampler_module.ItemToItemBatchSampler(
g, user_ntype, item_ntype, args.batch_size)
neighbor_sampler = sampler_module.NeighborSampler(
g, user_ntype, item_ntype, args.random_walk_length,
args.random_walk_restart_prob, args.num_random_walks, args.num_neighbors,
args.num_layers)
collator = sampler_module.PinSAGECollator(neighbor_sampler, g, user_ntype, item_ntype)
dataloader = DataLoader(
batch_sampler,
collate_fn=collator.collate_train,
num_workers=args.num_workers)
dataloader_test = DataLoader(
torch.arange(g.number_of_nodes(item_ntype)),
batch_size=args.batch_size,
collate_fn=collator.collate_test,
num_workers=args.num_workers)
dataloader_it = iter(dataloader)
# Model
model = PinSAGEModel(g, item_ntype, user_ntype, args.hidden_dims, args.num_layers).to(device)
print(model)
# Optimizer
opt = torch.optim.Adam(model.parameters(), lr=args.lr)
# For each batch of head-tail-negative triplets...
for epoch_id in range(args.num_epochs):
model.train()
for batch_id in tqdm.trange(args.batches_per_epoch):
pos_graph, neg_graph, blocks = next(dataloader_it)
I get the following error
Traceback (most recent call last):
File "model.py", line 149, in <module>
train(dataset, args)
File "model.py", line 101, in train
pos_graph, neg_graph, blocks = next(dataloader_it)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 819, in __next__
return self._process_data(data)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/utils/data/dataloader.py", line 846, in _process_data
data.reraise()
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/_utils.py", line 385, in reraise
raise self.exc_type(msg)
dgl._ffi.base.DGLError: Caught DGLError in DataLoader worker process 0.
Original Traceback (most recent call last):
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/utils/data/_utils/worker.py", line 178, in _worker_loop
data = fetcher.fetch(index)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/torch/utils/data/_utils/fetch.py", line 35, in fetch
return self.collate_fn(data)
File "/home/ubuntu/dl_workspace/dgl/examples/pytorch/pinsage/sampler.py", line 144, in collate_train
pos_graph, neg_graph, blocks = self.sampler.sample_from_item_pairs(heads, tails, neg_tails)
File "/home/ubuntu/dl_workspace/dgl/examples/pytorch/pinsage/sampler.py", line 77, in sample_from_item_pairs
blocks = self.sample_blocks(seeds, heads, tails, neg_tails)
File "/home/ubuntu/dl_workspace/dgl/examples/pytorch/pinsage/sampler.py", line 51, in sample_blocks
frontier = sampler(seeds)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/dgl/sampling/pinsage.py", line 115, in __call__
neighbor_graph = select_topk(neighbor_graph, self.num_neighbors, self.weight_column)
File "/home/ubuntu/anaconda3/envs/pytorch_p36/lib/python3.6/site-packages/dgl/sampling/neighbor.py", line 162, in select_topk
g._graph, nodes_all_types, k_array, edge_dir, weight_arrays, bool(ascending))
File "dgl/_ffi/_cython/./function.pxi", line 287, in dgl._ffi._cy3.core.FunctionBase.__call__
File "dgl/_ffi/_cython/./function.pxi", line 232, in dgl._ffi._cy3.core.FuncCall
File "dgl/_ffi/_cython/./base.pxi", line 155, in dgl._ffi._cy3.core.CALL
dgl._ffi.base.DGLError: [19:48:49] /opt/dgl/src/array/array.cc:620: Check failed: (weight->dtype).code == kDLFloat (
@BarclayIl