Support "OptimizedModule" models obtained from torch.compile() in inference pipelines
### Feature request

Currently models obtained by the [torch.compile()](https://pytorch.org/docs/stable/generated/torch.compile.html) feature introduced in Pytorch 2.0 are not supported in inference pipelines from :hugs: Transformers. 

### Motivation

The same way pipelines support optimization methods such as the use of [accelerate](https://github.com/huggingface/accelerate) with "device_map" and [bitsandbytes](https://github.com/TimDettmers/bitsandbytes) with "load_in_8bit",  torch.compile() support would make a great addition for better inference performance in pipelines.

### Your contribution

Opening this feature request :P. Unfortunately I'm not familiar enough with the :hugs: Transformers codebase and the quirks that one could find with such a new feature such as torch.compile() to feel as I can tackle his task.
cc @Narsil <|||||>Hi @iranz15 can you share an example of code of failure  ?

I tried to do :

```python
pipe.model = torch.compile(pipe.model)
```

And everything seems to work ok after removing `inference_mode` and just using `torch.no_grad`.
@sgugger any preference between compilation and inference mode ?

I haven't played enough with either but I remember `inference_mode` benefits being minor, maybe `torch.compile` benefits are currently much higher.<|||||>I don't know `inference_mode` very much, so not sure. It also seems like it should work with compiled model so might be worth reporting to the PyTorch team.<|||||>Hey @Narsil. A error/warning message seems to show when using `torch.compile()` on the model before adding to the pipeline, that is, for the following case
```python
model = AutoModelForCausalLM.from_pretrained("bigscience/bloomz-560m")
tokenizer = AutoTokenizer.from_pretrained("bigscience/bloomz-560m")
model = torch.compile(model)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
```
it will complain that `The model 'OptimizedModule' is not supported for $TASK_NAME ...`, but first loading the pipeline and then accessing the model and compiling it like you did seems to work fine. Surprisingly, after doing some additional tests, even when it complains about 'OptimizedModule' it seems that you can still use the pipeline without any problem. The additional errors that I was having where due to some oversights in my code that wrongly pointed me to blame `torch.compile()`.

<|||||>> The additional errors that I was having where due to some oversights in my code that wrongly pointed me to blame torch.compile().

OK thanks, a warning will trigger when sending arbitrary objects (because it's likely an issue in user code) but still will use the model pass through so you can use any class you want so you can run onnx, optimum etc.. too. (as long as they support the same API as the original model)