Retrieve paramter list of module

Carsten_Ditzel: <p>Is there a way to retrieve the parameter list of e.g. a nn.Conv2d module, i.e. both the arguments that were passed and the set default parameters, after the module has been created?</p>
<p>Thank you in advance!</p>

Alexey_Demyanchuk: <p>I believe you can use python dunder method <code>__dict__</code> on any python object. If I instantiate conv2d module like this:</p>
<pre><code class="lang-auto">conv2d = nn.Conv2d(in_channels=3, out_channels=6, kernel_size=3)
</code></pre>
<p>Calling <code>conv2d.__dict__</code> gives me this:</p>
<pre><code class="lang-auto">{'_backward_hooks': OrderedDict(),
 '_buffers': OrderedDict(),
 '_forward_hooks': OrderedDict(),
 '_forward_pre_hooks': OrderedDict(),
 '_load_state_dict_pre_hooks': OrderedDict(),
 '_modules': OrderedDict(),
 '_non_persistent_buffers_set': set(),
 '_parameters': OrderedDict([('weight', Parameter containing:
               tensor([[[[-0.0343,  0.0877, -0.1922],
                         [-0.0998,  0.0335,  0.1608],
                         [-0.0976,  0.0042,  0.0078]],
               
                       ...
               
                        [[ 0.0101,  0.1680, -0.1120],
                         [-0.0862,  0.0624, -0.0306],
                         [ 0.0852, -0.0843, -0.0521]]]], requires_grad=True)),
              ('bias', Parameter containing:
               tensor([ 0.0879,  0.0465, -0.1899, -0.1272,  0.0014,  0.0306],
                      requires_grad=True))]),
 '_reversed_padding_repeated_twice': (0, 0, 0, 0),
 '_state_dict_hooks': OrderedDict(),
 'dilation': (1, 1),
 'groups': 1,
 'in_channels': 3,
 'kernel_size': (3, 3),
 'out_channels': 6,
 'output_padding': (0, 0),
 'padding': (0, 0),
 'padding_mode': 'zeros',
 'stride': (1, 1),
 'training': True,
 'transposed': False}
</code></pre>
<p>If you need, you can filter out parameters which are starts with <code>_</code></p>

Carsten_Ditzel: <p>thank you, but I was referring to the parameter list exclusively</p>

Alexey_Demyanchuk: <p>I am not sure if I understand correctly, but here is couple of options:</p>
<ol>
<li>If you need just module arguments’ names (without values), you can just use <code>__dict__</code>, filtering out privates starting with <code>_</code> and converting the returned dictionary keys into list or even more simply like this:</li>
</ol>
<pre><code class="lang-auto">[arg_name for arg_name in conv2d.__dict__ if not arg_name.startswith('_')]
</code></pre>
<ol start="2">
<li>If you need module arguments’ names and their respective values, it seams appropriate to me to use <code>__dict__</code> as shown in my previous post (also filtering out privates starting with <code>_</code>)</li>
</ol>

Carsten_Ditzel: <aside class="quote no-group" data-username="Alexey_Demyanchuk" data-post="4" data-topic="106427">
<div class="title">
<div class="quote-controls"></div>
<img loading="lazy" alt="" width="24" height="24" src="https://discuss.pytorch.org/user_avatar/discuss.pytorch.org/alexey_demyanchuk/48/25254_2.png" class="avatar"> Alexey_Demyanchuk:</div>
<blockquote>
<pre><code class="lang-auto">[arg_name for arg_name in conv2d.__dict__ if not arg_name.startswith('_')]
</code></pre>
<ol start="2">
<li>If you need module arguments’ names and their respective values, it seams appropriate to me to use <code>__dict__</code> as shown in my previous post (also filtering out privates starting with <code>_</code>)</li>
</ol>
</blockquote>
</aside>
<p>thank you, I will try that!</p>