LazyFeature๏ƒ

class dgl.dataloading.base.LazyFeature(name=None, id_=None)[source]๏ƒ

Bases: object

Placeholder for feature prefetching.

One can assign this object to ndata or edata of the graphs returned by various samplersโ€™ sample method. When DGLโ€™s dataloader receives the subgraphs returned by the sampler, it will automatically look up all the ndata and edata whose data is a LazyFeature, replacing them with the actual data of the corresponding nodes/edges from the original graph instead. In particular, for a subgraph returned by the sampler has a LazyFeature with name k in subgraph.ndata[key]:

subgraph.ndata[key] = LazyFeature(k)

Assuming that graph is the original graph, DGLโ€™s dataloader will perform

subgraph.ndata[key] = graph.ndata[k][subgraph.ndata[dgl.NID]]

DGL dataloader performs similar replacement for edata. For heterogeneous graphs, the replacement is:

subgraph.nodes[ntype].data[key] = graph.nodes[ntype].data[k][
    subgraph.nodes[ntype].data[dgl.NID]]

For MFGsโ€™ srcdata (and similarly dstdata), the replacement is

mfg.srcdata[key] = graph.ndata[k][mfg.srcdata[dgl.NID]]
Parameters:
  • name (str) โ€“ The name of the data in the original graph.

  • id (Tensor, optional) โ€“ The ID tensor.