In ViTForMaskedImageModeling, you will receive a reconstructed_pixel_values which shape is different with input when model.config.patch_size is not 16. This further triggers an error about loss when patch_size is not 16 and bool_masked_pos is not None.
### System Info

- `transformers` version: 4.29.2
- Platform: Linux-3.10.0-1160.90.1.el7.x86_64-x86_64-with-glibc2.35
- Python version: 3.9.16
- Huggingface_hub version: 0.14.1
- Safetensors version: not installed
- PyTorch version (GPU?): 1.13.1+cu117 (True)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using GPU in script?: <fill in>
- Using distributed or parallel set-up in script?: <fill in>

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [ ] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Use ViTForMaskedImageModeling;
Set model.config.patch_size except 16;
Get error.

### Expected behavior

In ViTForMaskedImageModeling, you will receive a reconstructed_pixel_values which shape is different with input when model.config.patch_size is not 16. This further triggers an error about loss when patch_size is not 16 and bool_masked_pos is not None.
cc @amyeroberts <|||||>Hi @yrqUni, thanks for reporting this issue. 

Digging into this, the error is arising because the decoder head for the model is parametreized by `config.encoder_stride`, which controls the size of the upscaled image. When we update the patch size, in order to calculate the loss, the encoder stride needs to be updated to ensure the reconstructed image has the same resolution as the input. 

I've opened a PR to raise a warning if the loss calculation isn't possible with the configuration settings. 