fix the error which will make shape not match occur.
# What does this PR do?

When using PyTorch for model trace, the size of feature map will be inconsistent, resulting in failure to export successfully. The reason is that += is used in the size calculation code, and the object that happens to be added happens to be a shallow copy object, causing input_shape to change. You can solve this problem by declaring variables directly.

# Test script
```python3
from einops import repeat
from transformers import BertTokenizerFast,LayoutXLMTokenizerFast,LayoutLMv2ForSequenceClassification
import torch


## dummy inputs
dummy_input_ids = torch.LongTensor(torch.randint(low=0, high=1000, size=(2,256)))#.cuda()
box = [[48, 84, 73, 128]] * 256
dummy_bboxes = repeat(torch.LongTensor(box).unsqueeze(0), '1 b s-> 2 b s')
dummy_attention_mask = torch.LongTensor(torch.randint( low=0, high=1024, size=(2, 256) ))#.cuda()
dummy_imgs = torch.randn(2, 3, 448, 448)#.cuda()
dummy_token_ids = torch.zeros_like(dummy_attention_mask)

dummy_inputs = [
    dummy_input_ids,
    dummy_bboxes,
    dummy_imgs,
    dummy_attention_mask,
    dummy_token_ids
    ]
with torch.no_grad():

    model = LayoutLMv2ForSequenceClassification.from_pretrained("microsoft/layoutlmv2-base-uncased", torchscript=True,num_labels=30522)
    model.eval()
    traced_model = torch.jit.trace(func=model,
                                       strict=False,  
                                       example_inputs=dummy_inputs)
torch.jit.save(traced_model,'temp.pt')
model = torch.jit.load('temp.pt')
model.eval()
with torch.no_grad():
    result = model(*dummy_inputs)
print(result)
```

**If the script is run directly before the code is modified, the feature map size will be inconsistent**

# Who can review?
@LysandreJik

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_18789). All of your documentation changes will be reflected on that endpoint.<|||||>This issue has been automatically marked as stale because it has not had recent activity. If you think this still needs to be addressed please comment on this thread.

Please note that issues that do not follow the [contributing guidelines](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md) are likely to be ignored.