tglite.TBlock

TBlock captures 1-hop relationships between node/time pairs and their neighbors for doing computations. Figure shows the internal structure of a TBlock and the doubly-linked list design with next and prev pointing to sampled neighbors’ TBlock. To have a general idea of how TBlock works, please refer to the tutorial.

tblock-structure

Diagram of the doubly-linked list design and internal structure of a TBlock (destination node-time is denoted as <i,t>).

class tglite.TBlock(ctx: TContext, layer: int, dstnodes: np.ndarray, dsttimes: np.ndarray, dstindex: np.ndarray = None, srcnodes: np.ndarray = None, eid: np.ndarray = None, ets: np.ndarray = None)

Captures 1-hop relations between node/time pairs and their neighbors for doing computations, such as segmented softmax and message-passing aggregation.

__init__(ctx: TContext, layer: int, dstnodes: np.ndarray, dsttimes: np.ndarray, dstindex: np.ndarray = None, srcnodes: np.ndarray = None, eid: np.ndarray = None, ets: np.ndarray = None)

Internal constructor for creating a TBlock.

Parameters:
  • ctx (TContext) – The TContext.

  • layer (int) – The layer in the GNN.

  • dstnodes (np.ndarray) – The destination nodes.

  • dstindex (np.ndarray) – The indices of destination nodes in dstnodes.

  • srcnodes (np.ndarray) – The source nodes of the edges.

  • eid (np.ndarray) – The edge indices.

  • ets (np.ndarray) – The edge timestamps.

Query TBlock attributes

g

Returns the TGraph associated with this TBlock.

layer

Returns the GNN layer to which this TBlock belongs.

dstnodes

Returns the full destination nodes.

dsttimes

Returns the destination node timestamps.

num_dst()

Returns the length of destination node array.

Query neighbor attributes

dstindex

Returns the indices of destination nodes in self.dstnodes() that are used for sampling.

srcnodes

Return the source nodes (temporally sampled neighbors).

num_src()

Returns the length of source node array when self.has_nbrs() is True.

eid

Returns the edge indices, which are connections towards sampled neighbors.

ets

Returns the edge timestamps.

num_edges()

Returns the number of edges in the block when self.has_nbrs() is True.

has_nbrs()

Returns True when the block has the neighbor attributes, including dstindex, srcnodes, eid and ets.

Query data

dstdata

Returns the destination node data.

srcdata

Returns the source node data.

edata

Returns the edge data.

Query Cache

allnodes()

Returns a tensor containing the destination nodes concatenated with the source nodes (if available) in pre-defined TGraph's storage device.

uniq_src()

Returns a Tensor tuple: (the unique source node indices, the indices of the unique array that reconstructs the source node array) in pre-defined TGraph's storage device.

efeat()

Returns the edge features in TGraph's computation device, always use pinned memory if possible.

nfeat()

Returns the node features in TGraph's computation device, always use pinned memory if possible.

srcfeat()

Returns the source node features in TGraph's computation device, always use pinned memory if possible.

dstfeat()

Returns the destination node features in TGraph's computation device, always use pinned memory if possible.

mem_data()

Returns node memory in TGraph's computation device, always use pinned memory if possible.

mail()

Returns the node mails in TGraph's computation device, always use pinned memory if possible.

time_deltas()

Computes the timestamp differences between destination nodes (used for sampling) and edges and returns them as a tensor in pre-defined TGraph's computation device.

Neighbor ops

set_nbrs(dstindex, srcnodes, eid, ets)

Sets the neighbor attributes for the block.

clear_nbrs()

Clears the neighbor attributes and related cache.

Linked list ops

prev

Returns the previous TBlock.

next

Returns the next TBlock.

next_block([include_dst, use_dst_times])

Generates the next TBlock with neighbor information.

Execution ops

apply(fn[, need_nbrs, run_hooks])

Applies an operator to the block itself and returns the output.

register_hook(hook)

Registers a hook for running post-processing.

run_hooks(input)

Runs registered hooks on the input tensor in reversed order.

clear_hooks()

Clears all the hooks.