No, padding cannot be a trainable parameter, if I’m not mistaken.
If you are running into shape mismatches after changing the model, you would have to change the architecture e.g. by applying an adaptive pooling layer (as done in the resnet) or by using different linear layers later in the model.
The reason the for mismatch is that you are changing the shape of the intermediate activations, while the linear layers need a fixed input shape to work properly (set by in_feautres).