<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>Nn.Module on Programmer.ie: Modern AI programming</title>
    <link>http://programmer.ie/tags/nn.module/</link>
    <description>Recent content in Nn.Module on Programmer.ie: Modern AI programming</description>
    <generator>Hugo</generator>
    <language>en-us</language>
    <lastBuildDate>Sat, 08 Aug 2026 13:09:00 +0100</lastBuildDate>
    <atom:link href="http://programmer.ie/tags/nn.module/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>PyTorch nn.Module Explained: Missing Parameters, state_dict, Buffers and Registration Bugs</title>
      <link>http://programmer.ie/post/pytorch-zero-to-hero-04/</link>
      <pubDate>Sat, 08 Aug 2026 13:09:00 +0100</pubDate>
      <guid>http://programmer.ie/post/pytorch-zero-to-hero-04/</guid>
      <description>&lt;h2 id=&#34;pytorch-zero-to-hero--step-04&#34;&gt;PyTorch: Zero to Hero — Step 04&lt;/h2&gt;&#xA;&lt;p&gt;In the previous post we built a neural network using raw tensors and autograd.&lt;/p&gt;&#xA;&lt;p&gt;Now we are going to add the abstraction PyTorch expects almost every real model to use:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#66d9ef&#34;&gt;class&lt;/span&gt; &lt;span style=&#34;color:#a6e22e&#34;&gt;Model&lt;/span&gt;(torch&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;nn&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Module):&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    &lt;span style=&#34;color:#f92672&#34;&gt;...&lt;/span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;But this is not going to be a tour of &lt;code&gt;nn.Module&lt;/code&gt; methods.&lt;/p&gt;&#xA;&lt;p&gt;The useful question for programmers is:&lt;/p&gt;&#xA;&lt;blockquote&gt;&#xA;&lt;p&gt;&lt;strong&gt;What exactly does &lt;code&gt;nn.Module&lt;/code&gt; register, track, move, save and expose — and how do those mechanisms break?&lt;/strong&gt;&lt;/p&gt;</description>
    </item>
    <item>
      <title>Build a Neural Network From Scratch in PyTorch Without nn.Module</title>
      <link>http://programmer.ie/post/pytorch-zero-to-hero-03/</link>
      <pubDate>Sat, 08 Aug 2026 12:59:00 +0100</pubDate>
      <guid>http://programmer.ie/post/pytorch-zero-to-hero-03/</guid>
      <description>&lt;h2 id=&#34;pytorch-zero-to-hero--step-03&#34;&gt;PyTorch: Zero to Hero — Step 03&lt;/h2&gt;&#xA;&lt;p&gt;Most PyTorch tutorials begin with something like this:&lt;/p&gt;&#xA;&lt;div class=&#34;highlight&#34;&gt;&lt;pre tabindex=&#34;0&#34; style=&#34;color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;&#34;&gt;&lt;code class=&#34;language-python&#34; data-lang=&#34;python&#34;&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&lt;span style=&#34;color:#f92672&#34;&gt;import&lt;/span&gt; torch.nn &lt;span style=&#34;color:#66d9ef&#34;&gt;as&lt;/span&gt; nn&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;model &lt;span style=&#34;color:#f92672&#34;&gt;=&lt;/span&gt; nn&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Sequential(&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    nn&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Linear(&lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;16&lt;/span&gt;),&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    nn&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;ReLU(),&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;    nn&lt;span style=&#34;color:#f92672&#34;&gt;.&lt;/span&gt;Linear(&lt;span style=&#34;color:#ae81ff&#34;&gt;16&lt;/span&gt;, &lt;span style=&#34;color:#ae81ff&#34;&gt;2&lt;/span&gt;),&#xA;&lt;/span&gt;&lt;/span&gt;&lt;span style=&#34;display:flex;&#34;&gt;&lt;span&gt;)&#xA;&lt;/span&gt;&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;p&gt;That is useful code.&lt;/p&gt;&#xA;&lt;p&gt;It is also hiding almost everything interesting.&lt;/p&gt;&#xA;&lt;p&gt;In this post we are going to build the same kind of neural network using ordinary PyTorch tensors.&lt;/p&gt;&#xA;&lt;p&gt;No &lt;code&gt;nn.Module&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;No &lt;code&gt;nn.Linear&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;No &lt;code&gt;torch.optim.Adam&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;No &lt;code&gt;optimizer.step()&lt;/code&gt;.&lt;/p&gt;&#xA;&lt;p&gt;We will manually create the parameters, write the forward pass, calculate the loss, call autograd, update the weights, zero the gradients, batch the data, evaluate the model and then compare the result with the idiomatic PyTorch version.&lt;/p&gt;</description>
    </item>
  </channel>
</rss>
