Note that hidden_size is a property on all configurations, so if you use it instead of dim in your example, you should be good.
For pruning specific heads, I don’t think you will have one when using the AutoModel architecture since it’s supposed to be the bare model.
So the main issue will be to get the representation. For this, I’m afraid there is nothing generic that will work accross the model zoo (which is why the XxxForSequenceClassification are implemented in separate files) since some models expect to use the first token, others the last, others the mean etc.