<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Surat Teerapittayanon on Medium]]></title>
        <description><![CDATA[Stories by Surat Teerapittayanon on Medium]]></description>
        <link>https://medium.com/@steerapi?source=rss-d7f7bfb25faf------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ehsuYDJUjCu1azjhuD3EDA.jpeg</url>
            <title>Stories by Surat Teerapittayanon on Medium</title>
            <link>https://medium.com/@steerapi?source=rss-d7f7bfb25faf------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 30 Nov 2026 08:31:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@steerapi/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Fast Inference on IDN with Multiple Size Models]]></title>
            <link>https://medium.com/chainintel/fast-inference-on-idn-with-multiple-size-models-8a895965f92d?source=rss-d7f7bfb25faf------2</link>
            <guid isPermaLink="false">https://medium.com/p/8a895965f92d</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[idn]]></category>
            <dc:creator><![CDATA[Surat Teerapittayanon]]></dc:creator>
            <pubDate>Wed, 14 Nov 2018 15:01:01 GMT</pubDate>
            <atom:updated>2018-11-14T15:01:01.353Z</atom:updated>
            <content:encoded><![CDATA[<p>We have seen in <a href="https://blog.chainintel.com/fast-inference-for-deep-learning-models-f29a1ade2e03">Fast Inference for Deep Learning Models</a> that we can augment branches on the model to allow samples to exit early. In this article, we will discuss another way to enable fast inference with your DNN model in a distributed p2p network setting of IDN.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BfRpB8rDeGSGsFgu" /><figcaption>“plasma ball digital wallpaper” by <a href="https://unsplash.com/@joshriemer?utm_source=medium&amp;utm_medium=referral">Josh Riemer</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>In a distributed p2p network setting, a computation can be done on different peers at the same time in parallel. How can we make use of this benefit of the distributed p2p network setting for fast inference? One may try to divide up the model in various ways to try to reduce the computation of each piece. Depending on how one divides up the model, the amount of communication between different piece will vary.</p><p>In this article, we are exploring a different way. Instead of dividing up the model, we make a copy of it and let each peer run them at the same time. Just making a copy of the model will not help with our cause to lower inference time as each model will still do the same amount of computation as the original model.</p><p>In order to help with fast inference, we need to make some of the copies execute faster than the others so that we can get the result of the faster model and exit the inference early, lowering the overall inference time.</p><p>In order to do that, we create an overlay model where a Bernoulli random variable (which takes the value 1 with probability p and the value 0 with probability 1- p) is associated with each neuron and filter of the original model.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1123a5574f093159f2202a5abde4ff28/href">https://medium.com/media/1123a5574f093159f2202a5abde4ff28/href</a></iframe><p>To generate a smaller model, we just specify the parameter p. Those random variables for each neuron or filter are then drawn with the specified parameter p. The smaller p means that less random variables get a value of 1 and the resulting model has a smaller size. The larger p means that more random variables get a value of 1 and the resulting model will have a larger size.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/580/0*fOmkgALtPsqo0Gd9" /></figure><p>The figure shows the result of 4 different size models generated from the original AlexNet-style model with p=0.2, 0.4, 0.8 and 1.0.</p><p>Here is the characteristics of these generated models:<br>- AlexNet(p=1.0) (132 MFLOPs, 3.7M params, 15MB)<br>- AlexNet(p=0.8) (86 MFLOPs, 2.4M params, 9.6MB)<br>- AlexNet(p=0.4) (24 MFLOPs, 0.7M params, 2.8MB)<br>- AlexNet(p=0.2) (5 MFLOPs, 0.2M params, 0.8MB)</p><p>Notice that AlexNet(p=1.0) is the original model as p=1.0 will retain all neurons and filters of the original model.</p><p>These models are then jointly trained on FashionMNIST dataset. We then use those models to run inference on 10,000 test samples of FashionMNIST. For each test sample, all 4 models execute the inference in parallel. Confidence level is evaluated as the result from each model becomes available and if the confidence level is above a certain threshold for that sample, it is exited. The optimization scheme as presented in <em>Finding the Thresholds for BranchyNet Early Exits</em> is used to find a threshold for each model’s result. The star in red is the accuracy and average inference time per sample in microseconds using the found thresholds of 0.85, 0.79 and 0.72 for AlexNet(p=0.2), AlexNet(p=0.4) and AlexNet(p=0.8), respectively. Comparing this to the original AlexNet model, we achieve about 7x speed up in average inference time.</p><p>We will be releasing the pytorch library to generate and train different size models from your original model. Please stay tuned! As always, please let us know what you think! Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8a895965f92d" width="1" height="1" alt=""><hr><p><a href="https://medium.com/chainintel/fast-inference-on-idn-with-multiple-size-models-8a895965f92d">Fast Inference on IDN with Multiple Size Models</a> was originally published in <a href="https://medium.com/chainintel">ChainIntel</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Finding the Thresholds for Fast Inference]]></title>
            <link>https://medium.com/chainintel/finding-the-thresholds-for-fast-inference-ff96797fda7?source=rss-d7f7bfb25faf------2</link>
            <guid isPermaLink="false">https://medium.com/p/ff96797fda7</guid>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[deep-learning]]></category>
            <dc:creator><![CDATA[Surat Teerapittayanon]]></dc:creator>
            <pubDate>Mon, 12 Nov 2018 15:01:02 GMT</pubDate>
            <atom:updated>2018-11-12T15:01:02.151Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*1JYsGuCpWjceYCcO" /><figcaption>“closeup photo of gray tree branch with leaves and snow” by <a href="https://unsplash.com/@alisaanton?utm_source=medium&amp;utm_medium=referral">Alisa Anton</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h3>Finding the Thresholds for BranchyNet Early Exits</h3><p>Previously, we discussed augmenting deep neural network models for fast inference with branches in <a href="https://blog.chainintel.com/fast-inference-for-deep-learning-models-f29a1ade2e03">Fast Inference for Deep Learning Models</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1019/0*xMOn6IeDdFIT88Rv" /></figure><p>To recap, one can add exit branches to existing models to exit the inference execution early, resulting in fast inference. In the figure shown, the main branch is the original model and the early exit branch is the additional augmented layer to the original model.</p><p>To do fast inference with this augmented model, we pass a sample through to Exit 1 and get a confidence value. To decide whether a sample should exit at a branch, we look at the confidence of the softmax output of that branch, i.e.,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/322/0*hbVlrD2Ox_XJSnBx.png" /></figure><p>If the confidence value is high enough according to a set threshold, we exit the sample, otherwise the sample continues up to the main branch exit and the final result is the average of the outputs from both exits.</p><p>If the confidence is higher than a threshold T, we exit the inference. The issue remaining is how to pick this threshold or a set of thresholds when there are multiple augmented branches. In this article, we will discuss a method to find such threshold or set of thresholds.</p><p>The goal for us is to minimize the inaccuracy of an exit branch while maintaining the overall accuracy of the augmented model.</p><p>Let E be the number of exits at a branch and O of which is predicted incorrectly by that branch. Given a set of N test samples and I of which is predicted incorrectly by the augmented model, we then want to minimize</p><p>(O / E) + (I / N) * (1 - E / N)</p><p>We want to exit samples as early as we can in order to achieve fast inference, so we start the optimization with the earlier branches first, find the threshold for that branch, freeze it and then optimize the later branches.</p><p>With this, we have the following result.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/581/0*OLOGL444OHrb1I2D" /></figure><p>The figure above shows the result of this optimization on <a href="https://en.wikipedia.org/wiki/AlexNet">AlexNet</a>-style CNN model with 8 layers 2 augmented branches on <a href="https://github.com/zalandoresearch/fashion-mnist">FashionMNIST</a> dataset. The blue brute-force curve is obtained by trying many different set of thresholds. The red star is our resulting set of thresholds of 0.98 for the first branch and 0.96 for the second branch. The purple Original dot is the original model before branch augmentation. With branch augmentation and a way of finding exit thresholds, we can cut the average inference time in half.</p><p>We will be releasing a Pytorch library for everyone to augment your model and optimize for the suitable set of thresholds soon. Please stay tuned and let us know what you think or if you have ideas to share. Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=ff96797fda7" width="1" height="1" alt=""><hr><p><a href="https://medium.com/chainintel/finding-the-thresholds-for-fast-inference-ff96797fda7">Finding the Thresholds for Fast Inference</a> was originally published in <a href="https://medium.com/chainintel">ChainIntel</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[IDN: Intelligence Delivery Network]]></title>
            <link>https://medium.com/chainintel/idn-intelligence-delivery-network-491986a34362?source=rss-d7f7bfb25faf------2</link>
            <guid isPermaLink="false">https://medium.com/p/491986a34362</guid>
            <category><![CDATA[neural-networks]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <category><![CDATA[computer-science]]></category>
            <category><![CDATA[machine-learning]]></category>
            <dc:creator><![CDATA[Surat Teerapittayanon]]></dc:creator>
            <pubDate>Fri, 09 Nov 2018 05:47:30 GMT</pubDate>
            <atom:updated>2018-11-09T05:47:30.844Z</atom:updated>
            <content:encoded><![CDATA[<p>Moving the execution of deep neural networks (DNNs) closer to end devices, enabling <strong>fast</strong>, <strong>robust</strong> and <strong>scalable </strong>DNN inference.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*GcCFBBzVuG06qXJr" /><figcaption>“photo of outer space” by <a href="https://unsplash.com/@nasa?utm_source=medium&amp;utm_medium=referral">NASA</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>The applications of deep neural networks (DNN) have experienced unprecedented growth in recent years. But there is a problem: the inference computations of large DNN models are too intensive to run on a single end device. To solve this problem, this article introduces a novel platform called Intelligence Distribution Network (IDN) that is specifically designed to make DNN inference <strong>fast</strong>, <strong>robust</strong> and <strong>scalable</strong>. With IDN, it is possible to spread the inference computation over a distributed computing hierarchy of multiple devices, edges, and the cloud, allowing the application to support larger models and improve fault tolerance.</p><blockquote>Web developers can integrate intelligence into their web applications with ease and without being limited by compute resources.</blockquote><figure><a href="https://en.wikipedia.org/wiki/Peer-to-peer"><img alt="" src="https://cdn-images-1.medium.com/max/887/1*rSDnpTZJWbbO2CBs8j6ceg.png" /></a><figcaption>Image from <a href="https://en.wikipedia.org/wiki/Peer-to-peer">https://en.wikipedia.org/wiki/Peer-to-peer</a></figcaption></figure><p>At its core, IDN is a distributed peer-to-peer network of computing devices that moves the execution of deep neural network inference closer to the end devices. By leveraging and combining the capabilities of spare computing resources of nearby devices, edges, and the cloud, IDN provides high-performance low-latency inference to meet the growing demand from Artificial Intelligence (AI) applications.</p><p>IDN’s peer-to-peer network transparently distributes and routes the model execution from the target inference application to nearby participating nodes, which in turn cooperate to distribute the load in order to render a response quickly and efficiently. By shifting the execution of deep learning inference from the cloud to the edge and end devices, everyone with spare computing resources can become a node in the IDN network and therefore, a participant in the our society’s transition towards Artificial Intelligence (AI) by hosting DNN models and performing inference computation. By moving intelligence algorithms closer to the end user and making it more accessible, IDN lives up to its name as an Intelligence Distribution Network.</p><blockquote>Website visitors can participate and share compute resources for DNN inference.</blockquote><p>Here is how IDN achieves its core benefits: making inference 1) fast, 2) robust, and 3) scalable.</p><p>IDN enables <strong>fast inference </strong>by moving the execution closer to the end devices running the AI applications. Beyond this gain from latency reduction, IDN can further speedup inference by augmenting the target model with branches via BranchyNet. BranchyNet augments DNN models with branches at various points in the network to enable fast inference by terminating the execution early when enough confidence is accumulated, therefore making additional computation unnecessary (see <a href="https://blog.chainintel.com/fast-inference-for-deep-learning-models-f29a1ade2e03">Fast Inference for Deep Learning Models</a> for more details).</p><p>IDN enables <strong>robust inference</strong> by sending inference requests to multiple peers simultaneously in parallel. Further, when a peer is known to be inactive, the inference request can be rerouted to another available peer automatically. Because of this built-in redundancy, if any request or response is lost or corrupted, the inference result can still be obtained from other nodes. This enables robust and reliable inference for your applications.</p><p>IDN enables <strong>scalable inference </strong>by<strong> </strong>being able to<strong> </strong>send inference requests from the end device to unlimited number of nearby peers. Any available peer near your end device can be a host for your application’s inference computations. By not having every inference request hitting your server, IDN enables improved scalability for your applications.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*I5ssGyXQs1KZ9VDPEc51GA.png" /></figure><p><strong>Inference on IDN<br></strong>1) Computation is distributed across multiple devices over peer <strong>devices</strong>, <strong>edges</strong> and the <strong>cloud<br></strong>2) Peers can execute computation in <strong>parallel<br></strong>3) There are <strong>multiple </strong>output<strong> </strong>(<strong>exit</strong>)<strong> </strong>points<br>4) Each output returns a <strong>confidence value<br></strong>5) Each output can be <strong>progressively enhanced</strong> by combining it with previous output<br>6) The inference can <strong>terminate early</strong> if the output has high enough confidence</p><p>Below is an example of how you can use IDN to move the execution of your DNN models closer to end devices to realize these important gains.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3cf283fe7dc1a825243cf7ec5f92caaf/href">https://medium.com/media/3cf283fe7dc1a825243cf7ec5f92caaf/href</a></iframe><p>Consider a scenario in which you define 1) a model descriptor describing the identity of the model, 2) the path where the model can be accessed, and 3) the type of the model. Here, we use <a href="https://ipfs.io/">ipfs</a> to host our model, the type of the model is exported from <a href="https://pytorch.org/">torch</a>, and we specify that the model should be run using NVIDIA CUDA GPU. In addition to torchjs/cuda model type, other model types can be used as well, including <a href="https://github.com/mil-tokyo/webdnn">WebDNN</a>, which allows nodes to execute the inference computation entirely on the browsers.</p><p>With IDN, everyone will be able to tap into the power of Artificial Intelligence via their browsers. Web developers can integrate intelligence into their web applications with ease without being limited by compute resources. Website visitors can participate and share compute resources for DNN inference.</p><p>Once the model is defined, IDN sends initModel requests to peers, which triggers them to download the model and prepare it for inference requests. After the model is initialized, we can now send inference requests to the peers and wait for the response event to come back. The response event consists of outputs, the confidences for those outputs, and a finish callback function to terminate the ongoing computation early.</p><p>Below is an example of videos processed on IDN with the ResNet18 model. The video is a 224-by-224 4s-long 30fps video passed through ResNet18 model before each frame was rendered and displayed.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FkmkBiFK7JCo%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DkmkBiFK7JCo&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FkmkBiFK7JCo%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/21753cee9af67a7dfc651e633c8ae8e3/href">https://medium.com/media/21753cee9af67a7dfc651e633c8ae8e3/href</a></iframe><p>As the example video demonstrates, we see initial promising results of inference execution using IDN. With 3 nearby peers, we see a comparable result of executing the inference locally.</p><p>This post is edited by our editor in chief Marcus Comiter.</p><p>If you have comments or ideas, please let us know below. Please tell us how this could be useful in your project or how you could use it. We are writing more content on IDN and will be releasing an IDN library for everyone to experiment with in the near future. Please stay tuned. Thank you!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=491986a34362" width="1" height="1" alt=""><hr><p><a href="https://medium.com/chainintel/idn-intelligence-delivery-network-491986a34362">IDN: Intelligence Delivery Network</a> was originally published in <a href="https://medium.com/chainintel">ChainIntel</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TorchJS: Running PyTorch Models in NodeJS]]></title>
            <link>https://medium.com/chainintel/torchjs-running-pytorch-models-in-nodejs-348022b0d291?source=rss-d7f7bfb25faf------2</link>
            <guid isPermaLink="false">https://medium.com/p/348022b0d291</guid>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[pytorch]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Surat Teerapittayanon]]></dc:creator>
            <pubDate>Thu, 08 Nov 2018 05:04:26 GMT</pubDate>
            <atom:updated>2018-11-08T05:04:26.953Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7VH5J_3AFJjg5PfI" /><figcaption>“fish-eye photography of city” by <a href="https://unsplash.com/@serjosoza?utm_source=medium&amp;utm_medium=referral">sergio souza</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><p>A New Way to deploy Pytorch Deep Learning Model.</p><p>With the recent release of <a href="https://pytorch.org/">PyTorch</a> 1.0 and <a href="https://pytorch.org/docs/master/jit.html">Torch Script</a>, we now have an easy way to export and run a PyTorch model in C++. This will help shorten the time to production of DNN models tremendously.</p><p>On one hand, there is no denied that Python is one of the top language for machine learning due to its ease of use and powerful libraries. One of those includes PyTorch which has made the development and experimentation of DNN models easy.</p><p>On the other hand, NodeJS has been widely used to serve web API requests, due to its vastly available web libraries, ease of setup and use and asynchronous performance.</p><p>This post will discuss how one can export and run a PyTorch model with NodeJS. This could be useful when you have a NodeJS server serving APIs which run DNN inference using the PyTorch models that one has just developed in Python.</p><p>Let’s get started. First, we need to install the necessary tools:</p><blockquote>sudo apt install g++ cmake unzip</blockquote><p>Once the tools are installed, we can now install the <a href="https://www.npmjs.com/package/@idn/torchjs">@idn/torchjs</a> package:</p><blockquote>npm install @idn/torchjs</blockquote><p>Once the package is installed, we now need to export a model from PyTorch. Below is an example code to export a PyTorch model. In this case, we export the pretrained ResNet18 from the torchvision package.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b8db272bd34cb05155098dc92175b8a4/href">https://medium.com/media/b8db272bd34cb05155098dc92175b8a4/href</a></iframe><p>Once the model is exported, we can now load and run it in NodeJS.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e875b0c63747888b5b21dac4782e6499/href">https://medium.com/media/e875b0c63747888b5b21dac4782e6499/href</a></iframe><p>If you try this on machines without CUDA, please comment out line 8 to run the model on CPU.</p><p>This post is edited by Marcus Comiter.</p><p>This post is inspired by <a href="http://blog.christianperone.com/2018/10/pytorch-1-0-tracing-jit-and-libtorch-c-api-to-integrate-pytorch-into-nodejs/">PyTorch 1.0 tracing JIT and LibTorch C++ API to integrate PyTorch into NodeJS</a> by Christian S. Perone. You can visit the page to read more about the detail.</p><p>Please checkout <a href="https://www.npmjs.com/package/@idn/torchjs">@idn/torchjs</a> npm module and let us know what you think! Thank you for reading!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=348022b0d291" width="1" height="1" alt=""><hr><p><a href="https://medium.com/chainintel/torchjs-running-pytorch-models-in-nodejs-348022b0d291">TorchJS: Running PyTorch Models in NodeJS</a> was originally published in <a href="https://medium.com/chainintel">ChainIntel</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fast Inference for Deep Learning Models]]></title>
            <link>https://medium.com/chainintel/fast-inference-for-deep-learning-models-f29a1ade2e03?source=rss-d7f7bfb25faf------2</link>
            <guid isPermaLink="false">https://medium.com/p/f29a1ade2e03</guid>
            <category><![CDATA[machine-learning]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <category><![CDATA[distributed-computing]]></category>
            <category><![CDATA[artificial-intelligence]]></category>
            <dc:creator><![CDATA[Surat Teerapittayanon]]></dc:creator>
            <pubDate>Sun, 01 Oct 2017 05:33:49 GMT</pubDate>
            <atom:updated>2017-10-01T06:01:09.716Z</atom:updated>
            <content:encoded><![CDATA[<p>Neural networks have shown to provide significant improvement in prediction accuracy by stacking multiple hidden layers, hence we see the trend towards more and more usage of deep learning. The ImageNet challenge exemplifies this trend towards deep neural networks, from Alex-Net ( 8 layers ), VGG-Net ( 19 layers ) to ResNet ( 152-layers ) within a period of 4 years. Such improvement in accuracy by increasing the depth of neural network comes with the cost of additional execution time and power consumption.</p><p><strong>Even if we disregard the additional execution time during training of the neural network, overlooking this addition in execution time during inference could result in negative user-experience. Improving inference can be envisioned as how accurately we can infer and how quickly can we infer.</strong></p><p>Deeper layered networks help to improve the former argument for inference, while adding negative impact for the later. This article elaborates the idea of BranchyNet for fast inference through early-exits.</p><p>Let’s say we participate in an experimental math competition. We are given 3 mathematical problems to solve, each with an increasing level of difficulty.</p><p><strong>Problem 1: <em>Finding a square root of 4. (difficulty x)<br></em>Problem 2:<em> Finding a square root of 1000. (difficulty y)<br></em>Problem 3: <em>Finding a square root of 13371337.</em> (<em>difficulty z)</em></strong></p><p>For simplicity we assume that solving a problem of difficulty x takes t_x seconds, of difficulty y takes t_y seconds and of difficulty z takes t_z seconds and t_x&lt;t_y&lt;t_z. The total time taken for human (t_h) to solve the entire set of mathematical problems would be the summation of the difficulty of the problems in terms of time (t_x+t_y+t_z).</p><p>Now, we train a deep neural network to participate in this experimental math competition as well. The neural network has to be designed such that it can solve the hardest problem of difficulty z (assuming it also take t_z seconds). The time taken for the neural network to solve each problem is equal to the time required to complete execution through all the layers of the neural network. The total time taken for the neural network (t_n)would be equal to the number of mathematical problems multiplied by the time taken to solve each problem (3t_z).</p><p>Since the time required by the neural network (3t_z) is greater than the time taken by human (t_x+t_y+t_z) to solve the same set of mathematical problems, human will be the winner in this case.</p><p>The above example is purely based on assumptions, it may not necessarily be true in the real world given how fast machines can compute compare to human brain. What we are trying to convey with the help of the math competition example is that the deep neural network performs the same amount of work to predict any result regardless of the input and the total time is directly proportional to the number of layers. Each layer extracts different high-level features to aid in prediction of the input label.</p><p><strong>Confidence of predicting an input label is unevenly distributed between layers depending upon the features extracted. </strong>For instance, in digit recognition, certain features such as no curved lines would provide high confidence that the digit we are trying to predict is 1,4 or 7 and not 0, 2, 3, 5, 6, 8, or 9.<strong> Even though the neural network is highly confident about the prediction label of the input at earlier layers of the network, it still has to process through all the layers of the network before predicting the label due to its current structure. BranchyNet relaxes the rigid structure of the neural network by allowing early exits for high confident predictions.</strong></p><p>The BranchyNet architecture comprises of a single entry point and multiple exit points. An entry point can be viewed as an input layer and exit points can be viewed as an output layer. A branch is a subset of contiguous layers, which do not overlap with other branches, followed by an exit point. The original neural network can be viewed as a main branch and layers branching out from the main branch can be viewed as side branches. Each branch must resolve to an exit and can be numbered increasingly based on its distance from the entry point.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/938/1*i4f7gse6-Vw5sVCePsYyig.png" /><figcaption>Figure 1. BranchyNet with 2 branches added to AlexNet.</figcaption></figure><p>The above figure depicts BranchyNet with 2 side branches added to the AlexNet main branch. The boxes indicate the exit points, we have 2 early exits and one exit of the main AlexNet branch. BranchyNet can be used for fast inference when the input label is predicted at earlier layers of the neural network with high confidence. If the classifier at the exit point has sufficient confidence about the label of an input sample, the sample can exit and no further computation on the input sample through deeper layers is needed. <strong>An entropy is used to determine the confidence of a classifier at an exit point for the sample input.</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/378/1*d7g0SnfzCVAxBdJKISRkBA.gif" /></figure><p>where y is a vector containing predicted probabilities for all possible class labels.</p><p>Predicted probability for a class label is the measure of the likelihood that the input can be classified as the class label. A simple example would be classifying a digit number for the class labels ( 1, 2, 3, 4, 5, 6, 7, 8 , 9, 0 ). The predicted probability vector [ 0.05, 0.05, 0.1, 0.05, 0.05, 0.1, 0.45, 0.05, 0.05, 0.05 ] corresponds to the predicted probability for each class label ( 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 ).</p><p><strong>Entropy measures the amount of information conveyed in the predicted probability vector of each exit branch. The higher the entropy the more information the neural network has about a particular input. The more information the neural network has the more confidence it is about that particular input.</strong></p><p>During inference time, an entropy at an exit point is compared to the corresponding threshold set for that particular exit point. If the entropy is lesser than the threshold value, then the sample input is allowed to exit at the particular exit point. A high-level execution of the inference phase of the BranchyNet can be viewed as follows. We have a vector T denoting threshold for each exit, i.e., T[1] is the threshold for exit 1. The inference phase begins with the lowest exit points. The input sample is fed through the branch of the lowest exit point and the entropy is compared to the threshold value. If the entropy is lower than the threshold value, then the sample input can exit the network at that exit point. If not the next lowest exit point is chosen and the procedure is continued similarly until the highest or the final exit point is reached.</p><p>An important hyperparameter apart from the threshold in BranchyNet, is the weights in joint optimization during the training of the BranchyNet. BranchyNet involves usage of a loss function as an optimization objective, i.e., for classification specific task, we can use softmax cross entropy loss function. Each exit branch is designed to minimize this loss function. To train the entire BranchyNet, we form a joint optimization problem with the weighted sum of the loss functions on each exit branch. The earlier branches helps increasing the accuracy of the later branches due to the added regularization which prevents over-fitting. Giving more weight to the earlier branches allows the earlier layers to learn more discriminative features and allows more samples to exit the network early; thus, reducing the average time taken by a network to infer a label for an input sample.</p><p>The BranchyNet architecture synergizes well with the distributed execution of artificial intelligence models for inference. Since each branch (subset of layers) can be executed independently, the branches can be distributed on different nodes to execute in parallel. In case of an early exit, the remaining execution of the branches could be deterred by communication between nodes. This distributed nature of BranchyNet allows data scientists to deploy deeper models with very little trade off in time. Deeper models would enable more sophisticated feature extraction to solve more complex problems using Artificial Intelligence.</p><p>Let’s look at an example of how a 10-layered deep BranchyNet would be executed. The 10-layered deep BranchyNet has 4 different branches, 3 side branches and 1 main branch. We consider 4 nodes for executing these 4 different branches for simplicity. Node 1 executes the main branch till layer 3 and then communicates the output of layer 3 to Node 2. Node 1 in parallel continues executing the branch with exit 1. Node 2 executes the main branch from layer 4. Similarly Node 2 would communicate the output of layer 6 to Node 3, and in parallel continue to execute the branch with the exit 2. If a node can exit early, i.e., high confidence is obtained by a node at an exit, the result would immediately be communicated back to the client, thereby deterring the further execution of the BranchyNet and resulting in a faster response time. Early exit for higher confidence inputs and parallel execution of branches contribute to heavy reduction of the inference time. The execution time of the layers could further be reduced by parallelizing the execution of each neural network layer itself.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Be6yrBLqYzIUQkbgT8u6JA.png" /><figcaption>Figure 2. Execution of 10-layered BranchyNet.</figcaption></figure><p>Heavy reduction in inference time of Artificial Intelligence models increases their adoption for more real-time prediction tasks. Inference using BranchyNet could utilize paired execution by local nodes (Nodes on which an application is running, can be a Computer, Mobile or IoT device) and remote network nodes. Local nodes would execute the lowest branches and would predict an output locally in case of early exit, the remote nodes would begin execution of the latter branches simultaneously as the local node, thereby reducing time of inference in case of no local early exit. The time taken in case of no early exit locally would be the difference between execution time required for the layers of the exit branch and execution time of layers on the local node.</p><p>If you are interested to learn more about BranchyNet, the research paper is available at <a href="https://arxiv.org/abs/1709.01686">https://arxiv.org/abs/1709.01686</a>.</p><p>Please let me know if you have any feedback or suggestion on the topic. I am happy to discuss.</p><p>I am working on a tool for developers to easily augment a trained deep neural network model with branches for fast inference and will share about the progress in a later post.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f29a1ade2e03" width="1" height="1" alt=""><hr><p><a href="https://medium.com/chainintel/fast-inference-for-deep-learning-models-f29a1ade2e03">Fast Inference for Deep Learning Models</a> was originally published in <a href="https://medium.com/chainintel">ChainIntel</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>