Computer Science
Computer Science-2021.gz:143394
Computer Science
dcdd4e71209c896921e4e5e7a24a5116507a3647
Accelerating Deep Learning Inference via Learned Caches

Deep Neural Networks (DNNs) are witnessing increased adoption in multiple domains owing to their high accuracy in solving real-world problems. However, this high accuracy has been achieved by building deeper networks, posing a fundamental challenge to the low latency inference desired by user-facing applications. Current low latency solutions trade-off on accuracy or fail to exploit the inherent temporal locality in prediction serving workloads. We observe that caching hidden layer outputs of the DNN can introduce a form of late-binding where inference requests only consume the amount of computation needed. This enables a mechanism for achieving low latencies, coupled with an ability to exploit temporal locality. However, traditional caching approaches incur high memory overheads and lookup latencies, leading us to design learned caches - caches that consist of simple ML models that are continuously updated. We present the design of GATI, an end-to-end prediction serving system that incorporates learned caches for low-latency DNN inference. Results show that GATI can reduce inference latency by up to 7.69X on realistic workloads.


Introduction
Machine learning models based on deep neural networks (DNNs) have surpassed human-level accuracy on tasks ranging from speech recognition [74], image classification [33,68] to machine translation [31]. As a result, several enterprises are now deploying DNNs as a part of their applications, many of which are user-facing and hence latency-sensitive [23,43,79]. This gain in accuracy has largely come from models becoming more complex, typically deeper or having more layers. As each layer of DNN inference depends on the output from the previous layer, such deep models exacerbate inference latency, hurting the performance of applications that rely on them. For instance, the top-5 classification accuracy for ImageNet [9] increased from 71% in 2012 to 97% in 2015 but the models became 20× more computationally expensive, and inference latency has correspondingly worsened~15×. * Equal Contribution. Work done while at UW-Madison. A number of recent efforts have been aimed at reducing inference latency, such as: (a) quantization-based approaches that perform computation at lower precision [22,81], (b) model pruning-based approaches that prune dependencies across layers [17], and (c) distillation based techniques that teach a smaller model to behave like a larger model [34] ( §2.1.1). These approaches face two key issues. (1) All the above approaches trade-off some fixed amount of accuracy for latency improvements as shown in Figure 2b. In other words, they bind to a specific point in the latency-accuracy trade-off space for all prediction inputs. However, as prior work has shown [42,64], cheaper DNNs (e.g., Resnet-18) suffice for easier inputs while deeper models (e.g.,  are only necessary to handle more difficult examples. This suggests that postponing the binding to during inference can, in theory, lead to lower latencies for easier inputs without significantly impacting accuracy. (2) Prediction serving systems typically serve user facing applications which are often temporally dominated by a small number of classes [35,64]. Thus requests have a notion of temporal locality. Existing approaches like distillation can leverage this temporal locality by retraining or fine-tuning the model. However, this only improves the accuracy, not the latency of future requests, and retraining could also be expensive for deep models [76].
Traditionally, caches are used in web-services to improve latency for workloads with temporal locality. This paper explores using caches to both provide lower latencies for easier inputs and exploit temporal locality. To apply such a cachingbased approach to inference, we propose that during inference, if the result of any intermediate computation matches what we have seen earlier, we can skip the computations of the remain-ing layers of the DNN (Figure 1). Caches at deeper layers in a model capture information about progressively harder-toclassify inputs. Our approach to caching thus paves the way for late-binding the work performed for inference based on the input's hardness, allowing for lowering of prediction latency, depending upon the layer at which we observe a cache hit, without impacting accuracy. Intermediate (or hidden) layer caches can be initially populated using user-provided validation data and updated to hold the intermediate outputs for recent inputs, thereby exploiting temporal locality.
However, using a direct approach of storing hidden layer outputs as a cache leads to many challenges: hidden layer outputs in DNNs are high dimensional (e.g., 262144 floats for block 3 1 of ResNet-50) needing significant memory for storage and high latency at lookup ( §2.2). To address these challenges, we propose using simple machine learning models to represent the cache at each layer. Given the hidden layer output, such a learned cache model at a layer predicts if we have a cache-hit, and if so the final result to use. This provides improved latency during cache-hits; cache misses continue inference on the base model leading to no loss in accuracy.
Using ML models for the learned cache means that we need a methodology to both determine the predicted output of the base model and if this can be considered as a cache hit. We address this problem using a novel approach where the learned cache for a given layer of the base DNN uses two trained networks, a predictor network that generates the predicted output and a selector network that decides if the prediction can be used as a cache hit.
We develop GATI, a system for DNN inference that automatically integrates learned caches into the inference workflow given a pre-trained base DNN model and a validation dataset. During an initial deployment phase, GATI automatically explores model architectures for predictor and selector networks, estimating their hit-rate and accuracy using the validation dataset. Using this, GATI determines the optimal set of layers that should include a learned cache and the architecture to use to minimize the overall average latency, taking into account memory and compute resources available.
At runtime, GATI performs two main functions: query planning when using a directed acyclic graph (DAG) of models to process a user query, and incremental retraining of learned caches to provide temporal locality. Using learned caches enables run-time refinement of query plans, or incremental replanning, in systems like Nexus [63] that execute a DAG of models. We describe how GATI can incrementally improve prediction accuracy given a latency SLO for a DAG of models, based on which models in the DAG obtained a cache hit.
Finally, temporal shifts in input data might lead to worse hit rate for learned caches. For example, if we train an object detection model where the validation data consists of video snippets of car traffic, our learned caches will give a higher hit 1 ResNet-50 consists of 16 blocks, where each block has 3 convolutional layers and a residual connection. rate for input frames with cars. However the class distribution might change over time. We handle that in GATI by designing an online retraining scheme that periodically and quickly retrains predictor and selector networks when their hit-rate is worse than the expected hit rate.
We evaluate GATI against both systems and algorithmic techniques for low latency inference using popular datasets [6,49] and video streams [4,7,11]. Results show that GATI can opportunistically get cache hits for easier inputs and improve average latency by up to 1.95× over the base model and 1.39× over existing low latency techniques on image datasets. On real-world videos that exhibit temporal locality, GATI gives up to 7.69× improvement in average latency. Additionally, when using a DAG of models (Figure 2a), we see that incremental replanning simultaneously improves the overall accuracy, with respect to ground truth, by~1% and prediction latency by 1.26×.

Background and Motivation
A Deep Neural Network (DNN) consists of a sequence of layers, each of which is a mathematical function on the output of the previous layer. We refer to the first layer of the DNN that accepts the input as the input layer and the final layer that represents the prediction as the output layer. We term the remaining intermediate layers of the DNN as hidden layers.

Prediction Serving and DNN Inference
A prediction serving system serves machine learning models used for inference [23,61,63]. It accepts queries from clients which may require performing inference on a single model or a sequence of models. For instance, consider a traffic analysis application (Figure 2a). The analysis would first require object detection followed by either face or vehicle recognition depending upon the object, in order to deliver the final output. We can therefore view the query as a DAG of ML models that need to be executed. Client requests are often associated with a latency SLO within which the entire query needs to be executed. Prediction serving systems are deployed on a fleet of servers consisting of CPUs and accelerators (GPUs, TPUs, custom ASICs [3,28,41]).
DNN inference in prediction serving systems must meet two requirements: (1) Low Latency. As trained models often support user-facing applications, low inference latency (~10-100ms) [79] is key. However, executing DNN inference is computationally intensive and imposes high latency today [42,63,79]. Though some hardwares (e.g., GPUs) offer higher throughput when executing requests in batches, many systems perform minimal or no batching to keep the promise of low latency [20,32,45,79]. (2) High Accuracy. With DNNs being increasingly deployed in critical applications such as fraud detection and personal assistants, predictions need to have high accuracy.

Current state of DNN Inference
Increasingly, deeper DNN models with many layers are being used to achieve high accuracy, but they severely impact latency. Viewing the dependencies among DNN computations performed during inference as a computation graph [13], inference latency depends on: (i) the per-node latencies in the graph, and (ii) the critical path length. Existing techniques to reduce inference latency can be categorized on how they manipulate the computation graph. All of these techniques come with an inherent trade-off in accuracy as shown in Figure 2b: Reducing cost of individual nodes. This is used in model quantization [22,38,81] based techniques which perform computations at lower precision rather than 32-bit floating point, thereby reducing the cost of individual computations. We see (Figure 2b) that quantization can result in~5-10% loss in accuracy, while giving 1.

Opportunities in DNN Inference
Next, we present opportunities to improve DNN inference: (O1) Opportunity from DNN model architecture. Existing solutions for lowering latencies pick a fixed point on the latency-accuracy trade-off space ( Figure 2b). Thus, they earlybind, as they require committing to a particular latency and accuracy value prior to DNN deployment. We observe that deeper DNNs are built to offer an incremental accuracy benefit over their shallower counterparts. For instance, ResNet-50 [33] has an accuracy of 94.2% on CIFAR-10 [49] while a shallower ResNet-18 has an accuracy of 93.3%. Intuitively, ResNet-18 seems to suffice for obtaining accurate predictions for 93.3% seemingly "easy" inputs, while the "extra" layers in ResNet-50 offer an accuracy benefit for an additional~1% "hard" inputs. This raises the questioncan we obtain lower latencies without trading-off accuracy by opportunistically deciding the number of layers to compute?
Achieving this necessitates late-binding the decision of the number of layers that need to be computed at inference time, thereby obtaining progressively lower latencies for easier inputs without trading off on accuracy (Figure 2b). In practice we find that late-binding can improve average latency bỹ 1.95× for real-world workloads ( §7.1).
Today, using an ensemble of models [23] or cascades of specialized models [42,64] are some techniques that enable a limited spectrum of progressive latencies. However, as shown in our experiments ( §7.1), these techniques either inflate tail latencies or require extra resources. (O2) Opportunity from workload. Since prediction serving systems typically serve user-facing web applications, requests have a skewed distribution dominated by few classes [27,51]. Video analytics represent another important workload class that uses prediction serving systems. Both workloads exhibit temporal locality, where certain classes may be popular for a given window of time [35,64]. Current solutions can adapt to temporal locality by retraining or fine-tuning the model [76]. However, this only improves accuracy and not latency and retraining can be expensive for deep models [76].
We note that temporal locality has been exploited in other domains [18,27,30,60,80] like web-caching to extract latency benefits. Given an ability to late-bind the amount of computation depending on whether an input is "easy" or "hard", we see an opportunity to similarly exploit temporal locality and opportunistically obtain lower latencies for the "easier" frequently occurring requests. (O3) Opportunity from system architecture. Prediction serving systems typically consist of a query scheduler responsible for orchestrating the execution of multiple DNN models constituting a query [63]. The scheduler's query planner determines how to apportion the available query latency SLO amongst different DNN models that constitute the query, and computes a query evaluation plan (QEP), i.e., which DNN model is to be executed at each stage of the query.
Current approaches offer fixed latencies and hence the query planner determines a fixed QEP prior to query execution [63]. Late-binding however provides an opportunity for incremental replanning -this can distribute the "saved" latency from early execution of an "easy" input to downstream model executions. This could help use more expensive/complex downstream DNNs, resulting in higher accuracy for the query while not violating the latency SLO ( §5.1).

A Proposal for Caching
To exploit the above opportunities, we propose adopting the use of caches to complement DNNs during inference. Inference involves performing a forward-pass on the DNN  tions of the remaining layers of the DNN and directly arrive at the final prediction. Inspired by the design of multi-level caches, we propose associating a cache with each hidden layer of the DNN. Figure 1 illustrates a simple mechanism to realize the caching of DNN computations. As a pre-processing step, we can cache the hidden layer outputs along with the final predictions from the validation dataset. During inference, if a hidden layer output matches what was cached earlier, we deem this as a cache hit and skip performing computations for the remaining layers and directly deliver the final prediction. Caching thus paves the way for late-binding inference computation. Challenges in caching DNN computations. While caching holds promise as also observed in prior work [50], high dimensionality of hidden layer outputs introduces a number of challenges in designing caches. Cache lookups for DNN computations require distance-based similarity search such as k-nearest neighbors (k-NN), k-means clustering or locality sensitive hashing (LSH) [71] to infer cache hits and obtain predictions ( Table 1). High dimensionality means that the memory overhead associated with such caches would be high (as in k-NN). This makes caching challenging on accelerators such as GPUs that have limited memory. Further, the fidelity of distance-based search degrades in high-dimension [15], which could result in errors in cache lookup as observed in Table 1. Techniques such as LSH which can deal with high dimensions cannot be used due to the high memory overheads associated with storing the hidden layer outputs. High dimensionality also exacerbates lookup latencies.

Towards Learned Caches
To address the challenges mentioned above, we propose adopting a learning-based approach for caching. Instead of complementing each layer of the DNN with a traditional cache consisting of data entries, our key idea is to use a simple machine learning model (Figure 3a). We train a model that mimics a cache lookup function and term this as a learned cache. The interface exposed by a learned cache remains the same; i.e., the learned cache takes in a hidden layer output and delivers a prediction in the event of a cache hit.
Using a learned cache alleviates the issues associated with high dimensionality. First, ML models are effective at handling high dimension inputs, thereby allaying concerns about the fidelity of cache lookups. Second, a learned cache does not actually store any data but is instead a succinct representation encapsulated by the weights of the model. The size of a learned cache depends on the model architecture and is independent of the number of items that constitute the cache. Thus,   a learned cache can be used to encapsulate a large number of data entries without additional memory overheads. Third, the latency of a learned cache lookup is dictated by the cost of executing an ML model. By choosing an appropriate model architecture, it is possible to keep lookup latencies below an acceptable limit. Additionally, simple ML models with a small number of parameters can be retrained quickly using recent data, thereby allowing learned caches to effectively exploit temporal locality.

Learned Cache Design
Given our goal of using ML models to represent caches, we observe that ML models are directly amenable to generating a prediction; e.g., for a classification problem we can train a model that predicts the final class given the hidden layer output so far. However, to avoid returning incorrect results we also need to determine if the prediction is correct or not. Thus, we observe that we can decompose the cache lookup operation into two sub-operations as shown in Figure 3b: (i) A prediction operation that computes an output prediction given a hidden layer output. (ii) A selection operation that determines whether the prediction is a cache hit or not.
We model the two sub-operations using two different neural networks: a predictor network and a selector network. We use neural networks as they are universal function approximators and provide a direct mechanism to approximate the base DNN model. Next, we describe the neural network architectures that can be used to build predictor and selector networks, and systems requirements that guide their design.

Predictor and Selector Networks
Using a neural network for predictors and selectors opens up a large design space. We start by discussing systems requirements that guide our design. Latency, Memory Usage. As the selector and predictor networks are run in sequence, the cache lookup latency is the sum of their execution times. The memory usage is similarly the total amount of memory required to store model parameters as well as the runtime memory used while doing inference on these networks. Thus, we target using a simple network with a  limited number of hidden layers for low-latency and memory. Hit-Rate, Accuracy. We define hit-rate to be fraction of lookups that yield a cache hit. Since learned caches are approximate, we also need to account for the accuracy of the prediction, which we define as the fraction of lookups that do not yield incorrect cached predictions. Learned caches need a high hit rate with accuracy above a certain threshold (say 97%) relative to base model. Note that false negatives (FN; Table 2), where the learned cached returned a miss but the prediction was correct, do not hurt accuracy as we fall back to the base DNN on a cache miss. Given these requirements we next present various design choices and how they meet the requirements above. Predictor Network Design. We restrict predictor networks to simple neural networks to satisfy latency, memory requirements, and consider three possibilities (Table 3): (a) a fully connected architecture (FC) that can learn non-linear combinations of inputs and project it onto the output dimension, (b) a convolution based architecture that limits non-linear combinations to local regions of the input and (c) a pooling-based architecture that reduces the spatial size of the inputs before projecting them onto the output dimension. We choose these three options as they represent different points in terms of FLOPs required (Table 3). Our system is extensible and can include other model architectures. Selector Network Design. While the predictor network attempts to mimic the base DNN, the selector network has a simpler role as it only needs to perform a binary classification of whether we have a cache hit or miss. We find that using a simple neural network with one hidden layer that projects the output of the predictor network onto an output layer that enables a binary decision to be made is sufficient and other architectures do not provide any significant benefits. Training Learned Caches. Consider a base DNN model with N hidden layers L 1 , .., L N and that we are given M input samples from a validation dataset, X 1 , .., X M , to construct learned caches. To train a predictor network, we first run a forward pass of the base DNN over the M input samples. During the forward pass for each input X j , we collect the hidden layer output at layer i as HO i, j and also record the final prediction of the base DNN as Y j , where Y j is a vector representing the distribution of class probabilities for classification (arg max j Y j is predicted class). The collection of data < HO i,1 ,Y 1 >, .., < HO i,M ,Y M > is then used to train a predictor network at layer i of the DNN. Given that the predictor network is trying to mimic the behavior of the rest of the base DNN, we borrow insights from distillation [34] and use a loss  Table 4: Trade-off space exposed by different model architectures for predictor networks at the end of the 3 rd and 6 th ResNet-18 block.
function that takes into account the true labels and also the distribution of class probabilities. A selector network at layer i is a function T = σ i (PR), where PR is the class distribution prediction from the predictor network and T is a binary decision. To train a selector network at layer i, we first construct ground truth labels (G) in the following manner: The collection of data < PR i,1 , G i,1 >, .., < PR i,M , G i,M > can be used to train a selector network at layer i. A key function of the selector network is to reduce the number of false positives (FP) so as to achieve high accuracy. To this end, we employ a custom cross-entropy loss function that levies a higher loss penalty for FPs in comparison for FNs, since FNs do not impact accuracy as discussed earlier.

Predictor Design Trade-offs
We now discuss the trade-offs involved in choosing the appropriate architecture for predictor networks by considering three learned cache variants for the 3 rd and 6 th blocks in ResNet-18 as illustrated in Table 4. We train all variants per the procedure described earlier ( §3.1). Hit-rate vs. System resources. From Table 4, we notice that architectures that are more computationally expensive take up more systems resources (have larger lookup latencies and memory cost), but offer greater hit rate and hence greater reduction in the average end-to-end inference latency (see FC(1024) vs. Pool(8192) for both block 3 and 6). Hardware dependent behavior. From Table 4, we notice that the nature of the trade-off depends on the target hardware due to differences in the underlying lookup latencies. For instance, we notice that FC(1024) has both a better hit rate and lookup latency on GPU compared to Pool(8192), while FC(1024) has higher lookup latency on CPU. This is because the fully-connected layer requires a large dense matrix multiplication and this operation can be effectively parallelized across many thread blocks available on a GPU. Role of base DNN layer. From Table 4, we also see that the dynamics of the trade-off space varies across layers of the base DNN. We see that all architectures have a higher hit rate at block 6 compared to block 3 indicating that caching is easier as we get closer to the output layer. Additionally, the lookup latencies and memory costs also reduce at block 6 since dimensionality of the hidden layer output reduces as we go deeper in the base DNN.
Collectively the three observations indicate that the appropriate choice of network architecture depends on the systems resources available, the hardware being used, and the base-DNN layer being considered. This motivates the need for a scheme that can reason about various learned cache variants at each layer of the DNN and collectively optimize the system for end-to-end latency benefits. We next present a general approach to address this challenge of composing learned caches for end-to-end benefits.

Composing Learned Caches
The trade-offs presented in the previous section indicate that a number of learned cache variants could be applicable for each layer of the DNN. To allow for systematic exploration, our system first runs an exploration phase, where for each variant corresponding to a base DNN layer, we compute the expected hit rate, accuracy, lookup latency, and memory cost.
Then, we use these as inputs to select a subset of these learned cache variants for inference. GATI accomplishes this in a composition phase by formulating it as an optimization problem ( Figure 4). The above two phases are one-time operations performed when inference service owners upload trained DNNs. Once the learned caches are deployed, GATI exploits temporal locality by fine-tuning or retraining the chosen cache variants in an online manner ( §5.4).
Consider the following toy example that illustrates the problem underlying the final choice of the optimal learned caches to use during inference. Suppose we have an aggregate memory budget of 564 MB available for learned caches. Table 4 shows that a potential choice can be to greedily select architectures at earlier layers that offer high hit-rates. This would mean selecting FC(1024) at block 3 which yields cache hits for 38.75% of requests. However, it uses up all of the available memory budget and hence the remaining 62.25% of requests would incur the latency of running the entire base DNN. The latency for the 38.75% cached requests would be the time to compute the first three blocks of ResNet plus the lookup latency (6.08 ms).
Another potential choice can be to select Pool(8192) at block 3 and FC(1024) at block 6. Combined, they have a memory cost of 264 MB, which is within the memory budget. We would get cache hits for 34.1% of requests at block 3. Interestingly, due to a lower lookup latency, the latency for these requests would be lesser than the latency of requests with cache hits at block 3 in the first option. Further, an additional 28.8% of requests would get cache hits at block 6, and the remaining 37.1% of requests would incur the latency of running the entire base DNN. The second option is preferable since it can significantly reduce the average latency of requests, even though a small additional fraction of requests achieve higher latency relative to the first option. Composing an optimal set of caches thus requires a global view of the trade-off space across layers of the DNN. Goal: The goal of the composition phase is to jointly select a global set of learned caches that minimize the expected average latency, while ensuring minimal degradation in accuracy and meeting compute and memory constraints.
We can formulate this problem as a mix-integer quadratic program but we find that the formulation is intractable while handling deep networks. We present the optimization problem in full detail in Appendix A.1. GATI uses a relaxation of the formulation whose key details we explain below.
Let us assume that we have a DNN with N layers and K cache variants at each layer. We index each variant by its layer i and variant number j. From the exploration phase, we obtain the following metrics for each variant -Hit Rate (H i, j ), Accuracy (A i, j ), Lookup Latency (T i, j ), and Memory Cost (M i, j ). Additionally, we profile the latency for the computation of each layer (L i ). Binary variable b i, j indicates if learned cache variant j at layer i is chosen. b i, j = 1 means that the variant is selected.
We use a three-step approach to simplify the composition problem formulation: Step 1. Accuracy Filter: We do not consider variants whose accuracy A i, j is below a minimum accuracy threshold A.
Step 2. Score Computation: Motivated by the example from before, we consider two factors in determining the importance of a particular variant: (i) the hit rate of the variant and (ii) the latency gain obtained by using the model variant in the event of a cache hit. We compute latency gain (LG) for a learned cache variant as the ratio of running time for the entire DNN to the running time assuming that a cache hit is obtained at the given learned cache variant.
We prefer higher hit rates and higher latency gains. However, these are fundamentally at odds with each other since higher latency gains are obtained using variants at earlier layers of the base DNN where the hit rates would be lower, and vice versa. To balance these two factors, we compute a score (S -higher is better) that captures the benefit of using a variant:  where α is a knob that lies in [0,1] and controls the relative importance of hit rate and latency gain.
Step 3. Resource Constraints: We constrain the total memory occupied by chosen variants to be within a memory budget M. For computation, to avoid latency inflation, we wish to run the learned caches asynchronously while the computation of the base DNN proceeds. To minimize the amount of resources required, we specify a computational constraint that we can atmost perform one cache lookup at a given point of time 2 . Finally, the objective of our formulation is to maximize the sum of scores for chosen variants: The computed values of b i, j then determine which learned cache variants should be used along with the base DNN during inference. We next describe how the above composition phase is integrated into the end-to-end query lifecycle and present the design of our system GATI.

GATI System Design
We design GATI, an end-to-end prediction serving system that leverages learned caches to speed up DNN inference serving ( Figure 5). Users interact with GATI by issuing a query along with a latency SLO (query completion deadline). Similar to [63], GATI determines the dataflow DAG of DNNs that need to be executed for a query. Like prior work [63], GATI considers simple DAGs with chains or fork-join dependencies, that have a single input and a single output prediction. In addition, GATI allows the inference service owner to specify an array of possible DNN models with different accuracies that can be used at each node of the dataflow DAG. Example: Consider the traffic analysis application as shown in Figure 2a which represents a DAG of models that need to be executed. As shown in Table 5, the inference service provider can specify an array of possible DNNs that can be used for each node of the DAG. These options can vary from cheap DNNs that have lower accuracy to more expensive DNNs that have higher accuracy. Example: Consider a query for the traffic analysis application ( Figure 2a) with a latency SLO of 80 ms. First, the planner needs to split the available latency SLO budget amongst the different nodes in the dataflow DAG. There can be multiple policies [43,63,67] to compute these partial budgets ( §5.2.1). Let us assume a simple policy that divides the latency budget equally among all nodes: this will allocate 40 ms for object detection and 40 ms for face/vehicle recognition. Next, the planner needs to choose a DNN with maximum accuracy that can be executed within the partial latency budget. For object detection, state-of-the-art static planners [63,75] would choose ResNet-18, and SE-LResNet18E-IR and ResNet-18 for face and vehicle recognition respectively. This constitutes the QEP for a latency SLO of 80 ms. Learned caches enable incremental replanning: Consider a scenario where learned caches are used and, because of cache hit, say object detection can execute in 20 ms instead of 27 ms. This leaves 60 ms instead of 53 ms for face/vehicle recognition. With a new latency budget of 60 ms, we can now use SE-LResNet50E-IR and ResNet-50 for face and vehicle recognition respectively, without violating the latency SLO. These options have higher accuracy than the originally chosen ones. Thus, learned caches enable incremental replanning of the yet-to-be-traversed DAG nodes, leading to higher end-toend accuracy for the query.

Incremental Replanning Algorithm
GATI's query planner realizes incremental replanning by deferring the selection of a particular DNN at a node to when the node needs to be scheduled for execution (Algorithm 1). (i) On receiving a query, the planner allocates partial latency budgets to each node of the DAG according to a policy to compute partial latency budgets (described below) and begins query execution at the root of the DAG. (ii) When a node needs to be executed, the planner picks the highest accuracy DNN at that node that can be executed within the partial latency budget (Line 5 in Algorithm 1). (iii) When a DNN finishes execution, the planner computes the saved latency by subtracting the observed execution time from the allocated partial latency budget. This saved latency is redistributed amongst downstream nodes according to the partial latency budget allocation policy.

Computing Partial Latency Budgets
The query planner considers all possible critical paths from the input to the output in the DAG to compute partial latency budgets. First, GATI computes a partial latency budget for each node by considering one DAG-input-to-DAG-output path at a time. Borrowing from planners that support the execution of a DAG for prediction serving tasks [43,63], GATI currently supports two policies to compute partial latency budgets. Equal Split. This splits the latency SLO equally amongst each node in a path. If L is the latency SLO and there are N nodes in the path, then each node receives a budget of L N . Proportional Split. This policy splits the latency SLO among nodes in a critical path in proportion to the maximum execution time of any DNN option in that node. If there are N nodes in an input-output path and C i is the maximum execution time among options at node i, then the partial latency budget for node i is computed as - Next, GATI computes the final partial latency budget at a node as the minimum partial latency budget available for the node from all possible paths, so as to meet the latency SLO for any path that the request might go through.
GATI allows any policy to be plugged into the incremental replanning framework as shown in Algorithm 1, which we also evaluate in §7.3.

Retraining Learned Caches
GATI retrains learned caches to exploit the temporal locality inherently present in online workloads ( §2.1.2): retraining achieves the effect of fine-tuning the caches, leading to better hit rates. We sample input queries that users issue to GATI and maintain a window of samples obtained over time. Then, we periodically retrain the predictor and selector network for each learned cache variant chosen in the composition phase using a mix of data from the window of samples and the original validation dataset provided by the user [44]. While picking sampled inputs, we weigh recent samples more heavily [76]. We obtain the training data needed for retraining by running a forward pass over the base DNN on the chosen sampled inputs as described earlier in §3.1.
We have two parameters to control retraining: the number of samples stored and the frequency at which retraining is triggered. Our evaluation shows that using~20% samples we can perform retraining within 500ms, owing to the simplicity of the predictor/selector networks' designs, and that a retraining period of 15 minutes works well for realistic workloads.
We present more detailed results in Section 7.2.2.

Overall System Design
As outlined in Figure 5, users interact with GATI in two ways: (i) Deployment Phase: Inference service owners begin DNN deployment by uploading a trained model and its validation dataset. Given this, GATI constructs an initial set of learned caches by exploring multiple variants and composing an optimal set of learned caches ( §4). The base DNN and along with learned caches are then deployed to the inference service.
(ii) Online Phase: Queries issued to GATI go through a frontend query planner that formulates a QEP for the query and handles its execution. The cache adaptation service records samples of the query inputs from the inference service and periodically retrains the learned caches. The inference service periodically pulls new versions of learned caches.

Implementation
We developed a prototype of GATI that implements the above system design. Each of the services (query scheduler, inference service, cache adaptation service) are written as Apache Thrift [1] services that communicate using RPCs. Our prototype currently supports DNNs written in PyTorch [12] and supports inference on CPUs and GPUs. For the exploration of learned cache variants we load the PyTorch model from the checkpoint and add hooks to save hidden layer outputs by traversing the list of Modules in the model. The composition phase uses Gurobi [8] to compute the optimal set of learned caches after exploration.
At runtime, the query scheduler accepts queries using a REST API. Each DNN and its learned caches reside on the same dedicated instance. We use similar hooks as in the exploration phase so that cache lookups can be performed during inference. The learned caches lookups are done asynchronous to the execution of the base DNN. On CPUs, we achieve this by running the base DNN execution and learned cache lookup in different processes. Each process is pinned to a dedicated set of CPU cores that do not overlap and the intermediate layer output is shared between processes using pipes. This ensures isolation between the computations and guarantees that the execution time does not exceed that of the vanilla base DNN. On GPUs, we overlap computations using CUDA streams [5]. The base DNN computation proceeds on the default stream while the learned cache computations are issued on a different stream. Our cluster deployment design of GATI is similar to existing prediction serving systems [23,45,63] and thus GATI inherits their horizontal scaling and fault-tolerance properties.

Evaluation
We use our prototype implementation of GATI to evaluate if GATI can deliver on the opportunities identified in §2.1.2. Our evaluation shows the following: (i) Across a range of datasets and state-of-the-art DNNs, GATI maintains high accuracy and offers up to 1.95× improvement in average latency compared to the base DNN ( §7.1).
(ii) GATI exploits temporal locality in real-world videos, giving up to 7.69× improvement in average latency ( §7.2.1). (iii) Incremental replanning, when using a DAG of models, helps overcome the fundamental latency-accuracy trade-off by simultaneously improving accuracy, with respect to the ground truth, by~1% and prediction latency by 1.26× ( §7.3). Testbed Setup: We deployed GATI on a heterogeneous cluster comprising of 2 p3.2xlarge GPU instances and 12 c5.4xlarge instances on AWS [2] thus measuring how GATI helps on both CPU and GPUs. Each GPU instance has 1 NVIDIA Tesla V100 GPU. For GPU experiments, we use 1 GPU instance for the inference service and the other for the cache adaptation service. For CPU inference, we use the c5.4xlarge instance and allocate 8 vCPUs each for the base model and learned cache computation. Each service (query scheduler, inference service, and cache adaptation service) runs as a daemon. Since the construction of initial caches is a one-time operation, we use multiple AWS GPU spot instances and CloudLab [26] for exploring multiple cache variants. Default Parameters: We consider six learned cache variants -FC(1024), FC(512), Pool(8192), Pool(4096), Conv(3,1), Conv (5,2). For the composition phase, we choose the target accuracy A to be 97%. We evaluate higher accuracy targets in §7.1.2. We use a batch size of 1 in all of our experiments and evaluate larger batch sizes in §7.2.1. Learned Cache Training Methodology: We use the validation data from each dataset to train the predictor and selector networks. The initial cache construction uses 80% of the training data, sampled at random for training each predictor/selector network. The remaining 20% is used for obtaining the metrics needed by the composition phase ( §4).

Late Binding Benefits
We first evaluate the latency benefits of using learned caches during inference. To study this aspect in isolation, we disable the cache adaptation service for these experiments.   [42,64]. We assume that models in a cascade are run serially to enable a fair comparison with GATI which uses only a single hardware resource for inference.

Learned caches with ResNet-50
We first consider Resnet-50 with CIFAR-10 data as the base DNN and use CPUs for inference. From Figure 6a, we observe that GATI exhibits an average latency of~34 ms, which is 1.95× lower than the latency of running the entire DNN. Figure 6(b) shows that GATI exhibits a spectrum of latencies with an accuracy of 96.97% with respect to the base ResNet-50 model, which is very close to the accuracy target of 97%. The learned caches occupy 1277.5 MB memory. Against quantization: GATI outperforms both 8 and 10bit quantization, improving average latencies by a factor of 1.25× and 1.74× respectively while also improving accuracy by 0.57% and 0.97% respectively. Against 12-bit quantization, GATI's accuracy is~1% lower but it provides lower latency for~87% of requests. Against distillation: GATI outperforms ResNet-50 distilled to ResNet-34 with an average latency improvement of 1.41× and an accuracy improvement of 0.57%. ResNet-50 distilled to ResNet-18 and a simple 5-layer CNN have better average latency than GATI but incur significant trade-off on accuracy.
Against pruning: GATI has better accuracies than pruning at 50%, 60%, and 70%, while also improving average latency by a factor of 1.39×-1.42×. Pruning at 40% has higher accuracy, but GATI offers better latency for 70% of the requests. Against cascades: We evaluate GATI against a cascade of progressively deeper models (ResNet-18, ResNet-50). We configure the confidence threshold to achieve an accuracy of 97%. Figure 8a shows that cascades can give lower latencies than GATI for a greater % of requests and even offer a slightly lower average latency. However, GATI's tail latency (99%-ile) is 1.68× lower. Importantly, we observe that learned caches can complement the models in a cascade. In this case we deploy learned caches for both models in the cascade and this gives a 1.66× improvement over cascades' average latency.  Using GPUs: Figure 8b shows that GATI has an average latency of~7.98 ms, which is 1.63× lower than running ResNet-50 on a GPU. GATI exhibits a spectrum of latencies with an overall accuracy of 96.8% with respect to the base ResNet-50 model. Interestingly, the learned caches in this scenario occupy 8502 MB memory, which is 6.66× times the memory occupied for CPU inference. This can be attributed to the observation that on GPUs, GATI used six learned caches where predictor networks had a fully-connected architecture, while GATI did not pick caches with fully-connected architecture on CPU due to high lookup latencies. Among this, we also noticed that GATI preferred to pick fully-connected architectures for initial layers in order to maximize the number of early cache hits. This observation follows from the differences between CPUs and GPUs highlighted in Table 4. We also notice that some baselines do not work as well on GPUs. For example, comparing Figure 6b and Figure 8b, pruning offers significant latency benefits on CPUs but not on GPUs. GATI offers similar benefits on both CPUs and GPUs. One-time cost to train learned caches: From our testbed, we found that the time to train learned caches depended on the layer of the base DNN. Training took~1 GPU hour for learned caches associated with earlier layers since the hidden layer output dimensions are typically much higher. We found that training later layers took~20 GPU minutes. Overall, we found that training learned caches For ResNet-50 required~50 GPU hours. Note that individual learned caches can be trained in parallel and are hence amenable to speedup via scale-out. Finally composing an optimal set of learned caches involves solving an optimization problem that takes~5 seconds. Runtime Overhead: For inference on GPUs, we noticed that learned cache computation on an average increased GPU utilization by~14%. Even with this, we found that GPUs were still not fully utilized. We note that the tail latencies are within 1% of the latency of the base DNN. Our measurements show that adopting asynchronous cache lookups reduces tail latency by 50.11% compared to synchronous lookups.

Other Workloads
We evaluate GATI on three other workloads and observe that GATI can give similar latency benefits with an accuracy close to 97%. For sake of brevity, we present the graphs in Appendix ( §A.2) and summarize our findings in Table 6. We highlight a number of interesting insights from these workloads: (i) GATI has better benefits on deeper models: From Figure 7b, we observe that a greater number of requests get higher latency improvements for a deeper ResNet-50 model for CPU inference. This directly follows from the discussion in §2.1.2 that deeper networks are built to achieve higher accuracy for a few "hard" requests, thereby allowing GATI to extract greater latency benefits for "easier" requests through early cache hits. We observe similar trends for GPU inference.
(ii) GATI offers high accuracy on difficult tasks: From Figure 8c, we observe that GATI works well and minimally tradesoff on accuracy even when the base DNN has lower accuracy (94.2% for CIFAR-10 vs 76.4% CIFAR-100). However, we observe that obtaining earlier cache hits is difficult when the base model itself does not have high fidelity. Despite this, we note that nearly 40% of requests get~2× latency benefit. (iii) GATI offers benefits even under constrained memory budgets: We emulated this in our testbed by giving reduced memory budgets in the composition phase. This models scenarios where GATI is deployed on low end GPUs. 3 From Figure 7a, we see that when memory is not a bottleneck (10 GB), GATI improves average latency by 1.62× with respect to the base model. With a memory budget of 1 GB, the average latency is 1.44× better than the base model. Further, GATI responds to reduction in memory budget by choosing learned cache variants that have smaller memory footprints. With a budget of 10 GB, 6 of the 13 chosen variants have a fully-connected architecture, which has a greater memory requirement. With a budget of 1 GB, GATI chooses pooling and convolutional architectures, which have a smaller memory footprint. (iv) GATI offers benefits across accuracy targets: We modified the accuracy target to be 99% instead of 97% and observed that GATI was able still able to give a 1.41× improvement in average latency over the base ResNet-50 model with an accuracy of 99.12%. Though the latency benefit at an accuracy target of 99% is lower than 97% by 1.38×, GATI is able to deliver on its promise of meeting the accuracy target and still offer latency benefits.

Adapting to Temporal Locality
In this section, we evaluate the ability of GATI to exploit temporal locality in online workloads. Workload: We use 4 publically available videos -Two of these are traffic camera videos (bellevue [35] and bend [7]) while the other two are surveillance camera videos (oxford [11] and sittard [4]). Each of these has 5-6 hours of video footage. Similar to [42], we perform object classification on the video at 1 fps. All of our evaluations use ResNet-18 model trained on CIFAR-10. The initial set of learned caches are constructed using validation data from CIFAR-10. Parameters: The inference service accumulates a batch of 100 requests and samples 20% for use in the cache adaptation service. We maintain 60 minutes worth of windowed samples. The cache adaptation service retrains caches every 15 minutes and immediately deploys them. We use a learning rate of 0.002 and retrain the learned caches for 5 epochs. Baseline: We compare against STATIC-GATI, where the cache adaptation service is disabled. Latencies get inflated when the inference service updates learned caches before executing a request. We filter such latencies in our results. Figure 9 shows the latency benefits of adapting to inherent temporal locality on both CPUs and GPUs. Across all videos, we observe that GATI is able to improve the average inference latency by a factor of 1.45×-7.69× on CPUs with respect to the base ResNet-18 model. Additionally, none of the inference requests required computing the entire DNN. We also observe that the accuracy in all of the cases is above the target of 97%.

Results
GATI also outperforms STATIC-GATI by up to a factor of 4.61×. The relative performance between the two varies according to the video. We see that in one case (the bend video), STATIC-GATI is unable to yield any cache hits and the performance matches that of the base DNN. This happens when the  learned caches are trained on data that looks different from the inference requests. Retraining learned caches accounts for this variance in addition to exploiting temporal locality. Sources of Improvement: Figure 9 shows that GATI is able to get more cache hits at earlier layers leading to a number of requests with low latencies. Table 7 shows the reason behind this trend. We observe that retraining drastically improves the fidelity of predictions from the predictor network compared to STATIC-GATI, with the change being highest in earlier layers. High fidelity predictions allow the selector network to yield more cache hits and improve the end-to-end latency. Impact of batching: To evaluate the impact of batching requests, we modify GATI to wait for a batch and then run inference on a GPU. We execute each batch until both requests have either had a cache hit or reached the end of DNN. We record the latency from when inference starts on GPU to discount the effects of queuing while forming batches. With a batch size of 2, GATI gives 2.88×-2.93× improvement in average latency in comparison to 3.67×-3.75× with batch size of 1. This is because, with batching, some requests might need to wait for other requests in the batch to finish execution. Retraining is quick: Our measurements show that using simple predictor and selector networks enables retraining learned caches to finish in~480 ms. This enables fast adaptation to workloads where temporal locality could change rapidly.

Insights
We now present some insights showing the impact of the workload characteristics and system parameters on the ability of GATI to exploit temporal locality windows.
(i) Benefits on more skewed output class distributions: Since it is hard to control the distribution of objects over time in real videos, we use a synthetic workload to study the impact of varying class distributions. We use a Zipfian distribution where the parameter α is used to control the distribution skew of object classes with lower values indicating greater skew. We consider two skew levels with α values of 1.5 and 3.0. The dominant class in the distribution changes every 15 minutes. Figure 10a shows that GATI performs better when the distribution is more skewed, offering 3.6× improvement in latency compared to a 3.2× gain with lesser skew. This correlates well to the intuition that caches perform better when the workload has high occurrences of some popular objects.
(ii) Small sampling rates suffice : We observe that the end-toend latency of inference is not impacted unless the sampling rate becomes less than 10%, motivating us to choose 20% for our experiments. Interestingly, this points out that a small number of samples are sufficient to capture temporal locality effects in realistic workloads such as videos.
(iii) GATI is sensitive to the periodicity of retraining: To evaluate this aspect, we consider the same Zipfian workload used in (i) with α=1.5 and a temporal window of 20 minutes. We vary the interval at which we retrain caches. We observe from Figure 10b that a lower interval of 10 mins helps GATI maintain high cache hit rates and adapt quickly to changes in distribution. With a larger update interval (40 mins), we observe that the hit rate drops continuously and increases again only after the learned caches have been retrained.

Incremental Replanning Benefits
We deploy GATI with the cache adaptation service disabled to study the benefits of incremental replanning in isolation. Workload: We use the same traffic analysis application example as discussed in §5. We use learned caches in the object detection module. We sample images from the LFW dataset [37], Stanford Cars dataset [48], and CIFAR-100 and issue them as input requests. The input distribution consists of 46% faces and 45% vehicles. Each DNN model outlined in Table 5 is deployed on a separate CPU instance. Baselines: We consider both the equal split and smart split policy ( §5.2.1). We evaluate the performance of GATI against a baseline that does not use learned caches or replanning. Results: Figure 11 shows that incremental replanning gives accuracy benefits for a variety of latency SLOs, with up tõ 1% improvement in end-to-end accuracy and this applies to both the equal and smart split policy. We observe greater benefits at tight latency SLOs (≤ 100 ms) since this is when cheaper models can be replaced with more expensive ones through replanning. Figure 12 provides insight into why replanning is able to give accuracy benefits. As an example, at a latency SLO of 80 ms, the baseline uses SE-LResNet18E-IR for face recognition and ResNet-18 for vehicle recognition. Due to saved latencies obtained by learned cache hits, GATI is able to use a more accurate SE-LResNet50E-IR model for 79% of face recognition tasks and a more accurate ResNet-50 for~80% of vehicle recognition tasks. Both of these lead to greater end-to-end accuracy for the query.
We see that GATI can reduce average latencies by up to 1.26× along with an accuracy improvement of~1%. Thus, incremental replanning helps overcome the fundamental latency-accuracy trade-off by improving on both metrics.

Related Work
Prediction Serving Systems. GATI is a prediction serving system just like [14,23,45,46,52,61,63]. GATI enables late-binding in DNNs through learned caches unlike [23] which treats the model as a black-box and applies caching only at the input layer. GATI borrows the idea of expressing queries as DAGs from [63], but uses it to improve accuracy and not for resource efficiency. [45] is orthogonal to GATI since it focuses on failure resilience and improving tail latencies. NoScope [42] uses a cascade of models to achieve a limited form of late-binding. We show in §7.1.1 that learned caches can complement cascades to give further latency benefits. [35,46,61] focus on optimizing the serving pipeline but do not focus improving DNN inference latency. [14] uses caching to improve predictions for recent data but targets linear models like logistic regression and not DNNs. Accuracy-latency trade-off. [36,73] complement DNNs with auxiliary networks just like in GATI, but provide an option for configurable latency-accuracy trade-off. A number of systems [72,78] also enable such trade-offs. GATI however lowers latencies without significant trade-off in accuracy. High performance inference. A number of systems [10,19,39] optimize the computation graph for faster DNN inference. Others specifically focus on RNNs [29,79] and CNNs [62]. All of these complement GATI's goal of late-binding the amount of computation to the hardness of the input. Query Planning. [75] outlines an idea of automatically picking models based on the latency SLO. GATI builds on this idea and provides inference service owners an option to specify an array of models at each node of the query DAG. In other domains, several other systems have used query replanning and dynamic adaptation to resource or workload changes [25,40,56,57,70] to get performance benefits. Using ML in Systems. A number of projects use ML to improve system design. This includes use of ML for database indices [47], cache replacement [65,69], memory management [55]. cluster scheduling [16,59], resource management [21], packet classification [53], and video content delivery [58,76,77]. Per our knowledge, GATI is the first work to use ML models as caches to accelerate DNN inference.

Conclusion
In this paper we presented GATI, a low-latency prediction serving system that uses caching to late-bind DNN inference computation. We proposed using learned caches, where the cache is represented by neural networks and outlined a design for their construction. Our evaluations show that GATI can improve average latency for easier inputs and exploit temporal locality to help online workloads.

A.1 Composing learned caches
The goal of the composition phase is to jointly select a global set of learned caches that minimize the expected average latency, while ensuring minimal degradation in accuracy, and meeting computation and memory constraints. We can formulate this as a mix-integer quadratic program.
Let us assume that we have a DNN with N layers for which we wish to construct learned caches. Let us consider that for each layer of the DNN, we have an array of K possible variants. Let us consider that we have a memory budget of M.
From the exploration phase, we obtain the following metrics for each variant -Hit Rate (H i, j ), Accuracy (A i, j ), Lookup Latency (T i, j ), and Memory Cost (M i, j ). Additionally, we profile the latency for the computation of each layer (L i ).

A.1.1 Optimization Problem
Given the above, we wish to decide which layer(s) of the DNN to use learned caches for and which variant to use at those layers. Indicator Variables.
We use the indicator variable b i, j to indicate if a variant j at layer i is chosen. b i, j = 1 means we chose that particular variant at that layer; 0 means we do not choose.
We use the indicator variable c i, j to indicate if layer j is the first layer after layer i to have a learned cache (This corresponds to a 1). For instance, consider a neural network with 5 layers -L 1 , L 2 , .. L 5 . Let us assume that we ultimately need caches only for layers L 1 , L 3 , and L 5 . In such a case, c 1,3 and c 3,5 will be 1 and the rest will be 0. Derived Metrics.
The hit rate H i, j is an independent metric that is measured for each variant at each layer. However, when the cache at an earlier layer gives hits, it reduces the number of input samples available at a later layer. To model this, we measure an effective cache-hit rate EH i, j as defined below - The above equation subtracts the effective cache hit rate of the previous layer that has a learned cache in a recursive fashion. The base case is EH 1,k = H 1,k for all k ∈ K.

Constraints
From the definition of the indicator variable c i, j , we formulate a constraint that at most one layer j after a layer i can have c i, j = 1.
Accuracy constraint. Given that variant at each layer has an accuracy A i, j , we need to ensure that the cumulative accuracy is greater than a minimum accuracy threshold A - The first part of the equation measures the effective accuracy for all inputs predicted by learned caches while the second part captures the accuracy component for inputs that go through the entire DNN (which get 100% accuracy).
Resource constraints. There are two resource constraints to consider -(i) memory and (ii) computation. Memory constraint: The total memory occupied by the chosen variants should be within the memory budget M.
Computational constraint: The underlying hardware imposes computational constraints on the cost of that computation in terms of latency (captured by T i, j ), and the degree of parallelism with which the computation can be done. We assume a simple computational model that we can have atmost one cache lookup at any given point of time. This lookup happens asynchronous to the base DNN computation. With this information, we need to ensure that cache lookups do not coincide in time. Hence, we have - In the above constraint, the LHS captures the running time of the cache lookup at layer i. The RHS subtracts the remaining running time for layer i to the end of the DNN from the remaining running time for layer j to the end of the DNN, where j is the earliest layer after i to have a learned cache. Essentially, for a layer i that has a chosen variant, we measure the running time between layer i and j and constraint it to be at least as large as the cache lookup time at layer i.
Objective We wish to minimize the expected latency for a given input request. We capture this as belowmin.

A.1.2 Relaxed Formulation
The problem with above solution is that it not linear with respect to the indicator variables. GATI adopts a three-step approach to simplify the above formulation. The key idea is to separate out the concerns of accuracy, overall latency, and resource contraints (computation and memory). We use the same indicator variables b i, j and c i, j as described above.
Step 1. Accuracy Filter: As a first step, we filter out model variants M i, j whose accuracy A i, j is below a minimum threshold A. To formulate this as a constraint - Step 2. Score Computation: We consider two factors in determining the importance of a particular variant: (i) The hit rate of the variant and (ii) The latency gain obtained by using the model variant in the event of a cache hit. We compute latency gain (LG) for a learned cache variant as the ratio of running time for the entire DNN to the running time assuming that a cache hit is obtained at the given learned cache variant. LG We prefer higher hit rates and higher latency gains. However, these are fundamentally at odds with each other since higher latency gains are obtained using variants at earlier layers of the base DNN where the hit rates would be lower, and vice versa. To balance these two factors, we compute a score (S -higher is better) that captures the benefit of using a variant: where α is a knob that lies in [0,1] and controls the relative importance of hit rate and latency gain.
Step 3. Resource Constraints: The memory and computational constraint remain the same as in the initial formulation -Eqn. 8 and Eqn. 9 respectively. Objective: Finally, the objective of our formulation is to maximize the sum of scores for chosen variants: The computed values of b i, j then determine which learned cache variants should be used along with the base DNN during inference.

A.2 Late Binding Benefits
(i) CIFAR-100 on ResNet-152: From Figure 13,14, we observe that GATI exhibits an average latency of 148.34 ms (CPU), which is 1.24X lower than the latency of running the entire DNN. GATI exhibits a spectrum of latencies with an overall accuracy of 97.79% (CPU) with respect to the base ResNet-152 model. We also observe that for ResNet-152, 15.32% of inputs run through the entire DNN, which is a large increase comparing to 3.51% (ResNet-18) and 1.53% (ResNet-50) on CIFAR-10 dataset. The reason is that CIFAR-100 has a lesser proportion of easier examples, which reduces the chances for early hits.  Requests   30  40  10  8  ResNet-101  ResNet-50  ResNet-34 ResNet-152 Pruning(x%) Quantization(n-bit) Distillation Gati     (CPU) and 4.15 ms (GPU), which is 1.72X and 1.28 X lower than the latency of running the entire DNN. GATI exhibits a spectrum of latencies with an overall accuracy of 96.86% (CPU) and 96.54% (GPU) with respect to the base ResNet-18 model.

A.2.1 Learned Caches Design Analysis
We analyze the impact of specific design choices for learned caches adopted by GATI that enable better latencies while ensuring that the accuracy is close to the target accuracy. Using distillation loss function in predictor network: We  compare the benefit of using a loss function inspired by distillation against a standard cross-entropy loss function for ResNet-50 on CIFAR-10. We observe that the distillation loss function gives a greater number of cache hits at earlier layers. The distillation loss function results in more accurate predictor networks, thereby allowing the selector network to infer more points as confident cache hits. Overall, we observe that this loss function yields 5.9% improvement in average latency. Decoupling prediction and selection in learned caches: Decoupling the decisions helps give cache hits with the desired accuracy and hit rate properties. We compare this choice against a baseline that uses only the predictor network and establishes a threshold over the softmax scores from the predictor network to infer cache hits. We notice from Figure 23 that applying different thresholds on predictor networks induces trade-offs between accuracy and hit rate that is hard to control. The selector network provides a binary classification mechanism that allows for optimal control of the trade-off between accuracy and hit rate. Exploring multiple predictor network architectures: We evaluate the benefit of exploration by comparing against baselines that consider either only one type of network architecture or only one hyper-parameter for each architecture. While there is not much impact overall accuracy, we observe from Figure 24, that exploring more variants leads to better latency benefits, since it provides more data points for the composition phase to pick from. The minimum latency (5.57 ms) by considering all variants matches the minimum latency by considering only variants with pooling architecture. Similarly, the median latency (27.5 ms) by considering all variants matches the minimum latency by considering only variants with fullyconnected architecture. Exploration thus gives combined benefits of exploring individual variants. A trade-off incurred in exploring multiple variants is that it requires more resources during the initial cache construction phase. Developers can limit the number of variants to be explored depending upon the resource availability. Optimal cache composition: During the composition phase, GATI evaluates multiple α values and picks a value that minimizes the expected latency while maximizing accuracy. For ResNet-50 on CIFAR-10, Figure 25 shows that α values of 0.2 provide optimal results. We observe similar values for GPU based inference. GATI selects the final set of learned cache variants based on this value.
We evaluate the benefit of formulating the composition phase as an optimization problem by comparing it to two greedy approaches -(i) A latency greedy approach that greedily picks variants with maximum latency gain while respecting computational and memory constraints. (ii) A hit-rate greedy approach that greedily picks variants with maximum hit-rate by respecting computational and memory constraints. We observe that the optimization problem has the most optimal latency profile, offering up to 5% improvement in aver-age latency. This can be tied down to a better visibility of the trade-offs between the various metrics for learned caches that an optimization formulation can capture. Hardware-aware profiling: In the composition phase, GATI profiles the lookup latency on the same target hardware where the model will be deployed for prediction serving. We observe that profiling in such a hardware-aware manner yields a 12.93% improvement in average latency.