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

[BugFix] Fix a bug in using TUDataset #225

Merged
merged 2 commits into from
Apr 17, 2021
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
4 changes: 2 additions & 2 deletions cogdl/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,12 +648,12 @@ def _sample_adj(self, batch_size, indices, indptr, size):

def csr_subgraph(self, node_idx):
indptr, indices, nodes, edges = subgraph_c(self._adj.row_ptr, self._adj.col, node_idx.cpu())
nodes = nodes.to(self._adj.device)
nodes_idx = node_idx.to(self._adj.device)
edge_weight = self.edge_weight[edges]

data = Graph(row_ptr=indptr, col=indices, weight=edge_weight)
for key in self.__keys__():
data[key] = self[key][nodes]
data[key] = self[key][nodes_idx]
return data

def subgraph(self, node_idx):
Expand Down
2 changes: 1 addition & 1 deletion cogdl/datasets/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def build_dataset_from_path(data_path, task):
"ogbn-arxiv": "cogdl.datasets.ogb",
"ogbn-products": "cogdl.datasets.ogb",
"ogbn-proteins": "cogdl.datasets.ogb",
"ogbn-mag": "cogdl.datasets.pyg_ogb",
"ogbn-mag": "cogdl.datasets.ogb",
"ogbn-papers100M": "cogdl.datasets.ogb",
"ogbg-molbace": "cogdl.datasets.ogb",
"ogbg-molhiv": "cogdl.datasets.ogb",
Expand Down
2 changes: 1 addition & 1 deletion cogdl/datasets/tu_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def read_tu_data(folder, prefix):
if x is not None:
x = x[:, num_node_attributes(x) :]
if edge_attr is not None:
edge_attr = edge_attr[:, num_edge_attributes(edge_attr)]
edge_attr = edge_attr[:, : num_edge_attributes(edge_attr)]

graphs = _split(edge_index, batch=batch, x=x, y=y, edge_attr=edge_attr)
return graphs, y
Expand Down
15 changes: 13 additions & 2 deletions cogdl/trainers/distributed_sampled_trainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@
from cogdl.trainers.base_trainer import BaseTrainer


import resource

rlimit = resource.getrlimit(resource.RLIMIT_NOFILE)
resource.setrlimit(resource.RLIMIT_NOFILE, (4096, rlimit[1]))


class DistributedSampledTrainer(BaseTrainer):
def __init__(self, args):
super(DistributedSampledTrainer, self).__init__(args)
Expand Down Expand Up @@ -274,6 +280,10 @@ def _test_step(self, split="val"):
return super(DistributedNeighborSamplerTrainer, self)._test_step()


def batcher(data):
return data[0]


@register_trainer("dist_saint")
class DistributedSAINTTrainer(DistributedSampledTrainer, SAINTTrainer):
@staticmethod
Expand Down Expand Up @@ -304,10 +314,11 @@ def build_dataloader(self, dataset, rank):
dataset=train_dataset,
batch_size=1,
shuffle=False,
num_workers=0,
num_workers=4,
persistent_workers=True,
pin_memory=True,
sampler=train_sampler,
collate_fn=lambda x: x[0],
collate_fn=batcher,
)

test_loader = NeighborSampler(
Expand Down