<?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 HOANG Bao Tin on Medium]]></title>
        <description><![CDATA[Stories by HOANG Bao Tin on Medium]]></description>
        <link>https://medium.com/@tinhb92?source=rss-69f5f36d8a7c------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/2*UJKWtFT16ltpudrkScTzDQ.jpeg</url>
            <title>Stories by HOANG Bao Tin on Medium</title>
            <link>https://medium.com/@tinhb92?source=rss-69f5f36d8a7c------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 02 Dec 2026 04:18:58 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@tinhb92/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[Differentiable Architecture Search for RNN with fastai]]></title>
            <link>https://medium.com/data-science/differentiable-architecture-search-for-rnn-with-fastai-a5e247aeb937?source=rss-69f5f36d8a7c------2</link>
            <guid isPermaLink="false">https://medium.com/p/a5e247aeb937</guid>
            <category><![CDATA[fastai]]></category>
            <category><![CDATA[nlp]]></category>
            <category><![CDATA[deep-learning]]></category>
            <category><![CDATA[automl]]></category>
            <category><![CDATA[recurrent-neural-network]]></category>
            <dc:creator><![CDATA[HOANG Bao Tin]]></dc:creator>
            <pubDate>Mon, 15 Apr 2019 12:34:13 GMT</pubDate>
            <atom:updated>2019-04-17T17:08:59.889Z</atom:updated>
            <content:encoded><![CDATA[<p>Differentiable Architecture Search (<a href="https://openreview.net/pdf?id=S1eYHoC5FX">DARTS</a>) by Hanxiao Liu et al. is an algorithm to automate the process of architecture design for neural networks. It was originally <a href="https://github.com/quark0/darts">implemented</a> in pure pytorch. This post touches on key ideas behind DARTS and shows how I reimplemented DARTS using <a href="https://github.com/fastai/fastai">fastai</a> for clarity and ease of use.</p><p>The code is at <a href="https://github.com/tinhb92/rnn_darts_fastai">https://github.com/tinhb92/rnn_darts_fastai</a>.</p><h3><strong>DARTS</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kVbmFbmwmDCbYnROzRe4pg.png" /><figcaption>Overview of DARTS — from the paper</figcaption></figure><p>Using <a href="https://github.com/salesforce/awd-lstm-lm">AWD-LSTM</a> as the backbone, the goal is to find a good rnn cell to fill in the “recurrent” part of the model (RNNModel.rnns). Different configurations are tried to eventually extract the most suitable rnn cell.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QJn4EMjjMsxo5aXlM36Y8g.png" /><figcaption>DARTS Algorithm — from the paper</figcaption></figure><p>Let’s explain the algorithm:</p><ol><li><strong>train_search: search for a good rnn cell genotype</strong></li><li><strong>train: derive the genotype, train it to convergence and evaluate on test set</strong></li></ol><p>The first part, searching for a good rnn cell genotype, consists of continuous relaxation (i.e. creating a mixed operation) and alternatively updating architecture alpha and weights theta using gradient descent</p><p>Instead of using only <em>1 operation</em> (tanh, sigmoid …) at a node in the rnn cell, we apply several operations and get a weightage sum of these. In the experiment, there are <em>5 operations</em>: none, tanh, relu, sigmoid, identity. The weights given to each of these <em>5 operations</em> at each node are learnable parameters.</p><p>In Pytorch, we use <em>torch.rand()</em> to initialize this and set <em>requires_grad = True</em>. The author call this <strong>alpha/architecture parameters</strong> to distinguish from <strong>theta/normal parameters</strong> of the network. Updating theta requires the usual forward and backward passes.</p><p>The gradient for alpha is described in Equation (7) of the paper:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/751/1*0I9UCSFTwa2YHvlMsAUjCQ.png" /><figcaption>Eq (7) in paper: Gradient for alpha</figcaption></figure><p>ω’ denotes the weights for a one-step forward model.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/377/1*YA5rduIgVYUxZiVQU4jETg.png" /><figcaption>ω’</figcaption></figure><p>The first part of Eq(7) is calculated with 1 forward and 1 backward pass on validation data using ω’. The 2nd part of Eq(7) is calculated using finite difference approximation:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aZsy7JYYpp3aZgq0XTjCaw.png" /><figcaption>Finite difference approximation</figcaption></figure><p>ω+ and ω- are defined as:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*pDfaI3UjMVNELfyGg1XTXw.png" /><figcaption>ω+ and ω-</figcaption></figure><p>Evaluating the finite difference requires only 2 forward passes for the weights and 2 backward passes for alpha. The complexity is reduced from O(|alpha||theta|) to O(|alpha| + |theta|).</p><p>After training, we select the operation with highest probability (ignore none) to convert the continuous relaxation to 1 discrete specification of the cell. This genotype is then trained to convergence and evaluated on test set</p><h3><strong>Implement with fastai</strong></h3><p>The 2 phases, <strong>train_seach</strong> and <strong>train</strong>, have their training loops coded in pure pytorch in the original implementation. This is fine if the loop is not too complicated but it can get messy quickly and make the code hard to decipher. fastai has developed a <a href="https://t.co/zPGakJihrZ">callbacks</a> <a href="https://www.youtube.com/watch?v=roc-dOSeehM&amp;t=6s">system</a> to pigeonhole components of the training loop into separate parts for clarity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0a1044bc1ad4b31f0ce68a2a816287f0/href">https://medium.com/media/0a1044bc1ad4b31f0ce68a2a816287f0/href</a></iframe><p>You can specify what to do at each stage of training: on_train_begin, on_epoch_begin, on_batch_begin, on_loss_begin … and so on without cluttering the code. Find out more by reading the <a href="https://docs.fast.ai/callback.html">docs</a>!</p><p>Following the original implementation, I also have the DartsCell, DartsRnn modules (for train phase) and their respective subclasses DartsCellSearch, DartsRnnSearch (for train_search phase). The difference is other interesting add-ons are put into their own callbacks for ease of understanding.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b4d3ef3c2b67001c2a716a1a168a0067/href">https://medium.com/media/b4d3ef3c2b67001c2a716a1a168a0067/href</a></iframe><p>The big <strong>train_search</strong> loop above is replaced by a learner with callbacks where you can quickly see an overview of what is required.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/191baacc30663eea010d71d684cae5ef/href">https://medium.com/media/191baacc30663eea010d71d684cae5ef/href</a></iframe><p>Train_search has its ArchParamUpdate callback and all the logic of updating alpha/architecture parameters mentioned above is stored there.<br>The optimizer (arch_opt) for alpha (arch_p in the code) is part of this callback.</p><p>Similarly, train phase has a separate callback to trigger ASGD optimizer and conditions for trigger is in that callback, separate from the training loop. Other tasks that <strong>train</strong> and <strong>train_search</strong> share such as <em>regularization</em>, <em>hidden initialization</em>, <em>save</em> and <em>resume</em> training also have their own callbacks.</p><p>For more details, you can check out my <a href="https://github.com/tinhb92/rnn_darts_fastai">code</a> and run the notebooks provided.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a5e247aeb937" width="1" height="1" alt=""><hr><p><a href="https://medium.com/data-science/differentiable-architecture-search-for-rnn-with-fastai-a5e247aeb937">Differentiable Architecture Search for RNN with fastai</a> was originally published in <a href="https://medium.com/data-science">TDS Archive</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>