I personally don’t use this workflow, as I don’t think that an optimizer is necessarily bound to a model.
Of course your use case might use a single model and optimizer and thus this workflow will certainly work for your use case, but it’s “cleaner” to me to use them as separate objects.
One potential drawback would also be the creation of checkpoints. While model.state_dict() would properly return all parameters and buffers, you would now need to access the optimizer object through the model to save and load its state_dict. Again, this comes down to your coding style, so I’m sure there might also be valid reasons to use this approach.
Also, I wouldn’t add the device information inside the model directly, as this would break e.g. nn.DataParallel.