[XLMModel, FlaubertModel] Compatibility with torch make_fx
### System Info

- `transformers` version: 4.29.2
- Platform: Linux
- Python version: 3.8.16
- PyTorch version: 2.0.1


### 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

I am trying to get a torch.fx representation for some Transformer models and I noticed that some of them are not compatible with `make_fx` from PyTorch.

To reproduce the error:

```python
from torch.fx.experimental.proxy_tensor import make_fx
from transformers import XLMModel

model = XLMModel.from_pretrained('xlm-mlm-en-2048', torchscript=True)
inp = model.dummy_inputs['input_ids']
model.eval()
fx_g = make_fx(model)(inp)

```

which fails with the following:
```
RuntimeError: It appears that you're trying to get value out of a tracing tensor with aten._local_scalar_dense.default - erroring out! It's likely that this is caused by data-dependent control flow or similar.  It may be possible to trace this with dynamic shapes; try setting tracing_mode='symbolic' in your make_fx call.
```

This error is present in XLMModel and FlaubertModel because of the line:
```python
assert lengths.max().item() <= slen
```

It seems that make_fx does not support value-based control flow.
Removing the various occurrences of this line, or executing the code with the -O optimizer flag (that disables all the asserts) eliminate the issue, but neither solution is ideal.

Another element to note is that capturing the graph through dynamo also fails (or outputs multiple graphs) but because of the `.item()` call.



### Expected behavior

The full FX representation of FlaubertModel/XLMModel using torch make_fx.
We can have a look at a PR with a fix.<|||||>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.