P ERSISTENT M ESSAGE P ASSING
Heiko Strathmann, Mohammadamin Barekatain, Charles Blundell and Petar Veliˇckovi´c
DeepMind { strathmann,barekatain,cblundell,petarv } @google.com
A BSTRACT
Graph neural networks (GNNs) are a powerful inductive bias for modelling algorithmic reasoning procedures and data structures.
Their prowess was mainly demonstrated on tasks featuring Markovian dynamics, where querying any associated data structure depends only on its latest state.
For many tasks of interest, however, it may be highly beneﬁcial to support efﬁcient data structure queries dependent on previous states.
This requires tracking the data structure’s evolution through time, placing signiﬁcant pressure on the GNN’s latent representations.
We introduce Persistent Message Passing (PMP), a mechanism which endows
GNNs with capability of querying past state by explicitly persisting it: rather than overwriting node representations, it creates new nodes whenever required.
PMP generalises out-of-distribution to more than 2 × larger test inputs on dynamic temporal range queries, signiﬁcantly outperforming GNNs which overwrite states.
I NTRODUCTION
Graph neural networks (GNNs) are one of the the most impactful approaches to processing data over irregular domains (e.g., quantum chemistry (Klicpera et al., 2020), drug discovery (Stokes et al., 2020), social network analysis (Pal et al., 2020) and physics simulations (Pfaff et al., 2020)).
Combinatorial optimisation tasks (Nair et al., 2020) have been used to test the limits of GNNs particularly when extrapolation is required.
Extrapolation, in general, is now known to occur in
GNNs only under stringent conditions on their architecture and input featurisation (Xu et al., 2020).
Algorithmic reasoning (Cappart et al., 2021, Section 3.3.) has been the source of much of the knowledge of how to build extrapolating GNNs.
This emerging area of research seeks to emulate each iteration of classical algorithms (Cormen et al., 2009) directly within neural networks.
Through the lens of algorithmic alignment (Xu et al., 2019), GNNs can be constructed that closely mimic iterative computation (Veliˇckovi´c et al., 2019; Tang et al., 2020), linearithmic sequence processing (Freivalds et al., 2019), and pointer-based data structures (Veliˇckovi´c et al., 2020).
Also such approaches are capable of strongly generalising (Yan et al., 2020) and data-efﬁcient planning (Deac et al., 2020).
We study GNN-based reasoners acting on inputs that dynamically change over time.
This setup was previously studied brieﬂy (Veli ˇ ckovi ´ c et al., 2020) and only featured Markovian querying: only using the latest version of the data.
In the non-Markovian case, queries require knowledge of previous versions of the data.
For example, during search, a particular path of a search tree may be expanded but later backtracked.
Efﬁcient queries over histories of states serve as a basis for agents solving
POMDPs.
In economics, historical data are revised and these revisions themselves are of interest.
Most GNNs are designed with Markovian querying in mind: latent representations are overwritten in every step, and the last representation is used to answer queries.
This overloads GNNs’ latents, as all past snapshots of the data must be represented within them.
Further, Hinton (2021) recently makes a strong case for replicated embeddings.
We propose Persistent Message Passing (PMP), replacing overwriting with persisting : when updating a node’s state, a copy of that node is preserved for later use.
To avoid excessive memory usage, PMP has a mechanism to select which nodes to persist.
PMP effectively provides GNNs with an episodic memory (Pritzel et al., 2017) of their previous computations, just as in social networks where dynamically changing graph data may necessitate explicit memory modules (Rossi et al., 2020).
PMP aligns with the broad class of persistent data structures (Driscoll et al., 1989), which further expands the space of general-purpose algorithms that can be neurally executed.
We show on dynamic range querying that our method provides signiﬁcant beneﬁts to overwriting-based GNNs, both in- and out-of-distribution.
z b z d z f z a z c z e v a v c v d v e v f v b (a) b h b
z
d z f z a z c z e v a v c v d v e v f g b (b) b h b b h d b h f b h a b h c b h e g a g c g d g e g f g b φ a φ b φ c φ d φ e φ f (c) h b h d h f h a h c h e b h b b h
d (d)
P ROBLEM SETUP AND PMP ARCHITECTURE
Consider a sequential supervised learning setting: We are given a set of n entities, along with connectivity information between them.
At each time step, we perform operations , which both may change the entities’ states and emit an output that we aim to predict.
Each operation may further be associated with a speciﬁc snapshot of the entities, allowing operations over past states.
More formally, we are given an adjacency matrix, Π ∈ { 0 , 1 } n × n , and a sequence of input pairs ( E (1) , s (1) ) , ( E (2) , s (2) ) , . . .
where E ( t ) =
( e ( t ) 1 , . . .
, e ( t ) n ) are feature vectors (operation), and s ( t ) ∈ { 1 , . .
, t − 1 } are integers (snapshot indices).
The task is to predict operation outputs y ( t ) given ( E ( t ) , s ( t ) ) where we have persistency : ( E ( t ) , s ( t ) ) =
( E ( t (cid:48) ) , s ( t (cid:48) ) )
⇒ ( y ( t ) =
y ( t (cid:48) ) ) for all t (cid:48) < t .
Predicting targets y ( t ) requires the model to maintain a persistent set of internal states to represent the history of operations for all entities throughout their lifetime.
A na ¨ ıve solution is copying all entities after operations, but this quickly becomes intractable due to O ( tn ) storage costs—a selective approach is more desirable.
In the following, we present our proposed model, termed Persistent
Message Passing (PMP) , that combines these desiderata in an efﬁcient way.
See ﬁg. 1 for an overview.
Overview At each step, t , our PMP model maintains a set of N ( t ) hidden states H ( t )
=
{ h ( t ) j ∈
R d } N ( t ) j =1 .
Initially, N (0) = n in one-to-one correspondence with the n entities, and h (0) j = 0 .
During operations, instead of overwriting hidden states, PMP ﬁrst selects a subset of states to persist, and then adds an updated version of these to H ( t ) —preserving information about previous states in H ( t +1) .
To predict outputs, PMP needs to track (i) updated connectivity and (ii) which hidden states are relevant at time-step s ( t ) .
To achieve this, PMP maintains two N ( t ) × N ( t ) adjacency matrices, Π ( t ) for connectivity and Λ ( t ) for relevance .
We initialise Π (0) =
Π from the task input, and replicate its structure when adding copies of persisted nodes.
By that, we focus on persistency in isolation—even though our framework can easily be extended to inferred Π ( t ) , e.g. as in Veliˇckovi´c et al.
Λ ( t ) is updated so that new nodes link to their old versions.
Note that this form needs O ( t ) steps to reach past nodes and we leave improvements to O (log t ) (e.g. Pugh (1989)) for future work.
PMP closely follows the encode-process-decode paradigm (Hamrick et al., 2018), with additional masking to select nodes to persist (as done in Yan et al.
Veliˇckovi´c et al.
Input encoding We encode the current hidden states with both time-stamps and the current operation, using encoder networks f relevance and f operation :
[Equation]
) where, time stamp ( i ) is the time-step
when h ( t − 1) i was added to the set of hidden states H ( t ) , and expand ( E ( t ) , s ( t ) ) maps the n operation features to the N ( t − 1) hidden states, c.f. section 3.
Message passing The derived representations, Z ( t ) =
( z ( t ) 1 , . . .
, z ( t ) N ( t ) ) and V ( t )
=
( v ( t ) 1 , . . .
, v ( t ) N ( t ) ) are fed into a processor network , P , using Π ( t − 1) , Λ ( t − 1) as relational information: (cid:99)
H
[Equation]
t
[Equation]
=
[Equation] [Equation]
yielding candidate next-step latent features
[Equation]
and relevance latent features
G
[Equation]
H ( t ) are candidates, as (cid:98) h ( t )
j will be retained only if state j is persisted.
Relevance mechanism In order to decide which candidate next-step latent features are used for computing the operation response, we compute a per-state relevance mask using the relevance latents and a masking network ψ relevance as µ ( t ) j = ψ relevance ( g ( t ) j ) ∈ { 0 , 1 } .
This mask is used to select relevant hidden states from (cid:99)
H ( t ) in downstream computation of response and persistency.
Persistency mechanism Many efﬁcient data structures only modify a small (e.g. O (log n ) ) subset of the entities at once (Cormen et al., 2009).
We explicitly incorporate this inductive bias into PMP:
In order to decide which of the candidate next-step latent features (cid:98) h ( t ) i are appended to the set of hidden states H ( t ) , we predict a per-state persistency mask (on relevant states only), φ ( t ) j = ψ persistency ( (cid:98) h ( t ) j · µ ( t ) j ) ∈ { 0 , 1 } .
Using this mask, we generate a set of next-step latent features by appending masked candidates to the previous set of hidden features as H ( t ) =
concat ( H ( t − 1) , { (cid:98) h ( t ) j } j : φ ( t ) j =1 ) .
Updating adjacency We subsequently generate next-step adjacency matrices.
For Π ( t ) , we append copies of masked rows { j : φ ( t ) i = 1 } to the end, and additionally update connections to others replaced nodes within those rows.
For Λ ( t ) , we simply let each updated node point to its persisted predecessor.
These updated hidden states and adjacency matrices are used in the next time-step.
Readout Before moving to the next time-step, we compute a response to the input operation from the (cid:99)
H ( t ) using a decoder network g on relevant nodes ( µ ( t ) j = 1 ), y ( t ) =
g (cid:16)(cid:76) j : µ ( t ) i =
1 z ( t ) j , (cid:76) j : µ ( t ) i
= (cid:98) h ( t ) j (cid:17) , where (cid:76) is a readout aggregator (we use maximisation).
PMP components
In our implementation, encoder, decoder, masking and query networks are all linear transformations.
Echoing the results of prior work on algorithmic modelling with GNNs (Veli ˇ ckovi ´ c et al., 2019), we recovered strongest performance when using message passing neural networks (Gilmer et al., 2017) for P in eq.
(2): nodes aggregate messages from neighbouring nodes and combine those via an aggregation mechanism (we use maximisation), see appendix A for details.
Optimisation Besides the operation response loss for y ( t ) , PMP optimises the cross-entropy of relevance and persistency masks µ ( t ) j , φ ( t ) j against the ground-truth.
It is also possible to provide additional supervision for e.g. predicting per-node responses from the (cid:99)
H ( t ) , as done in the experiments.
T ASK : R ANGE MINIMUM QUERY WITH PERSISTENT SEGMENT TREES
We focus on the highly versatile range minimum query (RMQ) task on an array A of K integers.
At each step t , we perform one of two operations: (a) setting an individual array element to a new value,
A ( t +1)
k ← x , or (b) querying for the minimum value over a particular contiguous range, at a previous point in time, min a ≤ k ≤ b A ( t (cid:48) )
k , for t (cid:48) ≤ t .
RMQ-style tasks are effectively solved with segment trees (Bentley, 1977).
Segment trees are almostcomplete, full binary trees consisting of n = 2 K − 1 nodes, such that leaf nodes correspond to array elements, and any intermediate node maintains the minimum of its two children.
Updating a leaf nodes’ value only requires updating the O (log n ) nodes along the path to the root.
Querying requires minimising over the canonical covering of the query range, which contains O (log n ) nodes.
Segment
[Figure]
trees can be made persistent (PST) to for querying of past states: upon update, we copy instead of modifying nodes, resulting in additional O (log n ) storage per
We choose to use PMPs to imitate computations of persistent segment trees in our experiments, not only because of their high importance across computational geometry and combinatorial heuristics, but also because their “backbone” tree connectivity remains identical across steps.
This allows us to focus on the utility of PMP’s persistency mechanism (with hard-coded connectivity updates).
To model segment trees with PMP, we let our n entities correspond to the PST nodes.
Speciﬁcally,
PMP is provided with operation representations for (i) updating a leaf node (indicator feature) to a new integer value (global feature), or (ii) querying the minimum value in a given range (indicator feature), at a past state.
Our PMP model is supervised in a teacher-forced setup: it is guided to either: (a) select appropriate nodes to persist, and make their latents predictive of updated minimum values, in case of updates; or (b) select the relevant canonical cover of the relevant snapshot of the PST, and produce the appropriate answers over them, in the case of queries.
We represent all integers in binary form (c.f. Yan et al.
and consider a query answer correct if all bits are correctly predicted.
Dataset & training We generate a dataset consisting of 10,000 PST rollouts over arrays of size
K = 5 , resulting in N (0) =
n = 9 initial nodes.
For each rollout, we perform 5 updates with random position and new value, resulting in N (5) ≈ 26 nodes on average, followed by 5 random queries.
We compute features representations of queries (indicators) and updates (indicators & binary encodings) dynamically during rollouts, including their mapping onto the model’s growing collection of hidden states via expand in eq.
For in-distribution evaluation, we generate another 200 rollouts from the same distribution.
For out-of-distribution evaluation, we in addition use arrays of size K = 10 , and 10 updates, resulting in n = 19 and N (10) ≈ 63 nodes.
Further details can be found in appendix A.
Results In ﬁg. 2, we provide the test query accuracy (fraction of all bits correctly predicted) of our
PMP model for answering RMQ, in-distribution and over a dataset of more than twice as many nodes and operations, i.e., out-of-distribution.
At test time, teacher forcing is disabled, and a model must be properly rolled out over the entire lifetime of the data structure, including both persistency and relevance mechanisms.
We ﬁnd that PMP is close to perfect in predicting masks for both mechanisms (results not shown)—this is crucial as persisting wrong nodes, or selecting wrong relevant nodes would severely corrupt the model’s memory.
We compare PMP against message passing networks (MPNNs)
(Gilmer et al., 2017) which overwrite rather than persist (either entirely, or selectively by using a node-level mask), and an oracle MPNN, which predicts from the given correct snapshot of the segment tree and hence doesn’t need to memorise any evolution of the nodes.
Our test results are highly indicative of the strong performance of PMP: not only are they consistently more accurate at answering temporal range queries than their overwriting counterparts, but, given enough training time, they are capable of matching the oracle GNN even over long rollouts.
This demonstrates the robustness of the proposed neural persistency mechanism, and for temporal querying, they appear to effectively relieve the pressure on a GNN’s internal representations.
Interesting directions for future work are improving scalability of the number of updates, dealing with dynamic connectivity structure, an unsupervised earning of relevance and persistency masks.
Appendices A T RAINING DETAILS
We generate a dataset consisting of 10,000 PST rollouts over arrays of size K = 5 .
The array values are randomly initialized between [1 , 15] (represented using a 4 bit binary encoding), by ﬁrst sampling lower bound from the initial interval, and then sampling array elements uniformly between that and the chosen upper bound.
We choose this distribution in order to ensure non-trivial query responses for minimum queries.
We perform 5 PST updates where we uniformly sample update index k and new value x from the same distribution as the existing values.
This leads to 12 , 16 , 19 , 23 , 26 nodes on average, respectively after each update.
After the updates, we perform 5 PST queries, with uniformly sampled query bounds [ a, b ] and a random past time-step t (cid:48) <
t .
We use a shared representation for both queries and updates, setting query features to 0 when computing updates and vice versa.
In the update features, we add an indicator for the node corresponding to the updated PST leaf node, indicators for all leaf nodes, and a global binary encoding of new array value x .
For query features, we add an indicator for the leaf nodes which correspond to the query interval bounds [ a, b ] , and indicators whether nodes are left or right children or root nodes.
Using a 4-bit binary encoding of array values, this leads to a 10 -dimensional representation of operations.
It is straight-forward to dynamically compute these features (of n entities) for the growing set of N ( t ) hidden states via expand in eq.
(1): tagging leaf nodes, node type (left/right/root), etc can be inferred from the maintained connectivity of added hidden states within the PMP model.
For in-distribution evaluation, we generate another 200 rollouts from the same distribution.
For out-of-distribution evaluation, we in addition use arrays of size 10, and 10 updates resulting in n =and on average 23 , 28 , 32 , 37 , 41 , 45 , 50 , 54 , 58 , 63 nodes respectively after each update.
This is followed by 5 queries.
We train PMP for 2 · 10 4 iterations using a batch size of 16 (rollouts) using Adam (Kingma & Ba, 2014) with a learning rate of 10 − 3 , re-running the model with 5 different seeds.
Hidden states have d = 64 dimensions.
We use 10 message passing steps in the processor network, which we found to lead to slightly better performance of PMP compared to fewer steps.
We hypothesise this is due to the linked list approach in implemented in the relevance connectivity matrix Λ ( t ) —using a data structure that allows search in logarithmic time (such as skip lists, (Pugh, 1989)) are likely to allow lower the number of message passing steps.
Message passing network PMP builds on message passing neural networks (Gilmer et al., 2017), used as processor network P in eq.
The explicit computation of candidate next-step latent features (cid:98) h ( t ) j and relevance latent features g ( t ) j is:
[Equation]
where M and U are linear layers producing vector messages , followed by ReLU.