L OSSLESS C OMPRESSION OF S TRUCTURED C ONVOLUTIONAL M ODELS VIA L IFTING
Anonymous authors
Paper under double-blind review
A BSTRACT
Lifting is an efﬁcient technique to scale up graphical models generalized to relational domains by exploiting the underlying symmetries.
Concurrently, neural models are continuously expanding from grid-like tensor data into structured representations, such as various attributed graphs and relational databases.
To address the irregular structure of the data, the models typically extrapolate on the idea of convolution, effectively introducing parameter sharing in their, dynamically unfolded, computation graphs.
The computation graphs themselves then reﬂect the symmetries of the underlying data, similarly to the lifted graphical models.
Inspired by lifting, we introduce a simple and efﬁcient technique to detect the symmetries and compress the neural models without loss of any information.
We demonstrate through experiments that such compression can lead to signiﬁcant speedups of structured convolutional models, such as various Graph Neural Networks, across various tasks, such as molecule classiﬁcation and knowledge-base completion.
I NTRODUCTION
Lifted, often referred to as templated , models use highly expressive representation languages, typically based in weighted predicate logic, to capture symmetries in relational learning problems (Koller et al., 2007).
This includes learning from data such as chemical, biological, social, or trafﬁc networks, and various knowledge graphs, relational databases and ontologies.
The idea has been studied extensively in probabilistic settings under the notion of lifted graphical models (Kimmig et al., 2015), with instances such as Markov Logic Networks (MLNs) (Richardson & Domingos, 2006) or Bayesian
Logic Programs (BLPs) (Kersting & De Raedt, 2001).
In a wider view, convolutions can be seen as instances of the templating idea in neural models, where the same parameterized pattern is being carried around to exploit the underlying symmetries, i.e. some forms of shared correlations in the data.
In this analogy, the popular Convolutional Neural
Networks (CNN) (Krizhevsky et al., 2012) themselves can be seen as a simple form of a templated model, where the template corresponds to the convolutional ﬁlters, unfolded over regular spatial grids of pixels.
But the symmetries are further even more noticeable in structured, relational domains with discrete element types.
With convolutional templates for regular trees, the analogy covers Recursive
Neural Networks (Socher et al., 2013), popular in natural language processing.
Extending to arbitrary graphs, the same notion covers works such as Graph Convolutional Networks (Kipf & Welling, 2016) and their variants (Wu et al., 2019), as well as various Knowledge-Base
Embedding methods (Wang et al., 2017).
Extending even further to relational structures, there are works integrating parameterized relational logic templates with neural networks (Sourek et al., 2018; Rocktäschel & Riedel, 2017;
Marra & Kuželka, 2019; Manhaeve et al., 2018).
The common underlying principle of templated models is a joint parameterization of the symmetries, allowing for better generalization.
However, standard lifted models, such as MLNs, provide another key advantage that, under certain conditions, the model computations can be efﬁciently carried out without complete template unfolding, often leading to even exponential speedups (Kimmig et al., 2015).
This is known as “lifted inference” (Kersting, 2012) and is utilized heavily in lifted graphical models as well as database query engines (Suciu et al., 2011).
However, to our best knowledge, this idea has been so far unexploited in the neural (convolutional) models.
The main contribution of this paper is thus a “lifting” technique to compress symmetries in convolutional models applied to structured data, which we refer to generically as “structured convolutional models”.
1. R ELATED W ORK
The idea for the compression is inspired by lifted inference (Kersting, 2012) used in templated graphical models.
The core principle is that all equivalent sub-computations can be effectively carried out in a single instance and broadcasted into successive operations together with their respective multiplicities, potentially leading to signiﬁcant speedups.
While the corresponding “liftable” template formulae (or database queries) generating the isomorphisms are typically assumed to be given (Kimmig et al., 2015), we explore the symmetries from the unfolded ground structures, similarly to the approximate methods based on graph bisimulation (Sen et al., 2012).
All the lifting techniques are then based in some form of ﬁrst-order variable elimination (summation), and are inherently designed to explore structural symmetries in graphical models.
In contrast, we aim to additionally explore functional symmetries, motivated by the fact that even structurally different neural computation graphs may effectively perform identical function.
The learning in neural networks is also principally different from the model counting-based computations in lifted graphical models in that it requires many consecutive evaluations of the models as part of the encompassing iterative training routine.
Consequently, even though we assume to unfold a complete computation graph before it is compressed with the proposed technique, the resulting speedup due to the subsequent training is still substantial.
From the deep learning perspective, there have been various model compression techniques proposed to speedup the training, such as pruning, decreasing precision, and low-rank factorization (Cheng et al., 2017).
However, to our best knowledge, the existing techniques are lossy in nature, with a recent exception of compressing ReLU networks based on identifying neurons with linear behavior (Serra et al., 2020). None of these works exploit the model computation symmetries.
The most relevant line of work here are Lifted Relational Neural
Networks (LRNNs) (Sourek et al., 2018) which however, despite the name, provide only templating capabilities without lifted inference, i.e. with complete, uncompressed ground computation graphs.
B ACKGROUND
The compression technique described in this paper is applicable to a number of structured convolutional models, ranging from simple recursive (Socher et al., 2013) to fully relational neural models (Sourek et al., 2018).
The common characteristic of the targeted learners is the utilization of convolution (templating), where the same parameterized pattern is carried over different subparts of the data (representation) with the same local structure, effectively introducing repetitive sub-computations in the resulting computation graphs, which we exploit in this work.
2. G RAPH N EURAL N ETWORKS
Graph neural networks (GNNs) are currently the most prominent representatives of structured convolutional models, which is why we choose them for brevity of demonstration of the proposed compression technique.
GNNs can be seen as an extension of the common CNN principles to completely irregular graph structures.
Given a particularly structured input sample graph S j , they dynamically unfold a multi-layered computation graph G j , where the structure of each layer i follows the structure of the whole input graph S j .
For computation of the next layer i + 1 values, each node v from the input graph S j calculates its own value h ( v ) by aggregating A (“pooling”)
the values of the adjacent nodes u : edge ( u, v ) , transformed by some parametric function C W 1 (“convolution”), which is being reused with the same parameterization W 1 within each layer i as:
[Equation]
The ˜ h ( i ) ( v ) can be further combined through another C W 2 with the central node’s representation from the previous layer to obtain the ﬁnal updated value h ( i ) ( v ) for layer i as:
[Equation]
This general principle covers a wide variety of GNN models, such the popular GCNs (Kipf & Welling, 2016), graph-SAGE (Hamilton et al., 2017),
GIN (Xu et al., 2018a), and others (Xu et al., 2018b;
Gilmer et al., 2017), which then reduces to the respective choices of particular aggregations A and
f = f ( x ) =
x f ( x ) = x f ( x,y ) = x · cos ( y ) wwww
f = f ( x ) =
x f ( x,y ) = x · cos ( y ) www transformations C W .
An example computation graph of a generic GNN unfolded over an example molecule of methane is shown in Fig.
2. C OMPUTATION G RAPHS
For the sake of this paper, let us now deﬁne the common notion of a computation graph more formally.
A computation graph is a tuple G =
( N , E , F ) ,
where N = (1 , 2 , . . . , n ) is a list of nodes and
E ⊆ N 2 × N is a list of directed labeled edges .
Each labeled edge is a triple of integers ( n 1 , n 2 , l ) where n 1 and n 2 are nodes of the computation graph and l is the label .
The labels are used to assign weights to the edges in the computation graph.
Note this allows to deﬁne the weight sharing scheme as part of the graph (cf Example 1 below).
Finally, F = { f 1 , f 2 , . . . , f n } is the list of activation functions , one for each node from N .
As usual, the graph is assumed to be acyclic.
Children of a node N are naturally deﬁned as all those nodes M such that ( M, N, L ) ∈ E , and analogically for parents.
Note that since E is a list, edges contained in it are ordered, and the same edge may appear multiple times (which will be useful later).
Children of each node are also ordered – given two children C and C (cid:48) of a node N , C precedes C (cid:48)
iff ( C, N, L ) precedes ( C (cid:48) , N, L (cid:48) ) in the list of edges
E .
We denote the lists of children and parents of a given node N by Children ( N ) and Parents ( N ) , respectively.
Computation graphs are then evaluated bottom up from the leaves of the graph (nodes with no children) to the roots of the graph (nodes with no parents).
Given a list of weights W , we can now deﬁne the value of a node N ∈ N recursively as:
[Equation]
where ( M 1 , . . .
, M m ) ≡ Children ( N ) is the (ordered) list of children of the node N , and L 1 , . . .
, L m are the labels of the respective edges ( M 1 , N, L 1 ) , . . .
, ( M m , N, L m ) ∈ E , and W L i is the L i -th component of the list W .
Note that with the structured convolutional models, such as GNNs, we assume dynamic computation graphs where each learning sample S j generates a separate G j .
Consequently, we can associate the leaf nodes in each G j with constant functions 1 , outputting the corresponding node (feature) values from the corresponding structured input sample S j .
P ROBLEM D EFINITION
The problem of detecting the symmetries in computation graphs can then be formalized as follows.
Deﬁnition 1 (Problem Deﬁnition) .
Let G =
( N , E , F ) be a computation graph.
We say that two nodes N 1 , N 2 are equivalent if, for any W , it holds that value ( N 1 ; W )
= value ( N 2 ; W ) .
The problem of detecting symmetries in computation graphs asks to partition the nodes of the computation graph into equivalence classes of mutually equivalent nodes.
Example 1.
Consider the computation graph G =
( N , E , F ) , depicted in Fig.
1, where
[Equation] [Equation] [Equation]
[-F = { f 
-][Equation] [Equation] [Equation] [Equation]
[Equation]
[Equation] 3 ( x ) = x, f 4 ( x, y ) = x · cos ( y ) } .
Let W = ( w 1 , w 2 ) be the weight list.
The computation graph then computes the function ( w 1 w 2 ) · cos ( w 1 w 2 ) .
It is not difﬁcult to verify that the nodes 2 and 3 are functionally equivalent.
This also means, as we discuss in more detail in the next section, that we can “replace” 2 with 3 without changing the function that the graph computes.
The resulting reduced graph then has the form
N = { 1 , 3 , 4 } , E = { (1 , 3 , 1) , (3 , 4 , 2) , (3 , 4 , 2) } ,
F = { f
=
1 , f 3 ( x )
= x, f 4 ( x, y )
= x · cos ( y ) } .
In the example above, the nodes 2 and 3 are in fact also isomorphic in the sense that there exists an automorphism (preserving weights and activation functions) of the computation graph that swaps the two nodes.
Note that our deﬁnition is less strict: all we want the nodes to satisfy is functional equivalence, meaning that they should evaluate to the same values for any initialization of W .
We will also use the notion of structural-equivalence of nodes in computational graphs.
Two nodes are structurally equivalent if they have the same outputs for any assignment of weights W and for any replacement of any of the activation functions in the graph.
That is if two nodes are structurally equivalent then they are also functionally equivalent but not vice versa.
Importantly, the two nodes do not need to be automorphic 3 in the graph-theoretical sense while being structurally equivalent, which also makes detecting structural equivalence easier from the computational point of view.
In particular, we describe a simple polynomial-time algorithm in Section 4.2.
T WO A LGORITHMS FOR C OMPRESSING COMPUTATION G RAPHS
In this section we describe two algorithms for compression of computation graphs: a non-exact algorithm for compression based on functional equivalency (cf.
Deﬁnition 1) and an exact algorithm for compression based on detection of structurally-equivalent nodes in the computation graph.
While the exact algorithm will guarantee that the original and the compressed computation graphs represent the same function, that will not be the case for the non-exact algorithm.
Below we ﬁrst describe the non-exact algorithm and then use it as a basis for the exact algorithm.
4. A N ON -E XACT C OMPRESSION A LGORITHM
The main idea behind the non-exact algorithm is almost embarrassingly simple.
The algorithm ﬁrst evaluates the computation graph with n randomly sampled parameter lists W 1 , . . .
, W n , i.e. with n random initializations of the (shared) weights, and records the values of all the nodes of the computation graph (i.e. n values per node).
It then traverses the computation graph from the output nodes in a breadth-ﬁrst manner, and whenever it processes a node N , for which there exists a node N (cid:48) that has not been processed yet and all n of its recorded values are the same as those of the currently processed node N , the algorithm replaces N by N (cid:48) in the computation graph.
In principle, using larger n will decrease the probability of merging nodes that are not functionally equivalent as long as there is a non-zero chance that any two non-equivalent nodes will have different values (this is the same as the “ampliﬁcation trick” normally used in the design of randomized algorithms).
It is easy to see that any functionally equivalent nodes will be mapped by the above described algorithm to the same node in the compressed computation graph.
However, it can happen that the algorithm will also merge nodes that are not functionally equivalent but just happened (by chance) to output the same values on all the random parameter initializations that the algorithm used.
We acknowledge that this can happen in practice, nevertheless it was not commonly encountered in our experiments (Sec. 5), unless explicitly emulated.
To do that, we decreased the number of signiﬁcant digits used in each equivalence check between value ( N ; W i ) and value ( N (cid:48) ; W i ) .
This allows to compress the graphs even further, at the cost of sacriﬁcing ﬁdelity w.r.t.
the original model.
There are also cases when we can give (probabilistic) guarantees on the correctness of this algorithm.
One such case is when the activation functions in the computation graph are all polynomial.
In this case, we can use DeMillo-Lipton-Schwartz-Zippel Lemma (DeMillo & Lipton, 1977) to bound the probability of merging two nodes that are not functionally equivalent.
However, since the activation functions in the computation graphs that we are interested in are usually not polynomial, we omit the
I h(c 1 )
I h(h 1 )
I h(h 2 )
I h(h 3 )
I h(h 4 )
C (1)h(c 1 ) C (1)h(h 1 )
C (1)h(h 2 )
C (1)h(h 3 )
C (1)h(h 4 )
C
C 21 C
C
C C
C C
A A
A A
A
W
W W W
W W
W W
W W
W W
W
C ( n ) h(c 1 ) C ( n ) h(h 1 )
C ( n ) h(h 2 )
C ( n ) h(h 3 )
C ( n ) h(h 4 ) ...
A y
C y W ( n )
C 1 H
H H
Hy
[Figure]
[Figure]
h ( h
[Figure]
) C
[Figure]
C
[Figure]
C 41 C
C 14 C 13 C 12 C A A2A3A4A W4 × W4 × W4 × W
C ( n ) h ( c 1 )
C ( n ) h ( n 2 ) C ( n ) h ( n 3 ) C ( n ) h ( n 4 ) C ( n ) h ( h 4 ) . . .
A y
C y W ( n )
C 1 H 2 H 3 H 1 Hy details here.
In particular, obtaining similar probabilistic guarantees with activation functions such as
ReLU does not seem doable. 4. A N E XACT C OMPRESSION A LGORITHM The exact algorithm for compressing computation graphs reuses the evaluation with random parameter initializations while recording the respective values for all the nodes. However, the next steps are different.
First, instead of traversing the computation graph from the output nodes towards the leaves, it traverses the graph bottom-up, starting from the leaves. Second, rather than merging the nodes with the same recorded value lists right away, the exact algorithm merely considers these as candidates for merging. For that it keeps a data structure (based on a hash table) that indexes the nodes of the computation graph by the lists of the respective values recorded for the random parameter initializations. When, while traversing the graph, it processes a node N , it checks if there is any node N (cid:48) that had the same values over all the random parameter initializations and has already been processed.
If so it checks if N and N (cid:48) are structurally equivalent (which we explain in turn) and if they are it replaces N by N (cid:48) .
To test the structural equivalence of two nodes, the algorithm checks the following conditions: The activation functions of N and N (cid:48) are the same.
The lists of children of both N and N (cid:48) are the same (not just structurally equivalent but identical, i.e. Children ( N ) =
Children ( N (cid:48) ) ), and if C is the i -th child of N and C (cid:48) is the i -th child of N (cid:48) , with ( C, N, L 1 ) and ( C (cid:48) , N, L 2 ) being the respective edges connecting them to N , then the labels L 1 and L 2 must be equal, too.
One can show why the above procedure works by induction.
We sketch the main idea here.
The base case is trivial.
To show the inductive step we can reason as follows.
When we are processing the node
N , by the assumption, the node N (cid:48) has already been processed.
Thus, we know that the children of both N and N (cid:48) must have already been processed as well.
By the induction hypothesis, if any of the children were structurally equivalent, they must have been merged by the algorithm, and so it is enough to check identity of the child nodes.
This reasoning then allows one to easily ﬁnish a proof of correctness of this algorithm.
There is one additional optimization that we can do for symmetric activation functions.
Here by “symmetric” we mean symmetric with respect to permutation of the arguments.
An example of such a symmetric activation function is any function of the form f ( x 1 , . . .
, x k )
=
h (cid:16)(cid:80) ki
=1 x k (cid:17) ; such functions are often used in neural networks.
In this case we replace the condition 2 above by:
There is a permutation π such that π ( Children ( N )) =
Children ( N (cid:48) ) ), and if C is the i -th child of N and C (cid:48) is the π ( i ) -th child of N (cid:48) , with ( C, N, L 1 ) and ( C (cid:48) , N, L 2 ) being the respective edges connecting them to N , then the labels L 1 and L 2 must be equal.
It is not difﬁcult to implement the above check efﬁciently (we omit the details for brevity).
Note also that the overall asymptotic complexity of compressing a graph G with either of the algorithms is simply linear in the size of the graph. Speciﬁcally, it is the same as the n evaluations of G .
Finally, to illustrate the effect of the lossless compression, we show the GNN model (Sec. 2.1), unfolded over a sample molecule of methane from Fig.2, compressed in Fig.
E XPERIMENTS
To test the proposed compression in practice, we selected some common structured convolutional models, and evaluated them on a number of real datasets from the domains of (i) molecule classiﬁcation and (ii) knowledge-base completion.
The questions to be answered by the experiments are:
How numerically efﬁcient is the non-exact algorithm in achieving lossless compression?
What improvements does the compression provide in terms of graph size and speedup?
Is learning accuracy truly unaffected by the, presumably lossless, compression in practice?
Models We chose mostly GNN-based models as their dynamic computation graphs encompass all the elements of structured convolutional models (convolution, pooling, and recursive layer stacking).
Particularly, we choose well-known instances of GCNs and graph-SAGE (Sec. 2.1), each with 2 layers.
Additionally, we include Graph Isomorphism Networks (GIN) (Xu et al., 2018a), which follow the same computation scheme with 5 layers, but their particular operations ( C W 1 = identity , A = sum , C W 2 = MLP ) are theoretically substantiated in the expressiveness of the Weisfeiler-Lehman test (Weisfeiler, 2006).
This is interesting in that it should effectively distinguish non-isomorphic substructures in the data by generating consistently distinct computations, and should thus be somewhat more resistant to our proposed compression.
Finally, we include a relational template (“graphlets”) introduced in (Sourek et al., 2018), which generalizes GNNs to aggregate small 3-graphlets instead of just neighbors.
Datasets For structure property prediction, we used 78 organic molecule classiﬁcation datasets reported in previous works (Ralaivola et al., 2005; Helma et al., 2001; Lodhi & Muggleton, 2005).
Nevertheless, we show only the (alphabetically) ﬁrst 3 for clarity, as the target metrics were extremely similar over the whole set.
We note we also extended GCNs with edge embeddings to account for the various bond types, further decreasing the symmetries.
For knowledge base completion (KBC), we selected commonly known datasets of Kinships, Nations, and UMLS (Kok & Domingos, 2007) composed of different object-predicate-subject triplets.
We utilized GCNs to learn embeddings of all the items and relations, similarly to R-GCNs (Schlichtkrull et al., 2018), and for prediction of each triplet, we fed the three embeddings into an MLP, such as in (Dong et al., 2014), denoted as “KBE”.
The size of the individual input graphs is generally smallest in the molecular data with app. 25 atoms and 50 bonds per a single molecule, where there are app. 3000 molecules in each of the datasets [Figure]
r a t
i o ( un itl
[Figure]
ss )
[Figure]
Additionally, the startup graphs creation time of LRNNs (including the compression) is reported.
Model
[Table]
on average.
The input graphs are then naturally largest for the knowledge bases with app.
20, triples over hundreds of objects and relations.
The sizes of the corresponding computation graphs themselves are then in the orders of 10 2 – 10 5 nodes, respectively.
Experimental Protocol We approached all the learning scenarios under simple uniﬁed setting with standard hyperparameters, none of which was set to help the compression (sometimes on the contrary).
We used the (re-implemented) LRNN framework to encode all the models, and also compared with popular GNN frameworks of PyTorch Geometric (PyG) (Fey & Lenssen, 2019) and Deep Graph
Library (DGL) (Wang et al., 2019).
If not dictated by the particular model, we set the activation functions simply as C W = 1 1+ e − W · x and A = avg .
We then trained against MSE using 1000 steps of ADAM, and evaluated with a 5 -fold crossvalidation.
5. R ESULTS
Firstly, we tested numerical efﬁciency of the non-exact algorithm itself (Sec. 4), for which we used scalar weight representation in the models to detect symmetries on the level of individual “neurons” (rather than “layers”).
We used the (most expressive) graphlets model, where we checked the functional symmetries to overlap with the structural symmetries.
The results in Fig.
4 then show that the non-exact algorithm is already able to perfectly distinguish all structural symmetries with but a single weight initialization within less than 12 signiﬁcant digits.
While more initializations indeed improved the efﬁciency rapidly, in the end they proved unnecessary (but could be used in cases where the available precision would be insufﬁcient).
Moreover this test was performed with the actual low-range logistic activations.
The displayed ( 10 x) training time improvement (Fig.4 - left) in
[Figure]
[Figure]
the scalar models was then directly reﬂecting the network size reduction, and could be pushed further by decreasing the numeric precision at the expected cost of degrading the learning performance.
Secondly, we performed similar experiments with standard tensor parameterization, where the equivalences were effectively detected on the level of whole neural “layers”, since the vector output values (of dim=3) were compared for equality instead.
This further improved the precision of the non-exact algorithm (Fig.
4 - right)
, where merely the ﬁrst 4 digits were sufﬁcient to achieve lossless compression in all the models and datasets (Figure 5).
However, the training (inference) time was no longer directly reﬂecting the network size reduction, which we account to optimizations used in the vectorized computations.
Nevertheless the speedup (app.
3 x) was still substantial.
We further compared with established GNN frameworks of PyG (Fey & Lenssen, 2019) and
DGL (Wang et al., 2019).
We made sure to align the exact computations of GCN, graph-SAGE, and
GIN, while all the frameworks performed equally w.r.t.
the accuracies.
For a more fair comparison, we further increased all (tensor) dimensions to a more common dim=10.
The compression effects, as well as performance edge of the implemented LRNN framework itself, are displayed in Tab. for a sample molecular dataset (MDA).
Note that the compression was truly least effective for the aforementioned GIN model, nevertheless still provided app.
2 x speedup.
Finally, the results in Fig.
6 conﬁrm that the proposed lossless compression via lifting, with either the exact algorithm or the non-exact algorithm with a high-enough numeric precision used, indeed does not degrade the learning performance in terms of training and testing accuracy (both were close within margin of variance over the crossvalidation folds).
Note that the used templated models are quite simple and do not generate any symmetries on their own (which they would, e.g., with recursion), but rather merely reﬂect the symmetries in the data themselves.
Consequently, the speedup was overall lowest for the sparse knowledge graph of Nations, further decomposed by the 2 distinct relation types, and higher for the Kinships dataset, representing a more densely interconnected social network.
The improvement was then generally biggest for the highly symmetric molecular graphs where, interestingly, the compression often reduced the neural computation graphs to a size even smaller than that of the actual input molecules.
Note we only compressed symmetries within individual computation graphs (samples), and the results thus cannot be biased by the potential existence of isomorphic samples (Ivanov et al., 2019), however, potentially much higher compression rates could be also achieved with (dynamic) batching.
C ONCLUSION
We introduced a simple, efﬁcient, lossless compression technique for structured convolutional models inspired by lifted inference.
The technique is very light-weight and can be easily adopted by any neural learner, but is most effective for structured convolutional models utilizing weight sharing schemes to target relational data, such as in various graph neural networks.
We have demonstrated with existing models and datasets that a signiﬁcant inference and training time reduction can be achieved without affecting the learning results, and possibly extended beyond for additional speedup.