{'fraction_non_alphanumeric': 0.03974305843348529, 'fraction_numerical': 0.011645254869457108, 'mean_word_length': 4.4471783295711065, 'pattern_counts': {'":': 0, '<': 2, '<?xml version=': 0, '>': 0, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
Graph Reinforcement Learning-based CNN Inference Offloading in Dynamic Edge Computing

This paper studies the computational offloading of CNN inference in dynamic multi-access edge computing (MEC) networks. To address the uncertainties in communication time and Edge servers' available capacity, we use early-exit mechanism to terminate the computation earlier to meet the deadline of inference tasks. We design a reward function to trade off the communication, computation and inference accuracy, and formulate the offloading problem of CNN inference as a maximization problem with the goal of maximizing the average inference accuracy and throughput in long term. To solve the maximization problem, we propose a graph reinforcement learning-based early-exit mechanism (GRLE), which outperforms the state-of-the-art work, deep reinforcement learning-based online offloading (DROO) and its enhanced method, DROO with early-exit mechanism (DROOE), under different dynamic scenarios. The experimental results show that GRLE achieves the average accuracy up to 3.41x over graph reinforcement learning (GRL) and 1.45x over DROOE, which shows the advantages of GRLE for offloading decision-making in dynamic MEC.


I. INTRODUCTION
The advancement in convolutional neural networks (CNNs) has propelled various emerging CNN-based IoT applications, such as autonomous driving and augmented reality. For timecritical IoT applications, not only high reliability but also low latency is crucial to enable reliable services and safe intelligent control [1]. To achieve higher inference accuracy, deeper CNNs with massive multiply-accumulate operations are often required. However, resource-limited IoT devices are not feasible to complete computational intensive CNNs within a stringent deadline [2].
Edge computing is a paradigm that allows IoT devices to offload computational tasks to their nearby edge servers (ESs) via wireless channels [1], [3]. However, the stochastic wireless channel states may cause fluctuations in communication time, which consequently results in that the exact task completion time is unknown in advance and varies over time [4]. To address the uncertainties in communication time, dynamic offloading methods are proposed to strike a balance between the communication and computation [5]- [8]. However, when communication takes too much time or the available computation resource at ESs is insufficient, it cannot meet the stringent deadline if running an inference task through the entire pretrained CNN model (e.g., until the end of the main branch of  To address this issue, dynamic inference methods [9] are promising to meet the latency requirements through modification of CNN architecture and allowing dynamic inference time at the compromise of inference accuracy. Early-exit mechanism [10] is a dynamic inference method, which terminates the inference at an early stage, as shown in Fig. 1. Unlike the conventional CNN inference, early-exit architecture enables the intermediate classifiers of a CNN to provide different accuracy-latency trade-offs along its depth. The goal of early-exit architecture is to provide adaptive accuracy-latency behavior so that each inference task terminates at an appropriate exit based on its computation time budget. In other words, in case of poor channel states, an early-exit can be used to terminate the computation earlier, thereby providing the inference result within the deadline of time critical applications at the expense of slightly lower accuracy, instead of completely missing the deadline. However, how to design an efficient task offloading scheme to trade off communication, computation and inference accuracy in dynamic multi-access edge computing (MEC) is a challenging problem and has not yet been adequately addressed.
Based on the motivation above, this paper studies the offloading problem of CNN inference tasks in dynamic MEC networks. Our contributions are summarized as follows.
• We use early-exit CNN architecture to provide dynamic inference to address the issue caused by stochastic available computing resource of ESs and the uncertainties in communication time, thereby ensuring that inference task is completed within time constraints. • We define a reward function to strike a balance among the communication, computation and inference accuracy. Then we model the CNN inference offloading problem as a maximization problem to maximize the average inference accuracy and throughput in long term. • We design a graph reinforcement learning-based earlyexit mechanism (GRLE) to make optimal offloading decisions.

II. RELATED WORK
Due to the characteristics of time-varying wireless channels, it is crucial to make effective offload decisions to ensure the QoS in edge computing paradigms. Guo et al. [5] proposed a heuristic search-based energy-efficient dynamic offloading scheme to minimize energy consumption and completion time of task with strict deadline. Tran et al. [6] designed a heuristic search method to optimize task offloading and resource allocation to jointly minimize task completion time and energy consumption by iteratively adjusting the offloading decision. However, heuristic search methods require accurate input information, which is not applicable to dynamic MEC.
Reinforcement learning (RL) is a holistic learning paradigm that interacts with the dynamic MEC to maximize longterm rewards. Li et al. [7] proposed to use deep RL (DRL)based optimization methods to address dynamic computational offloading problem. However, applying DRL directly to the problem is inefficient in a practical deployment because offloading algorithms typically require many iterations to search an effective strategy for unseen scenarios. Huang et al. [8] proposed DROO to significantly improve the convergence speed through efficient scaling strategies and direct learning of offloading decisions. However, the DNN used in DROO can only handle Euclidean data, which makes it not well suitable for the graph-like structure data of MEC. In addition, all the above methods do not provide dynamic inference, which is lack of flexibility in making good use of any available computation resource under stringent latency.

III. SYSTEM MODEL
This paper studies the computation offloading in an MEC network, which consists of M IoT devices and N ESs. The set of IoT devices and ESs are denoted as M = {1, 2, · · · , M } and N = {1, 2, · · · , N } respectively. At each time slot k ∈ K, each IoT device generates a computational task that has to be processed within its deadline, where K = {1, 2, · · · , K}. The length of each time slot k is assumed to be τ . The computational task of IoT device is assumed to use a CNN with L convolutional layers (CLs), which are denoted as L = {1, 2, · · · , L}. Each IoT device can offload its inference task to one ES through wireless channel and each ES can serve multiple IoT devices at each time slot. In the case of poor wireless channel state or insufficient available computation resource of ESs, ESs can use the early-exit mechanism to terminate the computation earlier to meet the deadline of an inference task. After completing inference task, ES will send back the results to IoT devices. To perform computational offloading, two decisions should be considered: (1) to which ES an IoT device should offload its tasks; (2) to which earlyexit the ES can perform the task based on a time constraint.

A. Communication time
Computation offloading involves delivering of task data and its inference result between IoT device and ES. We assume that a task of IoT device m is offloaded to ES n at time slot k. The task information is expressed as θ k m,n = d k m,n , δ k m,n , r k m,n , where d k m,n and δ k m,n are the task size and latency requirement respectively, and r k m,n is the uplink transmission data rate from IoT device m to ES n. Therefore, the transmission delay of an inference task from IoT device m to ES n is denoted as where α k m,n ∈ {0, 1} is a binary variable to indicate whether the task of device m is offloaded to ES n at time slot k. As each inference task can only be offloaded to one ES, there is In addition, as the output of CNN is very small, often a number or value that represents the classification or detection result, transmission delay of the feedback is negligible.

B. Computation time
During computation, an ES can only select an early-exit to perform inference for each offloaded task. As we use a binary variable β k m,n,l ∈ {0, 1} to denote if ES n performs device m's task until early-exit l, there is l∈L β k m,n,l = 1, ∀m ∈ M and n ∈ N.
Assuming that ES n performs an inference task until earlyexit l, the computation time and inference accuracy are denoted as t cmp n,l and φ l respectively. Therefore, the computation time of m's task on ES n is expressed as Correspondingly, the achieved inference accuracy of the task generated by IoT device m at time slot k is We assume each ES processes inference tasks on a firstcome-first-served basis. Namely, ES n can start to process a new arrival task only if it has processed all the previously arrived tasks. Assume that device m's task generated at time slot k is offloaded to ES n, device m can start transmission of this task only after completing transmission of its previous tasks. Since the propagation time is negligible, the task generated by device m at time slot k arrives at ES n at time instant, T a m,n (k), which can be expressed as Correspondingly, the waiting time at ES n of device m's task generated at time slot k, t w m,n (k), can be calculated as (7), where 1 (·) is an indicator function to show the occurrence of device m 's task arriving at ES n before device m's task.
IV. PROBLEM FORMULATION A. Completion time of an inference task There are three steps to complete computation offloading. First, an IoT device sends an inference task to an ES over uplink wireless channel, and then ES performs inference. Finally, ES sends the inference result back to IoT device via downlink wireless channels. Therefore, completion time of an inference task includes communication time, waiting time and computation time, which is denoted as

B. Objective
In dynamic MEC scenarios, task information of each IoT device and the topology of network may change over time, such as the time-varying task size and wireless channel states, connection establishment and disconnection between IoT devices and ESs. To trade off communication, computation and inference accuracy, we define a reward function, Q (G k , x k ), to denote the achieved reward at time slot k, as below where G k is the MEC state including task information θ k m,n of IoT devices and the computation information t cmp n,l and φ l of early-exits; x k α k m,n β k m,n,l |m ∈ M, n ∈ N, l ∈ L is the offloading decision determining to offload device m's task to ES n, α k m,n , and ES n performs the task until early-exit l, when the completion time t m,n (k) exceeds the deadline δ k m,n and ψ (t m,n (k)) → 1 when t m,n (k) → 0; Sigmod (·) is a nonlinear function with the value between 0 and 1 [11]. The goal of CNN inference offloading is to maximize the average inference accuracy and throughput of inference tasks in a long term perspective, which is formulated as bellows: subject to (2), (3) and V. GRAPH REINFORCEMENT LEARNING-BASED

A. Candidate early-exits
At time slot k, the computational complexity of offloading decision x k is M N L, which is huge for MEC scenario when the number of IoT devices and the possible early-exists are large. In fact, it is not necessary to perform the computation with all early-exits. In Section VI-B, our experiment shows that some exits located deeper in a CNN does not improve inference accuracy. Therefore, we select the five meaningful early-exits in VGG-16 [12] in our experiments instead of using all early-exits (i.e., L = 17). Fig. 2 presents the framework of GRLE, where an actorcritic network is used to generate offloading decisions and update offloading policies. The actor network is responsible for predicting actions; critic network quantifies the prediction and generates offloading decisions; and experience replay buffer stores historical experiences and samples mini-batch training data to train the graph convolutional network (GCN) [13].

B. GRLE framework
In DROO [8], a DNN is used to construct the actor network to extract the features from the input data. However, DNN can only process regular Euclidean data, which is not applicable to dynamic MEC network with graph-like structure data. To better process such data, we apply GCN to replace DNN and analyze the characteristics of graph data through message passing and aggregation between nodes. GCN learns the aggregation method that relies on the relationship between nodes. For a new topology, GRLE does not need to re-train the aggregation function because it can automatically filter the messages from disconnected nodes by graph data updates. As such, GRLE has robust adaptability in dynamic MEC.

C. Actor network
Since each task can only be performed by one ES using one early-exit, the two-step task offload decision for device m's task can be merged into one step, i.e., a device has options of N L early-exits to offload its task. We model the structure information of MEC scenario as graph data G = (V, E). In GRLE, M devices and N L early-exits are represented by the graph vertices V, and each IoT device and early-exit is connected by a directed edge e ∈ E. At time slot k, we parse the MEC state G k as the initial input data h (0) for GCN. GCN uses multiple graph convolutional layers to aggregate the neighborhood information. For each node v ∈ V k , we define the neighborhood information aggregation process as follows, where W (i+1) is the weight parameters, A (i) (·) is the aggregation function, N v is the set of node v's neighbors, C (·) is a concatenate operation, Relu (·) is a non-linear function [11].
The system can acquire the information of tasks and the status of ESs by aggregating the information in the secondorder neighborhood of nodes. For example, IoT device m can grasp the information of its second-order neighborhood (other IoT devices connected to ES n) through its firstorder neighborhood ES n; ES n can acquire the status of its second-order neighborhood (other ESs) through its first-order neighborhood (IoT devices connected to ES n). Therefore, we use two GCN layers in GRLE, i.e., i ∈ {0, 1} in (12).
After completing the information aggregation of nodes, we first concatenate the features of the source node (IoT device) and destination node (an early-exit of an ES), h src e and h dst e , to get the feature of edge e ∈ E k as Then, we can classify the edges to get the relaxed offloading actionx k = {x k,e |x k,e = f (h e ) , e ∈ E k }, by the function f (h e ) = Sigmod (MLP 2 (Relu (MLP 1 (h e )))) where MLP 1 and MLP 2 are multi-layer perceptions to extract the feature of edge e. We use Sigmod (·) function to make the relaxed offloading action satisfy 0 <x k,e < 1 [11].

D. Critic network
We use the order-preserving method in DROO [8] to quantify the relaxed offloading actionx k and generate S candidate binary offloading decisions X k = x k,e ∈ {0, 1} , e ∈ E k and S = M N L. Recall that each candidate offloading action x (s) k can achieve reward by solving (9). Therefore, the optimal offloading action at kth time slot can be generated as

E. Offloading policy update
We use the experience replay buffer technique to train the GCN using the stored data samples (k, G k , x * k ), as shown in Fig. 2. At time slot k, we randomly select a mini-batch of training data ∆ k = (∆ T k , ∆ G k , ∆ X k ) from the memory to update the parameters of GCN and reduce the averaged cross-entropy loss [8], as where |∆ k | is the size of the mini-batch training data, ∆ T k is the set of time slots, ∆ G k is the set of graphs, and ∆ X k is the set of actions. The detailed process of GRLE is described in Algorithm 1.

Algorithm 1: GRLE for offloading decision-making
Input: MEC state G k , ∀k ∈ K, training interval ω Output: Offloading decision x * k for k = 1, 2, · · · , K do Generate the relaxed offloading actionx k in (14); Quantifyx k into S binary actions X k ; Select the optimal offloading action x * k using (15); Update the experience replay buffer by adding Randomly sample a mini-batch of training data ∆ k from the buffer, train GCN and update the parameters using (16). end end

A. Simulation setup and methodology
In this experiment, we consider an MEC network with 14 IoT devices and 2 ESs (RTX 2080TI and GTX 1080TI). We consider image recognition task using VGG-16, which should be processed within a fixed deadline of δ k m,n = 30ms. For IoT device m, the task size d k m,n is between 50 KBytes and 100 KBytes, and the uplink transmission data rate r k m,n is between 20 Mbps and 100 Mbps. We implement GRLE with PyTorch, and the training parameters are set as: the hidden neurons of two GCN layers are 128 and 64; the learning rate is initialized as 0.001; the experience replay buffer size is 128; the minibatch size |∆ k | = 64; the training interval ω = 10; the optimizer of loss function ξ (∆ k ) is Adam function [12]. To validate the effectiveness of our proposed GRLE, we compare it with the following three offloading methods: • GRL: Basic graph reinforcement learning; • DROO: The state-of-the-art work [8]; • DROOE: DROO with early-exit mechanism.

B. Performance of early-exits
In this experiment, we first train the main branch of VGG-16 on the dataset cifar-10 [14], and then use it as the pretrained model to train the sub-models of early-exits. We add a classifier after each CL or pooling layer as an early-exit, where early-exit 17 is the main branch. As shown in Fig. 3, the exits located deeper in the CNN model do not always increase inference accuracy. This means that we need to select the meaningful exits, which is also necessary to reduce the computation complexity for offloading decision. Here we choose the five circled points in Fig. 3 as the candidate earlyexits of VGG-16. The detailed information of the candidate early-exits is summarized in Table I.

C. Performance of Convergence
We first define the normalized reward for time slot k aŝ where the action x k is obtained by exhaustive searching. In Fig. 4, we plot the moving average ofQ over the last 50 time slots and training loss. As the time slot increases, the moving average ofQ and training loss gradually converge to the optimal solution, where the fluctuations are mainly due to the random sampling of training data. Specifically, the moving average of the normalized rewardQ of GRLE exceeds 0.96 and the training loss is below 0.03, which outperforms that of DROOE. This is because GRLE makes full use of MEC states for offloading decisions, while DROOE only considers the wireless channel states.

D. Performance evaluation and analysis
We test the performance of different offloading methods for 10,000 time slots in different scenarios. We define a successful task as the one that is completed within the deadline. The service success probability (SSP) is the ratio of the number of all successful tasks to the total number of tasks. The average inference accuracy is the sum of the achieved accuracy of successful tasks divided by the total number of tasks. The average throughput is the number of successful tasks divided by the sum of all time slots.
1) Performance under changing number of IoT devices: As shown in Fig. 5, the average accuracy and SSP decreases as M increases for the given ES computation resources. This is because when M is large, more tasks fail to meet their deadlines due to the limited resources of ESs. As such, the average throughput gradually reaches a plateau. Moreover, the system achieves higher throughput at τ = 10ms than that of τ = 30ms; however, its average accuracy and SSP are lower. This is because the higher task generation rate at τ = 10ms allows the system to make better use of ES's idle time to process more tasks in the same time; however, this will result in more failed tasks because of the higher occupancy of ESs and wireless channels. In addition, using early-exits it can improve average accuracy, SSP and throughput, especially when M is large. This is because a task that fails to meet the deadline using static inference can be terminated earlier to meet their application deadlines using early-exits. For example, with early-exits the average accuracy of GRLE is improved by 0.17 compared with GRL, when M = 10 and τ = 30ms. Compared with DROOE, GRLE achieves better performance because GRLE can use the full information of MEC to make offloading decisions.
2) Performance under various available capacity of ESs: In real scenarios, ES is not always completely idle at each time slot. Therefore, we assume that each ES has a stochastic available computation resource between 25% and 100% of the total computational capacity at each time slot. Compared with the average accuracy in Fig. 5(a), Fig. 6 shows that GRLE and DROOE achieve more improvement by using early-exits. For example, when M = 10 and τ = 30ms, GRLE improves the average accuracy up to 0.56, equivalent to 2.8× (i.e., 0.56/0.2) over GRL and DROOE improves the average accuracy up to 0.41, equivalent to 2.28× (i.e., 0.41/0.18) over DROO in Fig. 6, which is larger than that of 1.28× (i.e., 0.77/0.6) and 1.24× (i.e., 0.72/0.58) in Fig. 5(a). Meanwhile, GRLE  Fig. 5(a). When τ = 10ms, the gain of average accuracy thanks to the early-exits in Fig. 6 are larger than that in Fig. 5(a). This is because early-exit mechanism allows ESs with limited computation resource to terminate the computation earlier to reduce the number of failed tasks and GRLE can learn the state information of ESs better to make offloading decision.
3) Performance under various fluctuation of inference time: In addition to the variation of ES computation resource, we considered a realistic case where the inference time of each early-exit fluctuates ±25% of its measured value in Table I. In Fig. 7, GRLE achieves even higher improvement in average accuracy over other offloading methods. For example, GRLE achieves the average accuracy of 2.86× (i.e., 0.6/0.21) over GRL and 1.39× (i.e., 0.6/0.43) over DROOE when M = 10 and τ = 30ms. This is because GRLE can better learn the dynamic environment of MEC, and the early-exit mechanism ensures that more tasks are processed within the deadline. 4) Performance under imperfect channel state information: Since channel estimation is often not perfect in practical systems, in this study we include the transmission fluctuation of ±20% of the estimated values, in addition to the variation of ES computation resource and the variation of inference time. As shown in Fig. 8, GRLE achieves a higher improvement in average accuracy compared to other offloading methods. For example, in Fig. 8, GRLE achieves the average accuracy of 3.41× (i.e., 0.58/0.17) over GRL and 1.45× (i.e., 0.58/0.4) over DROOE when M = 10 and τ = 30ms. This is because GRLE can better aggregate all the information of dynamic MEC, including the uncertainty in communication time and the stochastic available capacity of ESs, and then select better early-exits to perform computation to ensure that more tasks are processed within the deadline. This further demonstrates the robust adaptability of GRLE for offloading decision-making in dynamic MEC scenarios.

VII. CONCLUSION
This paper studies computation offloading of CNN inference tasks in MEC networks. We use early-exit mechanism to address the uncertainties in communication time and available computation resource at ESs by terminating the inference earlier to meet the deadline with a slight compromise of inference accuracy. We design a reward function to trade off the inference accuracy and completion time, and formulate the CNN inference offloading problem as a maximization problem to maximize the average inference accuracy and throughput in long term. To solve this problem, we propose GRLE to make effective offloading decisions in dynamic MEC.