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
6bc92068
"git@developer.sourcefind.cn:renzhc/diffusers_dcu.git" did not exist on "a0c22997fd45770fffd9b454625e9ab525fa2b16"
Unverified
Commit
6bc92068
authored
Sep 27, 2020
by
Quan (Andy) Gan
Committed by
GitHub
Sep 27, 2020
Browse files
[Doc] fix minibatch user guide broken code (#2233)
parent
6b0d42db
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
10 deletions
+35
-10
docs/source/guide/minibatch-edge.rst
docs/source/guide/minibatch-edge.rst
+14
-2
docs/source/guide/minibatch-link.rst
docs/source/guide/minibatch-link.rst
+19
-6
docs/source/guide/minibatch-node.rst
docs/source/guide/minibatch-node.rst
+2
-2
No files found.
docs/source/guide/minibatch-edge.rst
View file @
6bc92068
...
...
@@ -188,7 +188,7 @@ classification/regression.
..
code
::
python
class
StochasticTwoLayerRGCN
(
nn
.
Module
):
def
__init__
(
self
,
in_feat
,
hidden_feat
,
out_feat
):
def
__init__
(
self
,
in_feat
,
hidden_feat
,
out_feat
,
rel_names
):
super
().
__init__
()
self
.
conv1
=
dglnn
.
HeteroGraphConv
({
rel
:
dglnn
.
GraphConv
(
in_feat
,
hidden_feat
,
norm
=
'right'
)
...
...
@@ -226,6 +226,18 @@ over the edge types for :meth:`~dgl.DGLHeteroGraph.apply_edges`.
edge_subgraph
.
apply_edges
(
self
.
apply_edges
,
etype
=
etype
)
return
edge_subgraph
.
edata
[
'score'
]
class
Model
(
nn
.
Module
):
def
__init__
(
self
,
in_features
,
hidden_features
,
out_features
,
num_classes
,
etypes
):
super
().
__init__
()
self
.
rgcn
=
StochasticTwoLayerRGCN
(
in_features
,
hidden_features
,
out_features
,
etypes
)
self
.
pred
=
ScorePredictor
(
num_classes
,
out_features
)
def
forward
(
self
,
edge_subgraph
,
blocks
,
x
):
x
=
self
.
rgcn
(
blocks
,
x
)
return
self
.
pred
(
edge_subgraph
,
x
)
Data
loader
definition
is
also
very
similar
to
that
of
node
classification
.
The
only
difference
is
that
you
need
:
class
:`~
dgl
.
dataloading
.
pytorch
.
EdgeDataLoader
`
instead
of
...
...
@@ -279,7 +291,7 @@ dictionaries of node types and predictions here.
..
code
::
python
model
=
Model
(
in_features
,
hidden_features
,
out_features
,
num_classes
)
model
=
Model
(
in_features
,
hidden_features
,
out_features
,
num_classes
,
etypes
)
model
=
model
.
cuda
()
opt
=
torch
.
optim
.
Adam
(
model
.
parameters
())
...
...
docs/source/guide/minibatch-link.rst
View file @
6bc92068
...
...
@@ -146,7 +146,7 @@ above.
positive_graph
=
positive_graph
.
to
(
torch
.
device
(
'cuda'
))
negative_graph
=
negative_graph
.
to
(
torch
.
device
(
'cuda'
))
input_features
=
blocks
[
0
].
srcdata
[
'features'
]
pos_score
,
neg_score
=
model
(
positive_graph
,
blocks
,
input_features
)
pos_score
,
neg_score
=
model
(
positive_graph
,
negative_graph
,
blocks
,
input_features
)
loss
=
compute_loss
(
pos_score
,
neg_score
)
opt
.
zero_grad
()
loss
.
backward
()
...
...
@@ -166,7 +166,7 @@ classification/regression.
..
code
::
python
class
StochasticTwoLayerRGCN
(
nn
.
Module
):
def
__init__
(
self
,
in_feat
,
hidden_feat
,
out_feat
):
def
__init__
(
self
,
in_feat
,
hidden_feat
,
out_feat
,
rel_names
):
super
().
__init__
()
self
.
conv1
=
dglnn
.
HeteroGraphConv
({
rel
:
dglnn
.
GraphConv
(
in_feat
,
hidden_feat
,
norm
=
'right'
)
...
...
@@ -197,6 +197,20 @@ over the edge types for :meth:`dgl.DGLHeteroGraph.apply_edges`.
dgl
.
function
.
u_dot_v
(
'x'
,
'x'
,
'score'
),
etype
=
etype
)
return
edge_subgraph
.
edata
[
'score'
]
class
Model
(
nn
.
Module
):
def
__init__
(
self
,
in_features
,
hidden_features
,
out_features
,
num_classes
,
etypes
):
super
().
__init__
()
self
.
rgcn
=
StochasticTwoLayerRGCN
(
in_features
,
hidden_features
,
out_features
,
etypes
)
self
.
pred
=
ScorePredictor
()
def
forward
(
self
,
positive_graph
,
negative_graph
,
blocks
,
x
):
x
=
self
.
rgcn
(
blocks
,
x
)
pos_score
=
self
.
pred
(
positive_graph
,
x
)
neg_score
=
self
.
pred
(
negative_graph
,
x
)
return
pos_score
,
neg_score
Data
loader
definition
is
also
very
similar
to
that
of
edge
classification
/
regression
.
The
only
difference
is
that
you
need
to
give
the
negative
sampler
and
you
will
be
supplying
a
dictionary
of
edge
...
...
@@ -252,7 +266,7 @@ dictionaries of node types and predictions here.
..
code
::
python
model
=
Model
(
in_features
,
hidden_features
,
out_features
,
num_classes
)
model
=
Model
(
in_features
,
hidden_features
,
out_features
,
num_classes
,
etypes
)
model
=
model
.
cuda
()
opt
=
torch
.
optim
.
Adam
(
model
.
parameters
())
...
...
@@ -261,9 +275,8 @@ dictionaries of node types and predictions here.
positive_graph
=
positive_graph
.
to
(
torch
.
device
(
'cuda'
))
negative_graph
=
negative_graph
.
to
(
torch
.
device
(
'cuda'
))
input_features
=
blocks
[
0
].
srcdata
[
'features'
]
edge_labels
=
edge_subgraph
.
edata
[
'labels'
]
edge_predictions
=
model
(
edge_subgraph
,
blocks
,
input_features
)
loss
=
compute_loss
(
edge_labels
,
edge_predictions
)
pos_score
,
neg_score
=
model
(
positive_graph
,
negative_graph
,
blocks
,
input_features
)
loss
=
compute_loss
(
pos_score
,
neg_score
)
opt
.
zero_grad
()
loss
.
backward
()
opt
.
step
()
...
...
docs/source/guide/minibatch-node.rst
View file @
6bc92068
...
...
@@ -184,7 +184,7 @@ removed for simplicity):
..
code
::
python
class
StochasticTwoLayerRGCN
(
nn
.
Module
):
def
__init__
(
self
,
in_feat
,
hidden_feat
,
out_feat
):
def
__init__
(
self
,
in_feat
,
hidden_feat
,
out_feat
,
rel_names
):
super
().
__init__
()
self
.
conv1
=
dglnn
.
HeteroGraphConv
({
rel
:
dglnn
.
GraphConv
(
in_feat
,
hidden_feat
,
norm
=
'right'
)
...
...
@@ -224,7 +224,7 @@ dictionaries of node types and predictions here.
..
code
::
python
model
=
StochasticTwoLayerRGCN
(
in_features
,
hidden_features
,
out_features
)
model
=
StochasticTwoLayerRGCN
(
in_features
,
hidden_features
,
out_features
,
etypes
)
model
=
model
.
cuda
()
opt
=
torch
.
optim
.
Adam
(
model
.
parameters
())
...
...
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