It depends on the model architecture and which dimensions are variable.
E.g. if you are working with a CNN the spatial size can be variable and you would usually use an adaptive pooling layer to create a defined activation shape before feeding it to the first linear layer. Linear layers accept a variable input shapes as [batch_size, *, in_features], RNN layers accept a variable sequence length etc. so you would need to give a bi more information about your use case.