JointDNN: An Efficient Training and Inference Engine for Intelligent Mobile Cloud Computing Services
Amir Erfan Eshratifar Mohammad Saeed Abrishami Massoud Pedram
cs.DC cs.AI cs.LG cs.PF

































































































Deep learning models are being deployed in many mobile intelligent applications. End-side services, such as intelligent personal assistants, autonomous cars, and smart home services often employ either simple local models on the mobile or complex remote models on the cloud. However, recent studies have shown that partitioning the DNN computations between the mobile and cloud can increase the latency and energy efficiencies. In this paper, we propose an efficient, adaptive, and practical engine, JointDNN, for collaborative computation between a mobile device and cloud for DNNs in both inference and training phase. JointDNN not only provides an energy and performance efficient method of querying DNNs for the mobile side but also benefits the cloud server by reducing the amount of its workload and communications compared to the cloud-only approach. Given the DNN architecture, we investigate the efficiency of processing some layers on the mobile device and some layers on the cloud server. We provide optimization formulations at layer granularity for forward- and backward-propagations in DNNs, which can adapt to mobile battery limitations and cloud server load constraints and quality of service. JointDNN achieves up to 18 and 32 times reductions on the latency and mobile energy consumption of querying DNNs compared to the status-quo approaches, respectively.





deep neural networks, intelligent services, mobile computing, cloud computing




JointDNN: An Efficient Training and Inference Engine for Intelligent Mobile Cloud Computing Services
    Amir Erfan Eshratifar,
        Mohammad Saeed Abrishami,
        and Massoud Pedram, Fellow, IEEE
        All authors are with the Department of Electrical Engineering, University of Southern California, Los Angeles, CA 90089-2562 USA (eshratif@usc.edu, abri442@usc.edu, pedram@usc.edu).


    
=====================================================================================================================================================================================================================================================================================================










§ INTRODUCTION

DNN architectures are promising solutions in achieving remarkable results in a wide range of machine learning applications, including, but not limited to computer vision, speech recognition, language modeling, and autonomous cars. Currently, there is a major growing trend in introducing more advanced DNN architectures and employing them in end-user applications. The considerable improvements in DNNs are usually achieved by increasing computational complexity which requires more resources for both training and inference <cit.>. Recent research directions to make this progress sustainable are: development of Graphical Processing Units (GPUs) as the vital hardware component of both servers and mobile devices <cit.>, design of efficient algorithms for large-scale distributed training <cit.> and efficient inference <cit.>, compression and approximation of models <cit.>, and most recently introducing collaborative computation of cloud and fog as known as dew computing <cit.>. 

Deployment of cloud servers for computation and storage is becoming extensively favorable due to technical advancements and improved accessibility. Scalability, low cost, and satisfactory Quality of Service (QoS) made offloading to cloud a typical choice for computing-intensive tasks. On the other side, mobile-device are being equipped with more powerful general-purpose CPUs and GPUs. Very recently there is a new trend in hardware companies to design dedicated chips to better tackle machine-learning tasks. For example, Apple's A11 Bionic chip <cit.> used in iPhone X uses a neural engine in its GPU to speed up the DNN queries of applications such as face identification and facial motion capture <cit.>.

In the status-quo approaches, there are two methods for DNN inference: mobile-only and cloud-only. In simple models, a mobile device is sufficient for performing all the computations. In the case of complex models, the raw input data (image, video stream, voice, etc.) is uploaded to and then the required computations are performed on the cloud server. The results of the task are later downloaded to the device. The effects of raw input and feature compression are studied in <cit.> and <cit.>.

Despite the recent improvements of the mobile devices mentioned earlier, the computational power of mobile devices is still significantly weaker than the cloud ones. Therefore, the mobile-only approach can cause large inference latency and failure in meeting QoS. Moreover, embedded devices undergo major energy consumption constraints due to battery limits. On the other hand, cloud-only suffers communication overhead for uploading the raw data and downloading the outputs. Moreover, slowdowns caused by service congestion, subscription costs, and network dependency should be considered as downsides of this approach <cit.>. 

The superiority and persistent improvement of DNNs depend heavily on providing a huge amount of training data. Typically, this data is collected from different resources and later fed into a network for training. The final model can then be delivered to different devices for inference functions. However, there is a trend of applications requiring adaptive learning in online environments, such as self-driving cars and security drones <cit.><cit.>. Model parameters in these smart devices are constantly being changed based on their continuous interaction with their environment. The complexity of these architectures with an increasing number of parameters and current cloud-only methods for DNN training implies a constant communication cost and the burden of increased energy consumption for mobile devices. The main difference of collaborative training and cloud-only training is that the data transferred in the cloud-only approach is the input data and model parameters but in the collaborative approach, it is layer(s)'s output and a portion of model parameters. Therefore, the amount of data communicated can be potentially decreased<cit.>.

Automatic partitioning of computationally extensive tasks over the cloud for optimization of performance and energy consumption has been already well-studied <cit.>. Most recently, scalable distributed hierarchy structures between the end-user device, edge, and cloud have been suggested <cit.> which are specialized for DNN applications. However, exploiting the layer granularity of DNN architectures for run-time partitioning has not been studied thoroughly yet. 













In this work, we are investigating the inference and training of DNNs in a joint platform of mobile and cloud as an alternative to the current single-platform methods as illustrated in Figure <ref>. Considering DNN architectures as an ordered sequence of layers, and the possibility of computation of every layer either on mobile or cloud, we can model the DNN structure as a Directed Acyclic Graph (DAG). The parameters of our real-time adaptive model are dependent on the following factors: mobile/cloud hardware and software resources, battery capacity, network specifications, and QoS. Based on this modeling, we show that the problem of finding the optimal computation schedule for different scenarios, i.e. best performance or energy consumption, can be reduced to the polynomial-time shortest path problem. 

To present realistic results, we made experiments with fair representative hardware of mobile device and cloud. To model the communication costs between platforms, we used various mobile network technologies and the most recent reports on their specifications in the U.S. 

DNN architectures can be categorized based on functionality. These differences enforce specific type and order of layers in architecture, directly affecting the partitioning result in the collaborative method. For discriminative models, used in recognition applications, the layer size gradually decreases going from input toward output as shown in Figure <ref>. This sequence suggests the computation of the first few layers on the mobile device to avoid excessive communication cost of uploading large raw input data. On the other hand, the growth of the layer output size from input to output in generative models which are used for synthesizing new data, implies the possibility of uploading a small input vector to the cloud and later downloading one of the last layers and performing the rest of computations on the mobile device for better efficiency. Interesting mobile applications like image-to-image translation are implemented with autoencoder architectures whose middle layers sizes are smaller compared to their input and output. Consequently, to avoid huge communication costs, we expect the first and last layers to be computed on the mobile device in our collaborative approach. We examined eight well-known DNN benchmarks selected from these categories to illustrate their differences in the collaborative computation approach. 

As we will see in Section <ref>, the communication between the mobile and cloud is the main bottleneck for both performance and energy in the collaborative approach. We investigated the specific characteristics of CNN layer outputs and introduced a loss-less compression approach to reduce the communication costs while preserving the model accuracy. 

State-of-the-art work for collaborative computation of DNNs <cit.> only considers one offloading point, assigning computation of its previous layers and next layers on the mobile and cloud platforms, respectively. We show that this approach is non-generic and fails to be optimal, and introduced a new method granting the possibility of computation on either platform for each layer independent of other layers. Our evaluations show that JointDNN significantly improves the latency and energy up to 3× and 7× respectively compared to the status-quo single platform approaches without any compression. The main contributions of this paper can be listed as:



  * Introducing a new approach for the collaborative computation of DNNs between the mobile and cloud 

  * Formulating the problem of optimal computation scheduling of DNNs at layer granularity in the mobile cloud computing environment as the shortest path problem and integer linear programming (ILP) 

  * Examining the effect of compression on the outputs of DNN layers to improve communication costs

  * Demonstrating the significant improvements in performance, mobile energy consumption, and cloud workload achieved by using JointDNN







§ INTRODUCTION











§ PROBLEM DEFINITION AND MODELING

In this section, we explain the general architecture of DNN layers and our profiling method. Moreover, we elaborate on how cost optimization can be reduced to the shortest path problem by introducing the JointDNN graph model. Finally, we show how the constrained problem is formulated by setting up ILP. 



 §.§ Energy and Latency Profiling


There are three methods in measuring the latency and energy consumption of each layer in neural networks <cit.>: 

Statistical Modeling: In this method, a regression model over the configurable parameters of operators (e.g. filter size in the convolution) can be used to estimate the associated latency and energy. This method is prone to large errors because of the inter-layer optimizations performed by DNN software packages. Therefore, it is necessary to consider the execution of several consecutive operators grouped during profiling. Many of these software packages are proprietary, making access to inter-layer optimization techniques impossible. 



In order to illustrate this issue, we designed two experiments with 25 consecutive convolutions on NVIDIA Pascal™ GPU using cuDNN® library <cit.>. In the first experiment, we measure the latency of each convolution operator separately and set the total latency as the sum of them. In the second experiment, we execute the grouped convolutions in a single kernel together and measure the total latency. All parameters are located on the GPU's memory in both experiments, avoiding any data transfer from the main memory to make sure results are exactly representing the actual computation latency. 



As we see in Figure <ref>, there is a large error gap between separated and grouped execution experiments which grows as the number of convolutions is increased. This observation confirms that we need to profile grouped operators to have more accurate estimations. Considering the various consecutive combination of operators and different input sizes, this method requires a very large number of measurements, not to mention the need for a complex regression model.




Analytical Modeling: To derive analytical formulations for estimating the latency and energy consumption, it is required to obtain the exact hardware and software specifications. However, the state-of-the-art in latency modeling of DNNs <cit.> fails to estimate layer-level delay within an acceptable error bound, for instance, underestimating the latency of a fully connected layer with 4096 neurons by around 900%. Industrial developers do not reveal the detailed hardware architecture specifications and the proprietary parallel computing architectures such as CUDA®, therefore, the analytical approach could be quite challenging <cit.>.

Application-specific Profiling: In this method, the DNN architecture of the application being used is profiled in run-time. The number of applications in a mobile device using neural networks is generally limited. In conclusion, this method is more feasible, promising higher accuracy estimations. We have chosen this method for the estimation of energies and latencies in the experiments of this paper.



 §.§ JointDNN Graph Model

First, we assume that a DNN is presented by a sequence of distinct layers with a linear topology as depicted in Figure <ref>. Layers are executed sequentially, with output data generated by one layer feeds into the input of the next one. We denote the input and output data sizes of k^th layer as α_k and β_k, respectively. Denoting the latency (energy) of layer k as ω_k, where k = 1, 2, ..., n, the total latency (energy) of querying the DNN is ∑_k=1^nω_k.



The mobile cloud computing optimal scheduling problem can be reduced to the shortest path problem, from node S to F, in the graph of Figure <ref>. Mobile Execution cost of the k^th layer (C(ME_k)) is the cost of executing the k^th layer in the mobile while the cloud server is idle. Cloud Execution cost of the k^th layer (C(CE_k)) is the executing cost of the k^th layer in the cloud server while the mobile is idle. Uploading the Input Data cost of the k^th layer is the cost of uploading output data of the (k-1)^th layer to the cloud server (UID_k). Downloading the Input Data cost of the k^th layer is the cost of downloading output data of the (k-1)^th layer to the mobile (DOD_k). The costs can refer to either latency or energy. However, as we showed in Section <ref>, the assumption of linear topology in DNNs is not true and we need to consider all the consecutive grouping of the layers in the network. This fact suggests the replacement of linear topology by a tournament graph as depicted in Figure <ref>. We define the parameters of this new graph, JointDNN graph model, in Table <ref>. 














In this graph, node C_i:j represents that the layers i to j are computed on the cloud server, while node M_i:j represents that the layers i to j are computed on the mobile device. An edge between two adjacent nodes in JointDNN graph model is associated with four possible cases: 1) A transition from the mobile to the mobile, which only includes the mobile computation cost (ME_i,j) 2) A transition from the cloud to the cloud, which only includes the cloud computation cost (CE_i,j) 3) A transition from the mobile to the cloud, which includes the mobile computation cost and uploading cost of the inputs of the next node (EU_i,j = ME_i,j + UID_j+1) 4) A transition from the cloud to the mobile, which includes the cloud computation cost and downloading cost of the inputs of the next node (ED_i,j = CE_i,j + DOD_j+1). Under this formulation, we can transform the computation scheduling problem to finding the shortest path from S to F. Residual networks are a class of powerful and easy-to-train architectures of DNNs <cit.>. In residual networks, as depicted in Figure <ref> (a), the output of one layer is fed into another layer with a distance of at least two. Thus, we need to keep track of the source layer (node 2 in Figure <ref>) to know that this layer is computed on the mobile or the cloud. Our standard graph model has a memory of one which is the very previous layer. We provide a method to transform the computation graph of this type of network to our standard model, JointDNN graph. 

In this regard, we add two additional chains of size k-1, where k is the number of nodes in the residual block (3 in Figure <ref>). One chain represents the case of computing layer 2 on the mobile and the other one represents the case of computing layer 2 on the cloud. In Figure <ref>, we have only shown the weights that need to be modified, where D_2 and U_2 are the cost of downloading and uploading the output of layer 2, respectively.

By solving the shortest path problem in the JointDNN graph model, we can obtain the optimal scheduling of inference in DNNs. The online training consists of one inference and one back-propagation step. The total number of layers is noted by N consistently throughout this paper so there are 2N layers for modeling training, where the second N layers are the mirrored version of the first N layers, and their associated operations are the gradients of the error function concerning the DNN's weights. The main difference between the mobile cloud computing graph of inference and online training is the need for updating the model by downloading the new weights from the cloud. We assume that the cloud server performs the whole back-propagation step separately, even if it is scheduled to be done on the mobile, therefore, there is no need for the mobile device to upload the weights that are updated by itself to save mobile energy consumption. The modification in the JointDNN graph model is adding the costs of downloading weights of the layers that are updated in the cloud to ED_i,j. The shortest path problem can be solved in polynomial time efficiently. 

However, the problem of the shortest path subjected to constraints is NP-Complete <cit.>. For instance, assuming our standard graph is constructed for energy and we need to find the shortest path subject to the constraint of the total latency of that path is less than a time deadline (QoS). However, there is an approximation solution to this problem, "LARAC" algorithm <cit.>, the nature of our application does not require to solve this optimization problem frequently, therefore, we aim to obtain the optimal solution. We can constitute a small look-up table of optimization results for a different set of parameters (e.g. network bandwidth, cloud server load, etc.). We provide the ILP formulations of DNN partitioning in the following sections.





 §.§ ILP Setup




  §.§.§ Performance Efficient Computation Offloading ILP Setup for Inference


We formulated the scheduling of inference in DNNs as an ILP with tractable number of variables. In our method, first we profile the delay and energy consumption of consecutive layers of size m ∈ {1, 2,…, N}. Thus, we will have
  
    N + (N-1) + ... + 1 = N(N+1)/2

number of different profiling values for delay and energy.
Considering layer i to layer j to be computed either on the mobile device or cloud server, we assign two binary variables m_i,j and c_i,j, respectively. Download and upload communication delays needs to be added to the execution time, when switching from/to cloud to/from mobile, respectively.


    T_computation   = ∑_i=1^n∑_j=i^n
    (m_i,j.T_mobile_L_i,j + c_i,j.T_cloud_L_i,j)

  
    T_communication   = ∑_i=1^n∑_j=i^n∑_k=j+1^nm_i,j.c_j+1,k.T_upload_L_j
        + ∑_i=1^n∑_j=i^n∑_k=j+1^nc_i,j.m_j+1,k.T_download_L_j
        + ∑_i=1^nc_1,i.T_upload_L_i
        + ∑_i=1^nc_i,n.T_download_L_n



    T_total = T_computation + T_communication


T_mobile_L_i,j and T_cloud_L_i,j represent the execution time of the i^th layer to the j^th layer on the mobile and cloud, respectively. T_download_L_i and T_upload_L_i represent the latency of downloading and uploading the output of the i^th layer, respectively. Considering each set of the consecutive layers, whenever m_i,j and one of {c_j+1,k}_k=j+1:n are equal to one, the output of the j^th layer is uploaded to the cloud. The same argument applies to downloading.
We also note that the last two terms in Eq. <ref> represent the condition by which the last layer is computed on the cloud and we need to download the output to the mobile device, and the first layer is computed on the cloud and we need to upload the input to the cloud, respectively. To support for residual architectures, we need to add a pair of download and upload terms similar to the first two terms in Eq. <ref> for the starting and ending layers of each residual block. In order to guarantee that all layers are computed exactly once, we need to add the following set of constraints:


    ∀ m ∈1:n: ∑_i=1^m∑_j=m^n(m_i,j + c_i,j) = 1


Because of the non-linearity of multiplication, an additional step is needed to transform Eq. <ref> to the standard form of ILP. We define two sets of new variables:


    u_i,j = m_i,j.∑_k=j+1^nc_j+1,k
       d_i,j = c_i,j.∑_k=j+1^nm_j+1,k


with the following constraints:


    u_i,j≤ m_i,j
       u_i,j≤∑_k=j+1^nc_j+1,k
       m_i,j + ∑_k=j+1^nc_j+1,k - u_i,j≤ 1
       d_i,j≤ c_i,j
       d_i,j≤∑_k=j+1^nm_j+1,k
       c_i,j + ∑_k=j+1^nm_j+1,k - d_i,j≤ 1


The first two constraints ensure that u_i,j will be zero if either m_i,j or ∑_l=j+1^nc_j+1,l are zero. The third inequality guarantees that u_i,j will take value one if both binary variables, m_i,j and ∑_l=j+1^nc_j+1,l, are set to one. The same reasoning works for d_i,j. In summary, the total number of variables in our ILP formulation will be 4N(N+1)/2, where N is total number of layers in the network. 



  §.§.§ Energy Efficient Computation Offloading ILP Setup for Inference

Because of the nature of the application, we only care about the energy consumption on the mobile side. We formulate ILP as follows:
  
    E_computation   = ∑_i=1^n∑_j=i^n
    m_i,j.E_mobile_L_i,j

  
    E_communication   = ∑_i=2^n∑_j=i^nm_i,j.E_download_L_i
        + ∑_i=1^n∑_j=i^n-1m_i,j.E_upload_L_j
        + (∑_i=1^n(1-m_1,i) - (n-1)).E_upload_L_1
        + (∑_i=1^n(1-m_i,n) - (n-1)).E_download_L_n

  
    E_total = E_computation + E_communication


E_mobile_L_i,j and E_cloud_L_i,j represent the amount of energy required to compute the i^th layer to the j^th layer on the mobile and cloud, respectively. E_download_L_i and E_upload_L_i represent the energy required to download and upload the output of i^th layer, respectively.
Similar to performance efficient ILP constraints, each layer should be executed exactly once:


    ∀ m ∈1:n: ∑_i=1^m∑_j=m^nm_i,j≤ 1


The ILP problem can be solved for different set of parameters (e.g. different uplink and download speeds), and then the scheduling results can be stored as a look-up table in the mobile device. Moreover because the number of variables in this setup is tractable solving ILP is quick. For instance, solving ILP for AlexNet takes around 0.045 seconds on Intel(R) Core(TM) i7-3770 CPU with MATLAB®'s intlinprog() function using primal simplex algorithm.



  §.§.§ Performance Efficient Computation Offloading ILP Setup for Training

The ILP formulation of online training phase is very similar to that of inference. In online training we have 2N layers instead of N obtained by mirroring the DNN, where the second N layers are backward propagation. Moreover, we need to download the weights that are updated in the cloud to the mobile. We assume that the cloud server always has the most updated version of the weights and does not require the mobile device to upload the updated weights. The following terms need to be added for the ILP setup of training:


    T_computation   = ∑_i=1^2n∑_j=i^2n
    (m_i,j.T_mobile_L_i,j + c_i,j.T_cloud_L_i,j)

  
    T_communication   = ∑_i=1^2n∑_j=i^2n∑_k=j+1^2nm_i,j.c_j+1,k.T_upload_L_j
        + ∑_i=1^2n∑_j=i^2n∑_k=j+1^2nc_i,j.m_j+1,k.T_download_L_j
        + ∑_i=1^nc_1,i.T_upload_L_i
        + ∑_i=n+1^2n∑_j=i^2nc_i,j.T_download_W_i



    T_total = T_computation + T_communication




  §.§.§ Energy Efficient Computation Offloading ILP Setup for Training

  
    E_computation   = ∑_i=1^2n∑_j=i^2n
    m_i,j.E_mobile_L_i,j

  
    E_communication   = ∑_i=2^2n∑_j=i^2nm_i,j.E_download_L_i
        + ∑_i=1^2n∑_j=i^2n-1m_i,j.E_upload_L_j
        + (∑_i=1^2n(1-m_1,i) - (2n-1)).E_upload_L_1
        + (∑_i=n+1^2n∑_j=i^2n(1-m_i,j) - (n-1)).E_download_W_i

  
    E_total = E_computation + E_communication




  §.§.§ Scenarios

There can be different optimization scenarios defined for ILP as listed below:


  * Performance efficient computation: In this case, it is sufficient to solve the ILP formulation for performance efficient computation offloading.

  * Energy efficient computation: In this case, it is sufficient to solve the ILP formulation for energy efficient computation offloading.

  * Battery budget limitation: In this case, based on the available battery, the operating system can decide to dedicate a specific amount of energy consumption to each application. By adding the following constraint to the performance efficient ILP formulation, our framework would adapt to battery limitations: 

    E_computation + E_communication≤ E_ubound



  * Cloud limited resources: In the presence of cloud server congestion or limitations on user's subscription, we can apply execution time constraints to each application to alleviate the server load:


    ∑_i=1^n∑_j=i^n
    c_i,j.T_cloud_L_i,j≤ T_ubound



  * QoS: In this scenario, we minimize the required energy consumption while meeting a specified deadline:


    min{E_computation + E_communication}
    
    T_computation + T_communication≤ T_QoS



This constraint could be applied to both energy and performance efficient ILP formulations.






§ EVALUATION




 §.§ Deep Architecture Benchmarks


Since the architecture of neural networks depends on the type of application, we have chosen three common application types of DNNs as shown in Table <ref>:



  * Discriminative neural networks are a class of models in machine learning for modeling the conditional probability distribution P(y|x). This class generally is used in classification and regression tasks. AlexNet<cit.>, OverFeat<cit.>, VGG16<cit.>, Deep Speech<cit.>, ResNet<cit.>, and NiN<cit.> are well-known discriminative models we use as benchmarks in this experiment. Except for Deep Speech, used for speech recognition, all other benchmarks are used in image classification tasks. 


  * Generative neural networks model the joint probability distribution P(x,y), allowing generation of new samples. These networks have applications in Computer Vision <cit.> and Robotics <cit.>, which can be deployed on a mobile device. Chair <cit.> is a generative model we use as a benchmark in this work.

  * Autoencoders are another class of neural networks used to learn a representation for a data set. Their applications are image reconstruction, image to image translation, and denoising to name a few. Mobile robots can be equipped with autoencoders to be used in their computer vision tasks. We use Pix2Pix <cit.>, as a benchmark from this class.








 §.§ Mobile and Server Setup

We used the Jetson TX2 module developed by NVIDIA® <cit.>, a fair representation of mobile computation power as our mobile device. This module enables efficient implementation of DNN applications used in products such as robots, drones, and smart cameras. It is equipped with NVIDIA Pascal®GPU with 256 CUDA cores and a shared 8 GB 128 bit LPDDR4 memory between GPU and CPU. To measure the power consumption of the mobile platform, we used INA226 power sensor <cit.>. 

NVIDIA® Tesla® K40C <cit.> with 12 GB memory serves as our server GPU. The computation capability of this device is more than one order of magnitude compared to our mobile device. 







 §.§ Communication Parameters

To model the communication between platforms, we used the average download and upload speed of mobile Internet <cit.> for different networks (3G, 4G and Wi-Fi) as shown in Table <ref>.


The communication power for download (P_d) and upload (P_u) is dependent on the network throughput (t_d and t_u). Comprehensive examinations in <cit.> indicates that uplink and downlink power can be modeled with linear equations (Eq. <ref>) fairly accurate with less than 6% error rate. Table <ref> shows the parameter values of this equation for different networks. 


    P_u = α_u t_u + β
    
    P_d = α_d t_d + β






§ RESULTS
 



The latency and energy improvements of inference and online training with our engine for 8 different benchmarks are shown in Figures <ref> and <ref>,  respectively. We considered the best case of mobile-only and cloud-only as our baseline. JointDNN can achieve up to 66% and 86% improvements in latency and energy consumption, respectively during inference. Communication cost increases linearly with batch size while this is not the case for computation cost and it grows with a much lower rate, as depicted in <ref>(b). Therefore, a key observation is that as we increase the batch size, the mobile-only approach becomes more preferable. 




During online training, the huge communication overhead of transmitting the updated weights will be added to the total cost. Therefore, to avoid downloading this large data, only a few back-propagation steps are computed in the cloud server. We performed a simulation by varying the percentage of updated weight. As the percentage of updated weights increases, the latency and energy consumption becomes constant which is shown in Figure <ref>. This is the result of the fact that all the backpropagations will be performed on the mobile device and weights are not transferred from the cloud to the mobile. JointDNN can achieve improvements up to 73% in latency and 56% in energy consumption during inference.



Different patterns of scheduling are demonstrated in Figure <ref>. They represent the optimal solution in the Wi-Fi network while optimizing for latency while mobile/cloud is allowed to use up to half of their computing resources. They show how the computations in DNN is divided between the mobile and the cloud. As can be seen, discriminative models (e.g. AlexNet), inference follows a mobile-cloud pattern and training follows a mobile-cloud-mobile pattern. The intuition is that the last layers are computationally intensive (fully connected layers) but with small data sizes, which require a low communication cost, therefore, the last layers tend to be computed on the cloud. For generative models (e.g. Chair), the execution schedule of inference is the opposite of discriminative networks, in which the last layers are generally huge and in the optimal solution they are computed on the mobile. The reason behind not having any improvement over the base case of mobile-only is that the amount of transferred data is large. Besides, cloud-only becomes the best solution when the amount of transferred data is small (e.g. generative models). Lastly, for autoencoders, where both the input and output data sizes are large, the first and last layers are computed on the mobile.






JointDNN pushes some parts of the computations toward the mobile device. As a result, this will lead to less workload on the cloud server. As we see in Table <ref>, we can reduce the cloud server's workload up to 84% and 53% on average, which enables the cloud provider to provide service to more users, while obtaining higher performance and lower energy consumption compared to single-platform approaches.  





 §.§ Communication Dominance

Execution time and energy breakdown for AlexNet, which is noted as a representative for the state-of-the-art architectures deployed in cloud servers, is depicted in Figure <ref>. The cloud-only approach is dominated by the communication costs. As demonstrated in Figure <ref>, 99%, 93% and 81% of the total execution time are used for communication in case of 3G, 4G, and Wi-Fi, respectively. This relative portion also applies to energy consumption. Comparing the latency and energy of the communication to those of mobile-only approach, we notice that the mobile-only approach for AlexNet is better than the cloud-only approach in all the mobile networks. We apply loss-less compression methods to reduce the overheads of communication, which will be covered in the next section. 






 §.§ Layer Compression


The preliminary results of our experiments show that more than 75% of the total energy and delay cost in DNNs are caused by communication in the collaborative approach. This cost is directly proportional to the size of the layer being downloaded to or uploaded from the mobile device. Because of the complex feature extraction process of DNNs, the size of some of the intermediate layers are even larger than the network's input data. For example, this ratio can go as high as 10× in VGG16. To address this bottleneck, we investigated the compression of the feature data before any communication. This process can be applied to different DNN architecture types; however, we only considered CNNs due to their specific characteristics explained later in detail. 



CNN architectures are mostly used for image and video recognition applications. Because of the spatially local preservation characteristics of conv layers, we can assume that the outputs of the first convolution layers are following the same structure as the input image, as shown in Figure <ref>. Moreover, a big ratio of layer outputs is expected to be zero due to the presence of the ReLU layer. Our observations shows that the ratio of neurons equal to zero (ZR) varies from 50% to 90% after relu in CNNs. These two characteristics, layers being similar to the input image, and a large proportion of their data being a single value, suggest that we can employ existing image compression techniques to their output. 



There are two general categories of compression techniques, lossy and loss-less <cit.>. In loss-less techniques, the exact original information is reconstructed. On the contrary, lossy techniques use approximations and the original data cannot be reconstructed. In our experiments, we examined the impact of compression of layer outputs using PNG, a loss-less technique, based on the encoding of frequent sequences in an image. 


Even though the data type of DNN parameters in typical implementations is 32-bits floating-points, most image formats are based on 3-bytes RGB color triples. Therefore, to compress the layer in the same way as 2D pictures, the floating-point data should be quantized into 8-bits fixed-point. Recent studies show representing the parameters of DNNs with only 4-bits affects the accuracy, not more than 1% <cit.>. In this work, we implemented our architectures with an 8-bits fixed-point and presented our baseline without any compression and quantization. 


The layers of CNN contain numerous channels of 2D matrices, each similar to an image. A simple method is to compress each channel separately. In addition to extra overhead of file header for each channel, this method will not take the best of the frequent sequence decoding of PNG. One alternative is locating different channels side by side, referred to as tiling, to form a large 2D matrix representing one layer as shown in Figure <ref>. It should be noted that 1D fully connected layers are very small and we did not apply compression on them.

The Compression Ratio (CR) is defined as the ratio of the size of the layer (8-bit) to the size of the compressed 2D matrix in PNG. Looking at the results of compression for two different CNN architectures in Figure <ref>, we can observe a high correlation between the ratio of pixels being zero (ZR) and CR. PNG can compress the layer data up to 5.8× and 3.5× by average, therefore the communication costs can be reduced drastically. By replacing the compressed layer's output and adding the cost of the compression process itself, which is negligible compared to DNN operators, in JointDNN formulations, we achieve an extra 4.9× and 4.6× improvements in energy and latency on average, respectively.





§ RELATED WORK AND COMPARISON


General Task Offloading Frameworks. There are existing prior arts focusing on offloading computation from the mobile to the cloud<cit.>. However, all these frameworks share a limiting feature that makes them impractical for computation partitioning of the DNN applications. 

These frameworks are programmer annotations dependent as they make decisions about pre-specified functions, whereas JointDNN makes scheduling decisions based on the model topology and mobile network specifications in run-time. Offloading in function level, cannot lead to efficient partition decisions due to layers of a given type within one architecture can have significantly different computation and data characteristics. For instance, a specific convolution layer structure can be computed on mobile or cloud in different models in the optimal solution. 

Neurosurgeon <cit.> is the only prior art exploring a similar computation offloading idea in DNNs between the mobile device and the cloud server at layer granularity. Neurosurgeon assumes that there is only one data transfer point and the execution schedule of the efficient solution starts with mobile and then switches to the cloud, which performs the whole rest of the computations. Our results show this is not true especially for online training, where the optimal schedule of execution often follows the mobile-cloud-mobile pattern. Moreover, generative and autoencoder models follow a multi-transfer points pattern. Also, the execution schedule can start with the cloud especially in case of generative models where the input data size is large. Furthermore, inter-layer optimizations performed by DNN libraries are not considered in Neurosurgeon. Moreover, Neurosurgeon only schedules for optimal latency and energy, while JointDNN adapts to different scenarios including battery limitation, cloud server congestion, and QoS. Lastly, Neurosurgeon only targets simple CNN and ANN models, while JointDNN utilizes a graph-based approach to handle more complex DNN architectures like ResNet and RNNs.



§ ACKNOWLEDGEMENTS

This research was supported by grants from NSF SHF, DARPA MTO, and USC Annenberg Fellowship.


§ CONCLUSIONS AND FUTURE WORK

In this paper, we demonstrated that the status-quo approaches, cloud-only or mobile-only, are not optimal with regard to latency and energy. We reduced the problem of partitioning the computations in a DNN to shortest path problem in a graph. Adding constraints to the shortest path problem makes it NP-Complete, therefore, we also provided ILP formulations to cover different possible scenarios of limitations of mobile battery, cloud congestion, and QoS. The output data size in discriminative models is typically smaller than other layers in the network, therefore, last layers are expected to be computed on the cloud, while first layers are expected to be computed on the mobile. Reverse reasoning works for Generative models. Autoencoders have large input and output data sizes, which implies that the first and last layers are expected to be computed on the mobile. With these insights, the execution schedule of DNNs can possibly have various patterns depending on the model architecture in model cloud computing. JointDNN formulations are designed for feed-forward networks and its extension to recurrent neural networks will be studied as a future work.



IEEEtran

[
    < g r a p h i c s >
]Amir Erfan Eshratifar
Amir Erfan Eshratifar received dual B.S. degrees in Electrical Engineering and Computer Science from Sharif University of Technology, Tehran, Iran in 2017. He is currently a Ph.D. student in Ming Hsieh Department of Electrical Engineering, University of Southern California (USC), Los Angeles, CA, USA since 2017.


[
    < g r a p h i c s >
]Mohammad Saeed Abrishami
Mohammad Saeed Abrishami received his B.S. degree in Electrical Engineering from University of Tehran, Tehran, Iran in 2014. He is currently a Ph.D. student in Ming Hsieh Department
of Electrical Engineering, University of Southern California (USC), Los Angeles, CA, USA since 2014.






[
    < g r a p h i c s >
]Massoud Pedram
Massoud Pedram (F’01) received the B.S. degree
in electrical engineering from the California Institute
of Technology, Pasadena, CA, USA, in 1986, and the
M.S. and Ph.D. degrees in electrical engineering and
computer sciences from the University of California Berkeley, CA, USA, in 1989 and 1991, respectively. In 1991, he joined the Ming Hsieh Department
of Electrical Engineering, University of Southern California (USC), Los Angeles, CA, USA, where he is currently the Charles Lee Powel Professor
of USC Viterbi School of Engineering.

















