"This tutorial shows how to train a multi-layer GraphSAGE for node\n",
"classification on ``ogbn-arxiv`` provided by [Open Graph\n",
"Benchmark (OGB)](https://ogb.stanford.edu/). The dataset contains around\n",
"170 thousand nodes and 1 million edges.\n",
"\n",
"[](https://colab.research.google.com/github/dmlc/dgl/blob/master/notebooks/stochastic_training/node_classification.ipynb) [](https://github.com/dmlc/dgl/blob/master/notebooks/stochastic_training/node_classification.ipynb)\n",
"\n",
"By the end of this tutorial, you will be able to\n",
"\n",
"- Train a GNN model for node classification on a single GPU with DGL's\n",
"Dataset consists of graph, feature and tasks. You can get the training-validation-test set from the tasks. Seed nodes and corresponding labels are already stored in each training-validation-test set. Other metadata such as number of classes are also stored in the tasks. In this dataset, there is only one task: `node classification`."
"## Defining Neighbor Sampler and Data Loader in DGL\n",
"\n",
"DGL provides tools to iterate over the dataset in minibatches while generating the computation dependencies to compute their outputs with the MFGs above. For node classification, you can use `dgl.graphbolt.MultiProcessDataLoader` for iterating over the dataset. It accepts a data pipe that generates minibatches of nodes and their labels, sample neighbors for each node, and generate the computation dependencies in the form of MFGs. Feature fetching, block creation and copying to target device are also supported. All these operations are split into separate stages in the data pipe, so that you can customize the data pipeline by inserting your own operations.\n",
"\n",
"Let’s say that each node will gather messages from 4 neighbors on each layer. The code defining the data loader and neighbor sampler will look like the following.\n"
"The following initializes the model and defines the optimizer.\n"
],
"metadata": {
"id": "OGLN3kCcwCA8"
}
},
{
"cell_type": "code",
"source": [
"opt = torch.optim.Adam(model.parameters())"
],
"metadata": {
"id": "dET8i_hewLUi"
},
"execution_count": null,
"outputs": []
},
{
"cell_type": "markdown",
"source": [
"When computing the validation score for model selection, usually you can also do neighbor sampling. To do that, you need to define another data loader."