title: In PyTorch, how to I make certain module `Parameters` static during training?
body: <p><strong>Context:</strong></p>
  
  <p>In pytorch, any <a href="https://pytorch.org/docs/stable/nn.html#parameters" rel="nofollow noreferrer"><code>Parameter</code></a> is a special kind of <code>Tensor</code>. A <code>Parameter</code> is automatically registered with a module's <code>parameters()</code> method when it is assigned as an attribute.</p>
  
  <p>During training, I will pass <code>m.parameters()</code> to the <a href="https://pytorch.org/docs/stable/optim.html#algorithms" rel="nofollow noreferrer"><code>Optimizer</code></a> instance so they can be updated.</p>
  
  <hr>
  
  <p><strong>Question</strong>: For a built-in pytorch module, how to I prevent certain parameters from being modified by the optimizer?</p>
  
  <pre><code>s = Sequential(
          nn.Linear(2,2),
          nn.Linear(2,3),   # I want this one's .weight and .bias to be constant
          nn.Linear(3,1)
      )
  </code></pre>
  
  <ul>
  <li>Can I make it so they don't appear in <code>s.parameters()</code>?</li>
  <li>Can I make the parameters read-only so any attempted changes are ignored?</li>
  </ul>