<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://abhi-glitchhg.github.io/feed.xml" rel="self" type="application/atom+xml" /><link href="https://abhi-glitchhg.github.io/" rel="alternate" type="text/html" /><updated>2026-06-20T04:07:18-07:00</updated><id>https://abhi-glitchhg.github.io/feed.xml</id><title type="html">Abhijit | अभिजित</title><subtitle>personal description</subtitle><author><name>Abhijit Deo</name><email>f20190041@goa.bits-pilani.ac.in</email></author><entry><title type="html">DropPath</title><link href="https://abhi-glitchhg.github.io/posts/2024/10/droppath_explained/" rel="alternate" type="text/html" title="DropPath" /><published>2024-10-27T00:00:00-07:00</published><updated>2024-10-27T00:00:00-07:00</updated><id>https://abhi-glitchhg.github.io/posts/2024/10/droppath_explained</id><content type="html" xml:base="https://abhi-glitchhg.github.io/posts/2024/10/droppath_explained/"><![CDATA[<p>While working on my latest project, I had to dive deep into the huggingface’s <code class="language-plaintext highlighter-rouge">transformers</code> codebase. In the process, I ventured into Swin Transformer territory—an innovative vision transformer designed for hierarchical feature representation. It was here that I noticed something that piqued my curiosity. Below is the code block that initially caught my attention:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code>
<span class="k">class</span> <span class="nc">SwinStage</span><span class="p">(</span><span class="n">nn</span><span class="p">.</span><span class="n">Module</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">config</span><span class="p">,</span> <span class="n">dim</span><span class="p">,</span> <span class="n">input_resolution</span><span class="p">,</span> <span class="n">depth</span><span class="p">,</span> <span class="n">num_heads</span><span class="p">,</span> <span class="n">drop_path</span><span class="p">,</span> <span class="n">downsample</span><span class="p">):</span>
        <span class="nb">super</span><span class="p">().</span><span class="n">__init__</span><span class="p">()</span>
        <span class="bp">self</span><span class="p">.</span><span class="n">config</span> <span class="o">=</span> <span class="n">config</span>
        <span class="bp">self</span><span class="p">.</span><span class="n">dim</span> <span class="o">=</span> <span class="n">dim</span>
        <span class="bp">self</span><span class="p">.</span><span class="n">blocks</span> <span class="o">=</span> <span class="n">nn</span><span class="p">.</span><span class="n">ModuleList</span><span class="p">(</span>
            <span class="p">[</span>
                <span class="n">SwinLayer</span><span class="p">(</span>
                    <span class="n">config</span><span class="o">=</span><span class="n">config</span><span class="p">,</span>
                    <span class="n">dim</span><span class="o">=</span><span class="n">dim</span><span class="p">,</span>
                    <span class="n">input_resolution</span><span class="o">=</span><span class="n">input_resolution</span><span class="p">,</span>
                    <span class="n">num_heads</span><span class="o">=</span><span class="n">num_heads</span><span class="p">,</span>
                    <span class="n">shift_size</span><span class="o">=</span><span class="mi">0</span> <span class="k">if</span> <span class="p">(</span><span class="n">i</span> <span class="o">%</span> <span class="mi">2</span> <span class="o">==</span> <span class="mi">0</span><span class="p">)</span> <span class="k">else</span> <span class="n">config</span><span class="p">.</span><span class="n">window_size</span> <span class="o">//</span> <span class="mi">2</span><span class="p">,</span>
                <span class="p">)</span>
                <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="n">depth</span><span class="p">)</span>
            <span class="p">]</span>
        <span class="p">)</span>

        <span class="c1"># patch merging layer
</span>        <span class="k">if</span> <span class="n">downsample</span> <span class="ow">is</span> <span class="ow">not</span> <span class="bp">None</span><span class="p">:</span>
            <span class="bp">self</span><span class="p">.</span><span class="n">downsample</span> <span class="o">=</span> <span class="n">downsample</span><span class="p">(</span><span class="n">input_resolution</span><span class="p">,</span> <span class="n">dim</span><span class="o">=</span><span class="n">dim</span><span class="p">,</span> <span class="n">norm_layer</span><span class="o">=</span><span class="n">nn</span><span class="p">.</span><span class="n">LayerNorm</span><span class="p">)</span>
        <span class="k">else</span><span class="p">:</span>
            <span class="bp">self</span><span class="p">.</span><span class="n">downsample</span> <span class="o">=</span> <span class="bp">None</span>

        <span class="bp">self</span><span class="p">.</span><span class="n">pointing</span> <span class="o">=</span> <span class="bp">False</span>


</code></pre></div></div>

<p>While digging deep into the Swin Transformer code in the <code class="language-plaintext highlighter-rouge">transformers</code> repository, I stumbled upon an intriguing discovery—thanks to a handy tool in VS Code. The tool flagged an unused <code class="language-plaintext highlighter-rouge">drop_path</code> argument in the constructor. This was unusual enough to prompt further investigation.</p>

<p>I opened up a <a href="https://github.com/huggingface/transformers/pull/34291/">pull request</a> in transformers repository mentioning the same.</p>

<p>At that moment, I realized I didn’t have a solid grasp of what Drop Path actually does. I was familiar with dropout, but Drop Path? Not quite. And so began my deep dive into Drop Path, resulting in this blog post.</p>

<h1 id="lets-first-understand-dropout">Let’s First understand DropOut</h1>

<p>Dropout is a regularization technique that was introduced by Geoffrey Hinton et al. in <a href="https://arxiv.org/abs/1207.0580">Improving neural networks by preventing co-adaptation of feature detectors</a> The basic idea is to randomly change some activations to zero at training time. I would like to quote the abstract of the paper here.</p>

<blockquote>
  <p>When a large feedforward neural network is trained on a small training set,
it typically performs poorly on held-out test data. This “overfitting” is greatly
reduced by randomly omitting half of the feature detectors on each training
case. This prevents complex co-adaptations in which a feature detector is only
helpful in the context of several other specific feature detectors. Instead, each
neuron learns to detect a feature that is generally helpful for producing the
correct answer given the combinatorially large variety of internal contexts in
which it must operate. Random “dropout” gives big improvements on many
benchmark tasks and sets new records for speech and object recognition.</p>
</blockquote>

<p>In other words randomly dropping out activations help models to reduce the overfitting. That makes dropout a wonderful regularisation technique.</p>

<p>During training,dropout layer randomly zeroes (drops) some of the elements of the input tensor with probability <code class="language-plaintext highlighter-rouge">p</code>. All the forward and backwards connections with a dropped element nodes are temporarily removed, thus creating a new network architecture out of the parent network. The zeroed element nodes are chosen independently for each forward call and are sampled from a Bernoulli distribution.</p>

<p>During evaluation, this layer behaves like an Identity layer.</p>

<p>Let’s see this visually how does dropout work during training time.</p>

<p><img src="https://github.com/user-attachments/assets/8b029f3f-6f4c-4443-ad88-735ddd895417" alt="image" /></p>

<p>As we can see, dropout works at individual neuron level, whether a neuron will be dropped or not is totally independent of another neuron. DropPath is bit different.</p>

<h1 id="introduction-to-droppath">Introduction to DropPath</h1>]]></content><author><name>Abhijit Deo</name><email>f20190041@goa.bits-pilani.ac.in</email></author><summary type="html"><![CDATA[While working on my latest project, I had to dive deep into the huggingface’s transformers codebase. In the process, I ventured into Swin Transformer territory—an innovative vision transformer designed for hierarchical feature representation. It was here that I noticed something that piqued my curiosity. Below is the code block that initially caught my attention:]]></summary></entry></feed>