Skip to content

Commit

Permalink
Fix not only preprocess but also postprocess issue.
Browse files Browse the repository at this point in the history
  • Loading branch information
mfbalin committed Jan 30, 2024
1 parent dcbfb4e commit 21fe633
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/sampling/graphbolt/node_classification.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def create_dataloader(
# [Role]:
# Initialize a neighbor sampler for sampling the neighborhoods of nodes.
############################################################################
datapipe = datapipe.sample_neighbor2(
datapipe = datapipe.sample_neighbor(
graph, fanout if job != "infer" else [-1]
)

Expand Down
16 changes: 14 additions & 2 deletions python/dgl/graphbolt/subgraph_sampler.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
from collections import defaultdict
from typing import Dict

import torchdata.dataloader2.graph as dp_utils

from torch.utils.data import functional_datapipe
from torchdata.datapipes.iter import Mapper

from .base import etype_str_to_tuple
from .internal import compact_temporal_nodes, unique_and_compact
Expand Down Expand Up @@ -36,6 +37,12 @@ def __init__(
datapipe,
):
super().__init__(datapipe, lambda x: x)

def _postprocess(minibatch):
delattr(minibatch, "seeds_timestamp")
return minibatch

self.datapipe = self.datapipe.transform(_postprocess)
self.append_sampling_step(MiniBatchTransformer, self._preprocess)

def _preprocess(self, minibatch):
Expand Down Expand Up @@ -192,4 +199,9 @@ def _node_pairs_preprocess(self, minibatch):
)

def append_sampling_step(self, datapipe_type, *args, **kwargs):
self.datapipe = datapipe_type(self.datapipe, *args, **kwargs)
parent_datapipe = self.datapipe.datapipe
dp_utils.replace_dp(
dp_utils.traverse_dps(self.datapipe),
parent_datapipe,
datapipe_type(parent_datapipe, *args, **kwargs),
)

0 comments on commit 21fe633

Please sign in to comment.