Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix drop last in distributed sampler #125

Merged
merged 2 commits into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/igbh/dist_train_rgnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,8 @@ def run_training_proc(local_proc_rank, num_nodes, node_rank, num_training_procs,
num_neighbors=[int(fanout) for fanout in fan_out.split(',')],
input_nodes=('paper', val_idx),
batch_size=val_batch_size,
shuffle=False,
shuffle=True,
drop_last=False,
edge_dir=edge_dir,
collect_features=True,
to_device=current_device,
Expand Down
17 changes: 13 additions & 4 deletions graphlearn_torch/python/distributed/dist_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -387,9 +387,15 @@ def _collate_fn(

if self.sampling_config.sampling_type in [SamplingType.NODE,
SamplingType.SUBGRAPH]:
batch_dict = {
self._input_type: node_dict[self._input_type][:self.batch_size]
}
batch_key = f'{self._input_type}.batch'
if msg.get(batch_key) is not None:
batch_dict = {
self._input_type: msg[f'{self._input_type}.batch'].to(self.to_device)
}
else:
batch_dict = {
self._input_type: node_dict[self._input_type][:self.batch_size]
}
batch_labels_key = f'{self._input_type}.nlabels'
if batch_labels_key in msg:
batch_labels = msg[batch_labels_key].to(self.to_device)
Expand Down Expand Up @@ -426,7 +432,10 @@ def _collate_fn(

if self.sampling_config.sampling_type in [SamplingType.NODE,
SamplingType.SUBGRAPH]:
batch = ids[:self.batch_size]
if msg.get('batch') is not None:
batch = msg['batch'].to(self.to_device)
else:
batch = ids[:self.batch_size]
batch_labels = msg['nlabels'].to(self.to_device) if 'nlabels' in msg else None
else:
batch = None
Expand Down
11 changes: 11 additions & 0 deletions graphlearn_torch/python/distributed/dist_neighbor_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,7 @@ async def _sample_from_nodes(
if is_hetero:
assert input_type is not None
src_dict = inducer.init_node({input_type: input_seeds})
batch = src_dict
out_nodes, out_rows, out_cols, out_edges = {}, {}, {}, {}
num_sampled_nodes, num_sampled_edges = {}, {}
merge_dict(src_dict, out_nodes)
Expand Down Expand Up @@ -329,6 +330,7 @@ async def _sample_from_nodes(
{etype: torch.cat(eids) for etype, eids in out_edges.items()}
if self.with_edge else None
),
batch=batch,
num_sampled_nodes=num_sampled_nodes,
num_sampled_edges=num_sampled_edges,
input_type=input_type,
Expand All @@ -337,6 +339,7 @@ async def _sample_from_nodes(

else:
srcs = inducer.init_node(input_seeds)
batch = srcs
out_nodes, out_edges = [], []
num_sampled_nodes, num_sampled_edges = [], []
out_nodes.append(srcs)
Expand All @@ -359,6 +362,7 @@ async def _sample_from_nodes(
row=torch.cat([e[0] for e in out_edges]),
col=torch.cat([e[1] for e in out_edges]),
edge=(torch.cat([e[2] for e in out_edges]) if self.with_edge else None),
batch=batch,
num_sampled_nodes=num_sampled_nodes,
num_sampled_edges=num_sampled_edges,
metadata={}
Expand Down Expand Up @@ -717,6 +721,10 @@ async def _colloate_fn(
result_map[f'{as_str(etype)}.efeats'] = efeats
elif self.edge_dir == 'in':
result_map[f'{as_str(reverse_edge_type(etype))}.efeats'] = efeats
# Collect batch info
if output.batch is not None:
for ntype, batch in output.batch.items():
result_map[f'{as_str(ntype)}.batch'] = batch
else:
result_map['ids'] = output.node
result_map['rows'] = output.row
Expand All @@ -743,5 +751,8 @@ async def _colloate_fn(
fut = self.dist_edge_feature.async_get(eids)
efeats = await wrap_torch_future(fut)
result_map['efeats'] = efeats
# Collect batch info
if output.batch is not None:
result_map['batch'] = output.batch

return result_map
Loading