title: How does the apply(fn) function in pytorch work with a function without return statement as argument?
body: <p>I have some questions about the following code fragments:</p>
  
  <pre><code>&gt;&gt;&gt; def init_weights(m):
          print(m)
          if type(m) == nn.Linear:
              m.weight.data.fill_(1.0)
              print(m.weight)
  
  &gt;&gt;&gt; net = nn.Sequential(nn.Linear(2, 2), nn.Linear(2, 2))
  &gt;&gt;&gt; net.apply(init_weights)
  </code></pre>
  
  <p>apply() is part of the pytorch.nn package. You find the code in the documentation of this package. The final questions:
  1. Why does this code sample work, although there is no argument or brackets added to init_weights() when it is given to apply()?
  2. Where does the function init_weights(m) gets its argument m from, when it's given as a parameter to the function apply() without brackets and an m?</p>