How do I print the scheduler nicely in PyTorch?

pinocchio: <p>for example look how nice the optimizer is (with all the fields):</p>
<pre><code class="lang-auto">optimizer
Adam (
Parameter Group 0
    amsgrad: False
    betas: (0.9, 0.999)
    eps: 1e-08
    initial_lr: 0.001
    lr: 0.001
    weight_decay: 0
)
</code></pre>
<p>but look at the scheduler:</p>
<pre><code class="lang-auto">scheduler
&lt;torch.optim.lr_scheduler.MultiStepLR at 0x12035d4a8&gt;
</code></pre>
<p>why does the scheduler print so badly?</p>

alex.veuthey: <p>To answer your question, that’s most likely because the scheduler does not have as important parameters as the optimizer, and the <code>__str__()</code> method has not been implemented.</p>
<p>You can either inherit from <code>MultiStepLR</code> and create your own subclass, with a <code>__str__()</code> method that prints the elements you want, or create an external function that extracts the elements you want directly (e.g. <code>milestones</code>, <code>gamma</code>, <code>last_epoch</code>…)</p>

pinocchio: <p>The parameters are obviously important! They affect the final generalization of any model!</p>
<p>Anyway, thats a pitty its not implemented. How does one implement it and pull request it?</p>

ptrblck: <p>Have a look at the <a href="https://github.com/pytorch/pytorch/blob/master/CONTRIBUTING.md">CONTRIBUTING</a> document for some guide lines.</p>
<blockquote>
<p>If you are interested in contributing to PyTorch, your contributions will fall into two categories:</p>
</blockquote>
<pre><code>You want to propose a new feature and implement it.
    Post about your intended feature, and we shall discuss the design and implementation. Once we agree that the plan looks good, go ahead and implement it.
You want to implement a feature or bug-fix for an outstanding issue.
    Search for your issue here: https://github.com/pytorch/pytorch/issues
    Pick an issue and comment on the task that you want to work on this feature.
    If you need more context on a particular issue, please ask and we shall provide.
</code></pre>
<blockquote>
<p>Once you finish implementing a feature or bug-fix, please send a Pull Request to <a href="https://github.com/pytorch/pytorch" class="inline-onebox">GitHub - pytorch/pytorch: Tensors and Dynamic neural networks in Python with strong GPU acceleration</a></p>
</blockquote>

Zhihao_Wu: <p>One way is similar to what <a class="mention" href="/u/alex.veuthey">@alex.veuthey</a>  mentioned, you can implement <code>__repr__()</code> method in your scheduler class. The following is <code>__repr__()</code> method in optimizer class.</p>
<pre><code class="lang-auto">def __repr__(self):
        format_string = self.__class__.__name__ + ' ('
        for i, group in enumerate(self.param_groups):
            format_string += '\n'
            format_string += 'Parameter Group {0}\n'.format(i)
            for key in sorted(group.keys()):
                if key != 'params':
                    format_string += '    {0}: {1}\n'.format(key, group[key])
        format_string += ')'
        return format_string
</code></pre>
<p>It exactly does what you want when you print(optimizer), so you can do something like this.</p>
<p>Another way you can directly call <code>state_dict()</code> method just like <code>print(scheduler.state_dict())</code> and it will return some parameters you might want to look into.</p>