Unverified Commit 65d83ad7 authored by Ramon Zhou's avatar Ramon Zhou Committed by GitHub
Browse files

[GraphBolt] Delete `to_dgl` in graphbolt examples (#6759)


Co-authored-by: default avatarRhett Ying <85214957+Rhett-Ying@users.noreply.github.com>
parent a4cacf13
......@@ -99,7 +99,6 @@ and combined as well.
feature = feature.to(device)
for step, data in tqdm(enumerate(dataloader)):
data = data.to_dgl()
x = feature[data.input_nodes]
hidden_x = layer(data.blocks[0], x) # len(blocks) = 1
if not is_last_layer:
......@@ -107,7 +106,7 @@ and combined as well.
hidden_x = self.dropout(hidden_x)
# By design, our output nodes are contiguous.
y[
data.output_nodes[0] : data.output_nodes[-1] + 1
data.seed_nodes[0] : data.seed_nodes[-1] + 1
] = hidden_x.to(device)
feature = y
......
......@@ -129,8 +129,6 @@ above.
total_loss = 0
start_epoch_time = time.time()
for step, data in enumerate(dataloader):
# Convert MiniBatch to DGLMiniBatch.
data = data.to_dgl()
# Unpack MiniBatch.
compacted_pairs, labels = to_binary_link_dgl_computing_pack(data)
node_feature = data.node_features["feat"]
......@@ -273,8 +271,6 @@ except for computing loss on specific edge type.
total_loss = 0
start_epoch_time = time.time()
for step, data in enumerate(dataloader):
# Convert MiniBatch to DGLMiniBatch.
data = data.to_dgl()
# Unpack MiniBatch.
compacted_pairs, labels = to_binary_link_dgl_computing_pack(data, category)
node_features = {
......
......@@ -56,14 +56,12 @@ putting the list of generated MFGs onto GPU.
Iterating over the DataLoader will yield :class:`~dgl.graphbolt.MiniBatch`
which contains a list of specially created graphs representing the computation
dependencies on each layer. In order to train with DGL, you need to convert them
to :class:`~dgl.graphbolt.DGLMiniBatch`. Then you could access the
*message flow graphs* (MFGs).
dependencies on each layer. In order to train with DGL, you can access the
*message flow graphs* (MFGs) by calling `mini_batch.blocks`.
.. code:: python
mini_batch = next(iter(dataloader))
mini_batch = mini_batch.to_dgl()
print(mini_batch.blocks)
......@@ -132,18 +130,15 @@ The training loop simply consists of iterating over the dataset with the
customized batching iterator. During each iteration that yields
:class:`~dgl.graphbolt.MiniBatch`, we:
1. Convert the :class:`~dgl.graphbolt.MiniBatch` to
:class:`~dgl.graphbolt.DGLMiniBatch`.
2. Access the node features corresponding to the input nodes via
1. Access the node features corresponding to the input nodes via
``data.node_features["feat"]``. These features are already moved to the
target device (CPU or GPU) by the data loader.
3. Access the node labels corresponding to the output nodes via
2. Access the node labels corresponding to the output nodes via
``data.labels``. These labels are already moved to the target device
(CPU or GPU) by the data loader.
4. Feed the list of MFGs and the input node features to the multilayer
3. Feed the list of MFGs and the input node features to the multilayer
GNN and get the outputs.
4. Compute the loss and backpropagate.
......@@ -155,7 +150,6 @@ customized batching iterator. During each iteration that yields
opt = torch.optim.Adam(model.parameters())
for data in dataloader:
data = data.to_dgl()
input_features = data.node_features["feat"]
output_labels = data.labels
output_predictions = model(data.blocks, input_features)
......@@ -235,7 +229,6 @@ dictionaries of node types and predictions here.
opt = torch.optim.Adam(model.parameters())
for data in dataloader:
data = data.to_dgl()
# For heterogeneous graphs, we need to specify the node types and
# feature name when accessing the node features. So does the labels.
input_features = {
......
......@@ -105,10 +105,10 @@ class SAGE(nn.Module):
hidden_x = layer(data.blocks[0], x) # len(blocks) = 1
if not is_last_layer:
hidden_x = F.relu(hidden_x)
# By design, our output nodes are contiguous.
y[
data.output_nodes[0] : data.output_nodes[-1] + 1
] = hidden_x.to(buffer_device, non_blocking=True)
# By design, our seed nodes are contiguous.
y[data.seed_nodes[0] : data.seed_nodes[-1] + 1] = hidden_x.to(
buffer_device, non_blocking=True
)
feature = y
return y
......@@ -311,8 +311,8 @@ def train(args, model, graph, features, train_set):
for step, data in enumerate(dataloader):
# Get node pairs with labels for loss calculation.
compacted_pairs, labels = data.node_pairs_with_labels
node_feature = data.node_features["feat"]
# Convert sampled subgraphs to DGL blocks.
blocks = data.blocks
# Get the embeddings of the input nodes.
......
......@@ -208,9 +208,9 @@ class SAGE(nn.Module):
hidden_x = F.relu(hidden_x)
hidden_x = self.dropout(hidden_x)
# By design, our output nodes are contiguous.
y[
data.output_nodes[0] : data.output_nodes[-1] + 1
] = hidden_x.to(buffer_device)
y[data.seed_nodes[0] : data.seed_nodes[-1] + 1] = hidden_x.to(
buffer_device
)
feature = y
return y
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment