MCPcopy
hub / github.com/dmlc/dgl / forward

Method forward

python/dgl/backend/pytorch/sparse.py:687–718  ·  view source on GitHub ↗

Forward function. Pseudo-code: .. code:: python score = dgl.EData(g, score) score_max = score.dst_max() # of type dgl.NData score = score - score_max # edge_sub_dst, ret dgl.EData score_sum = score.dst_sum() # of type dgl.NData

(ctx, gidx, score, eids, norm_by)

Source from the content-addressed store, hash-verified

685class EdgeSoftmax(th.autograd.Function):
686 @staticmethod
687 def forward(ctx, gidx, score, eids, norm_by):
688 """Forward function.
689
690 Pseudo-code:
691
692 .. code:: python
693
694 score = dgl.EData(g, score)
695 score_max = score.dst_max() # of type dgl.NData
696 score = score - score_max # edge_sub_dst, ret dgl.EData
697 score_sum = score.dst_sum() # of type dgl.NData
698 out = score / score_sum # edge_div_dst, ret dgl.EData
699 return out.data
700 """
701 # remember to save the graph to backward cache before making it
702 # a local variable
703 if not is_all(eids):
704 gidx = gidx.edge_subgraph([eids], True).graph
705 if norm_by == "src":
706 gidx = gidx.reverse()
707 # Note: Now _edge_softmax_forward op only supports CPU
708 # TODO(Zhejiang): We will support GPU in the future
709 if score.is_cuda:
710 score_max = _gspmm(gidx, "copy_rhs", "max", None, score)[0]
711 score = th.exp(_gsddmm(gidx, "sub", score, score_max, "e", "v"))
712 score_sum = _gspmm(gidx, "copy_rhs", "sum", None, score)[0]
713 out = _gsddmm(gidx, "div", score, score_sum, "e", "v")
714 else:
715 out = _edge_softmax_forward(gidx, score, "copy_rhs")
716 ctx.backward_cache = gidx
717 ctx.save_for_backward(out)
718 return out
719
720 @staticmethod
721 def backward(ctx, grad_out):

Callers

nothing calls this directly

Calls 6

is_allFunction · 0.85
_gspmmFunction · 0.85
_gsddmmFunction · 0.85
_edge_softmax_forwardFunction · 0.85
reverseMethod · 0.80
edge_subgraphMethod · 0.45

Tested by

no test coverage detected