How to extract weights, but not biases, from model?

I am trying to extract all the weights, but not biases, from a network. I realise I could just use model.parameters() and then filter out the biases, but this would likely be too slow. Additionally, using layer.weight would not work as I need it to be as “universal” as possible so I don’t have to change the code every time I modify the network. Is there any other way of doing this?

You can use named_parameters for easier filtering ( Why do you think filtering out bias would be too slow? It doesn’t make sense for pytorch to maintain such a collection. So to get such a list, it is very reasonable to sweep over all parameters.