Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
dgl
Commits
88833e6f
Unverified
Commit
88833e6f
authored
Dec 21, 2023
by
Ramon Zhou
Committed by
GitHub
Dec 21, 2023
Browse files
[Misc] Delete all the DGLMiniBatch from docs and comments. (#6805)
parent
a9656e2c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
12 additions
and
50 deletions
+12
-50
docs/source/api/python/dgl.graphbolt.rst
docs/source/api/python/dgl.graphbolt.rst
+0
-2
docs/source/guide/minibatch-link.rst
docs/source/guide/minibatch-link.rst
+10
-40
docs/source/guide/minibatch-parallelism.rst
docs/source/guide/minibatch-parallelism.rst
+1
-2
python/dgl/graphbolt/feature_fetcher.py
python/dgl/graphbolt/feature_fetcher.py
+1
-1
tests/python/pytorch/graphbolt/test_feature_fetcher.py
tests/python/pytorch/graphbolt/test_feature_fetcher.py
+0
-5
No files found.
docs/source/api/python/dgl.graphbolt.rst
View file @
88833e6f
...
@@ -111,8 +111,6 @@ features. It is the basic unit for training a GNN model.
...
@@ -111,8 +111,6 @@ features. It is the basic unit for training a GNN model.
:template: graphbolt_classtemplate.rst
:template: graphbolt_classtemplate.rst
MiniBatch
MiniBatch
DGLMiniBatch
DGLMiniBatchConverter
NegativeSampler
NegativeSampler
...
...
docs/source/guide/minibatch-link.rst
View file @
88833e6f
...
@@ -95,22 +95,8 @@ Define a GraphSAGE model for minibatch training
...
@@ -95,22 +95,8 @@ Define a GraphSAGE model for minibatch training
When a negative sampler is provided, the data loader will generate positive and
When a negative sampler is provided, the data loader will generate positive and
negative node pairs for each minibatch besides the *Message Flow Graphs* (MFGs).
negative node pairs for each minibatch besides the *Message Flow Graphs* (MFGs).
Let's define a utility function to compact node pairs as follows:
Use `node_pairs_with_labels` to get compact node pairs with corresponding
labels.
.. code:: python
def to_binary_link_dgl_computing_pack(data: gb.DGLMiniBatch):
"""Convert the minibatch to a training pair and a label tensor."""
pos_src, pos_dst = data.positive_node_pairs
neg_src, neg_dst = data.negative_node_pairs
node_pairs = (
torch.cat((pos_src, neg_src), dim=0),
torch.cat((pos_dst, neg_dst), dim=0),
)
pos_label = torch.ones_like(pos_src)
neg_label = torch.zeros_like(neg_src)
labels = torch.cat([pos_label, neg_label], dim=0)
return (node_pairs, labels.float())
Training loop
Training loop
...
@@ -130,7 +116,7 @@ above.
...
@@ -130,7 +116,7 @@ above.
start_epoch_time = time.time()
start_epoch_time = time.time()
for step, data in enumerate(dataloader):
for step, data in enumerate(dataloader):
# Unpack MiniBatch.
# Unpack MiniBatch.
compacted_pairs, labels =
to_binary_link_dgl_computing_pack(data)
compacted_pairs, labels =
data.node_pairs_with_labels
node_feature = data.node_features["feat"]
node_feature = data.node_features["feat"]
# Convert sampled subgraphs to DGL blocks.
# Convert sampled subgraphs to DGL blocks.
blocks = data.blocks
blocks = data.blocks
...
@@ -240,26 +226,9 @@ If you want to give your own negative sampling function, just inherit from the
...
@@ -240,26 +226,9 @@ If you want to give your own negative sampling function, just inherit from the
datapipe = datapipe.customized_sample_negative(5, node_degrees)
datapipe = datapipe.customized_sample_negative(5, node_degrees)
For heterogeneous graphs, node pairs are grouped by edge types.
For heterogeneous graphs, node pairs are grouped by edge types. The training
loop is again almost the same as that on homogeneous graph, except for computing
.. code:: python
loss on specific edge type.
def to_binary_link_dgl_computing_pack(data: gb.DGLMiniBatch, etype):
"""Convert the minibatch to a training pair and a label tensor."""
pos_src, pos_dst = data.positive_node_pairs[etype]
neg_src, neg_dst = data.negative_node_pairs[etype]
node_pairs = (
torch.cat((pos_src, neg_src), dim=0),
torch.cat((pos_dst, neg_dst), dim=0),
)
pos_label = torch.ones_like(pos_src)
neg_label = torch.zeros_like(neg_src)
labels = torch.cat([pos_label, neg_label], dim=0)
return (node_pairs, labels.float())
The training loop is again almost the same as that on homogeneous graph,
except for computing loss on specific edge type.
.. code:: python
.. code:: python
...
@@ -272,7 +241,7 @@ except for computing loss on specific edge type.
...
@@ -272,7 +241,7 @@ except for computing loss on specific edge type.
start_epoch_time = time.time()
start_epoch_time = time.time()
for step, data in enumerate(dataloader):
for step, data in enumerate(dataloader):
# Unpack MiniBatch.
# Unpack MiniBatch.
compacted_pairs, labels =
to_binary_link_dgl_computing_pack(data, category)
compacted_pairs, labels =
data.node_pairs_with_labels
node_features = {
node_features = {
ntype: data.node_features[(ntype, "feat")]
ntype: data.node_features[(ntype, "feat")]
for ntype in data.blocks[0].srctypes
for ntype in data.blocks[0].srctypes
...
@@ -282,11 +251,12 @@ except for computing loss on specific edge type.
...
@@ -282,11 +251,12 @@ except for computing loss on specific edge type.
# Get the embeddings of the input nodes.
# Get the embeddings of the input nodes.
y = model(blocks, node_feature)
y = model(blocks, node_feature)
logits = model.predictor(
logits = model.predictor(
y[category][compacted_pairs[0]] * y[category][compacted_pairs[1]]
y[category][compacted_pairs[category][0]]
* y[category][compacted_pairs[category][1]]
).squeeze()
).squeeze()
# Compute loss.
# Compute loss.
loss = F.binary_cross_entropy_with_logits(logits, labels)
loss = F.binary_cross_entropy_with_logits(logits, labels
[category]
)
optimizer.zero_grad()
optimizer.zero_grad()
loss.backward()
loss.backward()
optimizer.step()
optimizer.step()
...
...
docs/source/guide/minibatch-parallelism.rst
View file @
88833e6f
...
@@ -11,8 +11,7 @@ generate a minibatch, including:
...
@@ -11,8 +11,7 @@ generate a minibatch, including:
* Sample neighbors for each seed from graph.
* Sample neighbors for each seed from graph.
* Exclude seed edges from the sampled subgraphs.
* Exclude seed edges from the sampled subgraphs.
* Fetch node and edge features for the sampled subgraphs.
* Fetch node and edge features for the sampled subgraphs.
* Convert the sampled subgraphs to DGLMiniBatches.
* Copy the MiniBatches to the target device.
* Copy the DGLMiniBatches to the target device.
.. code:: python
.. code:: python
...
...
python/dgl/graphbolt/feature_fetcher.py
View file @
88833e6f
...
@@ -107,7 +107,7 @@ class FeatureFetcher(MiniBatchTransformer):
...
@@ -107,7 +107,7 @@ class FeatureFetcher(MiniBatchTransformer):
if
original_edge_ids
is
None
:
if
original_edge_ids
is
None
:
continue
continue
if
is_heterogeneous
:
if
is_heterogeneous
:
# Convert edge type to string
for DGLMiniBatch
.
# Convert edge type to string.
original_edge_ids
=
{
original_edge_ids
=
{
etype_tuple_to_str
(
key
)
etype_tuple_to_str
(
key
)
if
isinstance
(
key
,
tuple
)
if
isinstance
(
key
,
tuple
)
...
...
tests/python/pytorch/graphbolt/test_feature_fetcher.py
View file @
88833e6f
...
@@ -9,11 +9,6 @@ from torchdata.datapipes.iter import Mapper
...
@@ -9,11 +9,6 @@ from torchdata.datapipes.iter import Mapper
from
.
import
gb_test_utils
from
.
import
gb_test_utils
class
MiniBatchType
(
Enum
):
MiniBatch
=
1
DGLMiniBatch
=
2
def
test_FeatureFetcher_invoke
():
def
test_FeatureFetcher_invoke
():
# Prepare graph and required datapipes.
# Prepare graph and required datapipes.
graph
=
gb_test_utils
.
rand_csc_graph
(
20
,
0.15
,
bidirection_edge
=
True
)
graph
=
gb_test_utils
.
rand_csc_graph
(
20
,
0.15
,
bidirection_edge
=
True
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment