-
Notifications
You must be signed in to change notification settings - Fork 2
/
hooks.py
71 lines (63 loc) · 2.11 KB
/
hooks.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from dgl import DGLHeteroGraph
from torch import Tensor
class PopularityPredictorHooks:
"""
Used to implement other `forward` computation.
Workflow of popularity predictor forward:
-> process_graph
-> on_conv_start
-> [
-> on_conv_step_start
-> conv
-> on_conv_step_end
] * 2
-> on_conv_end
-> prediction
"""
def on_conv_start(self, g: DGLHeteroGraph, feats_dim: int) -> DGLHeteroGraph:
"""
Hook before predefined graph convolution.
:param g: heterogeneous graph in workflow.
:param feats_dim: feature dimension.
:return: DGLHeteroGraph
"""
return g
def on_conv_end(self, g: DGLHeteroGraph, feats_dim: int) -> DGLHeteroGraph:
"""
Hook after predefined graph convolution.
:param g: heterogeneous graph in workflow.
:param feats_dim: feature dimension.
:return: DGLHeteroGraph
"""
return g
def on_conv_step_start(self, g: DGLHeteroGraph, feats_dim: int) -> DGLHeteroGraph:
"""
Hook before steps in predefined graph convolution.
:param g: heterogeneous graph in workflow.
:param feats_dim: feature dimension.
:return: DGLHeteroGraph
"""
return g
def on_conv_step_end(self, g: DGLHeteroGraph, feats_dim: int) -> DGLHeteroGraph:
"""
Hook after steps in predefined graph convolution.
:param g: heterogeneous graph in workflow.
:param feats_dim: feature dimension.
:return: DGLHeteroGraph
"""
return g
def on_readout_start(self, g: DGLHeteroGraph, feats_dim: int) -> DGLHeteroGraph:
"""
Hook before graph readout for prediction.
:param g: heterogeneous graph in workflow.
:param feats_dim: feature dimension.
:return: DGLHeteroGraph
"""
return g
def on_readout_end(self, popularity: Tensor) -> Tensor:
"""
Hook after graph readout for prediction.
:param popularity: result of graph readout.
:return: Tensor
"""
return popularity