"docs/git@developer.sourcefind.cn:OpenDAS/vision.git" did not exist on "aaee8ff1f75941dd2be82a180826a052965ce84c"
Unverified Commit 9120b5a7 authored by Rhett Ying's avatar Rhett Ying Committed by GitHub
Browse files

[Doc] specify backend as pytorch for tutorials (#5198)

parent ebca7860
...@@ -21,6 +21,8 @@ networks with PyTorch. ...@@ -21,6 +21,8 @@ networks with PyTorch.
""" """
import os
os.environ['DGLBACKEND'] = 'pytorch'
import torch import torch
import torch.nn as nn import torch.nn as nn
import torch.nn.functional as F import torch.nn.functional as F
......
...@@ -30,6 +30,8 @@ By the end of this tutorial you will be able to: ...@@ -30,6 +30,8 @@ By the end of this tutorial you will be able to:
# center node to the leaves. # center node to the leaves.
# #
import os
os.environ['DGLBACKEND'] = 'pytorch'
import numpy as np import numpy as np
import torch import torch
......
...@@ -18,6 +18,8 @@ GNN for node classification <1_introduction>`. ...@@ -18,6 +18,8 @@ GNN for node classification <1_introduction>`.
""" """
import os
os.environ['DGLBACKEND'] = 'pytorch'
import torch import torch
import torch.nn as nn import torch.nn as nn
import torch.nn.functional as F import torch.nn.functional as F
......
...@@ -13,6 +13,8 @@ By the end of this tutorial, you will be able to ...@@ -13,6 +13,8 @@ By the end of this tutorial, you will be able to
(Time estimate: 18 minutes) (Time estimate: 18 minutes)
""" """
import os
os.environ['DGLBACKEND'] = 'pytorch'
import torch import torch
import torch.nn as nn import torch.nn as nn
import torch.nn.functional as F import torch.nn.functional as F
......
...@@ -88,7 +88,7 @@ interactions.head() ...@@ -88,7 +88,7 @@ interactions.head()
# #
import os import os
os.environ['DGLBACKEND'] = 'pytorch'
import torch import torch
import dgl import dgl
......
...@@ -22,6 +22,8 @@ Here we store the node labels as node data in the DGL Graph. ...@@ -22,6 +22,8 @@ Here we store the node labels as node data in the DGL Graph.
.. code-block:: python .. code-block:: python
import os
os.environ['DGLBACKEND'] = 'pytorch'
import dgl import dgl
import torch as th import torch as th
from ogb.nodeproppred import DglNodePropPredDataset from ogb.nodeproppred import DglNodePropPredDataset
......
...@@ -19,6 +19,8 @@ into a training graph, validation edges and test edges with :class:`~dgl.data.As ...@@ -19,6 +19,8 @@ into a training graph, validation edges and test edges with :class:`~dgl.data.As
.. code-block:: python .. code-block:: python
import os
os.environ['DGLBACKEND'] = 'pytorch'
import dgl import dgl
import torch as th import torch as th
from ogb.linkproppred import DglLinkPropPredDataset from ogb.linkproppred import DglLinkPropPredDataset
......
...@@ -25,6 +25,8 @@ Sampling for GNN Training <L0_neighbor_sampling_overview>`. ...@@ -25,6 +25,8 @@ Sampling for GNN Training <L0_neighbor_sampling_overview>`.
# OGB already prepared the data as DGL graph. # OGB already prepared the data as DGL graph.
# #
import os
os.environ['DGLBACKEND'] = 'pytorch'
import dgl import dgl
import torch import torch
import numpy as np import numpy as np
......
...@@ -52,6 +52,8 @@ Sampling for Node Classification <L1_large_node_classification>`. ...@@ -52,6 +52,8 @@ Sampling for Node Classification <L1_large_node_classification>`.
# :doc:`previous tutorial <L1_large_node_classification>`. # :doc:`previous tutorial <L1_large_node_classification>`.
# #
import os
os.environ['DGLBACKEND'] = 'pytorch'
import dgl import dgl
import torch import torch
import numpy as np import numpy as np
......
...@@ -13,6 +13,8 @@ for stochastic GNN training. It assumes that ...@@ -13,6 +13,8 @@ for stochastic GNN training. It assumes that
""" """
import os
os.environ['DGLBACKEND'] = 'pytorch'
import dgl import dgl
import torch import torch
import numpy as np import numpy as np
......
...@@ -45,6 +45,8 @@ message passing APIs. ...@@ -45,6 +45,8 @@ message passing APIs.
# aggregation on a node :math:`u` only involves summing over the neighbors' # aggregation on a node :math:`u` only involves summing over the neighbors'
# representations :math:`h_v`, we can simply use builtin functions: # representations :math:`h_v`, we can simply use builtin functions:
import os
os.environ['DGLBACKEND'] = 'pytorch'
import torch as th import torch as th
import torch.nn as nn import torch.nn as nn
import torch.nn.functional as F import torch.nn.functional as F
......
...@@ -136,6 +136,8 @@ multiple edges among any given pair. ...@@ -136,6 +136,8 @@ multiple edges among any given pair.
# efficient :class:`builtin R-GCN layer module <dgl.nn.pytorch.conv.RelGraphConv>`. # efficient :class:`builtin R-GCN layer module <dgl.nn.pytorch.conv.RelGraphConv>`.
# #
import os
os.environ['DGLBACKEND'] = 'pytorch'
import dgl import dgl
import torch import torch
import torch.nn as nn import torch.nn as nn
......
...@@ -86,6 +86,8 @@ Line Graph Neural Network ...@@ -86,6 +86,8 @@ Line Graph Neural Network
# The following code snippet verifies that there are more intra-class edges # The following code snippet verifies that there are more intra-class edges
# than inter-class. # than inter-class.
import os
os.environ['DGLBACKEND'] = 'pytorch'
import torch import torch
import torch as th import torch as th
import torch.nn as nn import torch.nn as nn
......
...@@ -104,6 +104,8 @@ structure-free normalization, in the style of attention. ...@@ -104,6 +104,8 @@ structure-free normalization, in the style of attention.
# DGL provides an off-the-shelf implementation of the GAT layer under the ``dgl.nn.<backend>`` # DGL provides an off-the-shelf implementation of the GAT layer under the ``dgl.nn.<backend>``
# subpackage. Simply import the ``GATConv`` as the follows. # subpackage. Simply import the ``GATConv`` as the follows.
import os
os.environ['DGLBACKEND'] = 'pytorch'
from dgl.nn.pytorch import GATConv from dgl.nn.pytorch import GATConv
############################################################### ###############################################################
......
...@@ -58,6 +58,8 @@ Tree-LSTM in DGL ...@@ -58,6 +58,8 @@ Tree-LSTM in DGL
from collections import namedtuple from collections import namedtuple
import os
os.environ['DGLBACKEND'] = 'pytorch'
import dgl import dgl
from dgl.data.tree import SSTDataset from dgl.data.tree import SSTDataset
......
...@@ -50,6 +50,8 @@ Generative Models of Graphs ...@@ -50,6 +50,8 @@ Generative Models of Graphs
# you can write the code as follows. # you can write the code as follows.
# #
import os
os.environ['DGLBACKEND'] = 'pytorch'
import dgl import dgl
g = dgl.DGLGraph() g = dgl.DGLGraph()
......
...@@ -67,6 +67,8 @@ offers a different perspective. The tutorial describes how to implement a Capsul ...@@ -67,6 +67,8 @@ offers a different perspective. The tutorial describes how to implement a Capsul
# #
# Here's how we set up the graph and initialize node and edge features. # Here's how we set up the graph and initialize node and edge features.
import os
os.environ['DGLBACKEND'] = 'pytorch'
import matplotlib.pyplot as plt import matplotlib.pyplot as plt
import numpy as np import numpy as np
import torch as th import torch as th
......
...@@ -70,6 +70,8 @@ to start the distributed backend at the beginning of each process. We use ...@@ -70,6 +70,8 @@ to start the distributed backend at the beginning of each process. We use
process ID, which should be an integer from `0` to `world_size - 1`. process ID, which should be an integer from `0` to `world_size - 1`.
""" """
import os
os.environ['DGLBACKEND'] = 'pytorch'
import torch.distributed as dist import torch.distributed as dist
......
...@@ -33,6 +33,8 @@ models with multi-GPU with ``DistributedDataParallel``. ...@@ -33,6 +33,8 @@ models with multi-GPU with ``DistributedDataParallel``.
# tutorial. # tutorial.
# #
import os
os.environ['DGLBACKEND'] = 'pytorch'
import dgl import dgl
import torch import torch
import numpy as np import numpy as np
......
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