ConversationalPipeline Not Compatible With HuggingFace SageMaker Deploy
Author: joelsimonoff
Pull request: no

## Environment info
<!-- You can run the command `transformers-cli env` and copy-and-paste its output below.
     Don't forget to fill out the missing fields in that output! -->

- `transformers` version: 4.11.3
- Platform: macOS-10.16-x86_64-i386-64bit
- Python version: 3.8.8
- PyTorch version (GPU?): 1.9.1 (False)
- 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?: No
- Using distributed or parallel set-up in script?: No

### Who can help
<!-- Your issue will be replied to more quickly if you can figure out the right person to tag with @
 If you know how to use git blame, that is the easiest way, otherwise, here is a rough guide of **who to tag**.
 Please tag fewer than 3 people.

Models:

- ALBERT, BERT, XLM, DeBERTa, DeBERTa-v2, ELECTRA, MobileBert, SqueezeBert: @LysandreJik
- encoder-decoder models (For example, BlenderBot, BART, Marian, Pegasus, T5, ByT5): @patrickvonplaten, @patil-suraj
- Longformer, Reformer, TransfoXL, XLNet, FNet: @patrickvonplaten
- FSMT: @stas00
- Funnel: @sgugger
- GPT-2, GPT: @patrickvonplaten, @LysandreJik
- RAG, DPR: @patrickvonplaten, @lhoestq
- TensorFlow: @Rocketknight1
- JAX/Flax: @patil-suraj @patrickvonplaten 
- TAPAS, LayoutLM, LayoutLMv2, LUKE, ViT, BEiT, DEiT, DETR, CANINE: @NielsRogge
- GPT-Neo, GPT-J, CLIP: @patil-suraj
- Wav2Vec2, HuBERT, SpeechEncoderDecoder: @patrickvonplaten, @anton-l

If the model isn't in the list, ping @LysandreJik who will redirect you to the correct contributor.

Library:

- Benchmarks: @patrickvonplaten
- Deepspeed: @stas00
- Ray/raytune: @richardliaw, @amogkam
- Text generation: @patrickvonplaten
- Tokenizers: @LysandreJik
- Trainer: @sgugger
- Pipelines: @Narsil
- Speech: @patrickvonplaten, @anton-l
- Vision: @NielsRogge, @sgugger

Documentation: @sgugger

Model hub:

- for issues with a model, report at https://discuss.huggingface.co/ and tag the model's creator.

HF projects:

- datasets: [different repo](https://github.com/huggingface/datasets)
- rust tokenizers: [different repo](https://github.com/huggingface/tokenizers)

Examples:

- maintained examples (not research project or legacy): @sgugger, @patil-suraj

For research projetcs, please ping the contributor directly. For example, on the following projects:

- research_projects/bert-loses-patience: @JetRunner
- research_projects/distillation: @VictorSanh

 -->

Tagging: @Narsil 

## Information

I am using the ConversationalPipeline with BlenderBot and SageMaker deploy. However, any model will encounter the same issue.

The SageMaker handler passes the type `dict` inputs directly to the model: `prediction = model(inputs, **parameters)` (https://github.com/aws/sagemaker-huggingface-inference-toolkit/blob/f884fc65d64f2e15637ccf16d2a83e37114cb23f/src/sagemaker_huggingface_inference_toolkit/handler_service.py#L157).

That triggers this ValueError from https://github.com/huggingface/transformers/blob/26b6ef79d6554a2ffc3b50ec8c68f8688bdff7a2/src/transformers/pipelines/conversational.py#L247:

```python
 if not isinstance(conversation, Conversation):
     raise ValueError("ConversationalPipeline, expects Conversation as inputs")
```

## To reproduce

Follow the SageMaker deploy boiler plate code and run the predictor.

```python
from sagemaker.huggingface import HuggingFaceModel
import sagemaker

role = sagemaker.get_execution_role()
# Hub Model configuration. https://huggingface.co/models
hub = {
	'HF_MODEL_ID':'facebook/blenderbot-1B-distill',
	'HF_TASK':'conversational'
}

# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
	transformers_version='4.6.1',
	pytorch_version='1.7.1',
	py_version='py36',
	env=hub,
	role=role, 
)

# deploy model to SageMaker Inference
predictor = huggingface_model.deploy(
	initial_instance_count=1, # number of instances
	instance_type='ml.m5.xlarge' # ec2 instance type
)

predictor.predict({
	'inputs': {
		"past_user_inputs": ["Which movie is the best ?"],
		"generated_responses": ["It's Die Hard for sure."],
		"text": "Can you explain why ?",
	}
})
```

<!-- If you have code snippets, error messages, stack traces please provide them here as well.
     Important! Use code tags to correctly format your code. See https://help.github.com/en/github/writing-on-github/creating-and-highlighting-code-blocks#syntax-highlighting
     Do not use screenshots, as they are hard to read and (more importantly) don't allow others to copy-and-paste your code.-->

## Expected behavior

The input to the SageMaker handler has to be JSON because we can't send `Conversation` objects as part of an HTTP Post request. Therefore the ConversationalPipeline needs to accept a dictionary and Conversation objects. 

Specifically, we need to change:

```python
 if not isinstance(conversation, Conversation):
     raise ValueError("ConversationalPipeline, expects Conversation as inputs")
```
to
```python
if not isinstance(conversation, Conversation) and not isinstance(conversation, dict):
    raise ValueError("ConversationalPipeline, expects Conversation as inputs")
if isinstance(conversation, dict):
    try:
        conversation = Conversation(**conversation)
    except Exception as e:
        raise ValueError("Failed converting input dict to Conversation") from e
```

This should enable the ConversationalPipeline to work with the SageMaker deployment.
<!-- A clear and concise description of what you would expect to happen. -->


Comments:
That's seems like a very nice feature to add !

Do you want to make the PR (only NIT would be 

"ConversationalPipeline, expects Conversation as inputs" -> "ConversationalPipeline, expects Conversation or dicts as inputs"

Hey @joelsimonoff, 

this should be fixed with a higher DLC version. I see that you are using `transformers_version=4.6.1` for your SageMaker Image. 
We added a `wrapper` for this here Here https://github.com/aws/sagemaker-huggingface-inference-toolkit/blob/f884fc65d64f2e15637ccf16d2a83e37114cb23f/src/sagemaker_huggingface_inference_toolkit/transformers_utils.py#L92

You can switch to `transformers_version=4.11` and `pytorch_version=1.9` then your code works. 
But there is currently a bug in the `python-sagemaker-sdk` which is not generating the correct `image_uri` for `transformers=4.11`. I added the DLC directly via the `image_uri`. When the bug is solved you can normally use `transformers_version` and `pytorch_version` again. Issue: https://github.com/aws/sagemaker-python-sdk/issues/2700



P.S. I noticed that the instance type you used `ml.m5.xlarge`, was too large to use the model I went with an `ml.g4dn.2xlarge`. 

```python
f
from sagemaker.huggingface import HuggingFaceModel
import sagemaker
​
role = sagemaker.get_execution_role()
# Hub Model configuration. https://huggingface.co/models
hub = {
    'HF_MODEL_ID':'facebook/blenderbot-1B-distill',
    'HF_TASK':'conversational'
}
​
# create Hugging Face Model Class
huggingface_model = HuggingFaceModel(
    #transformers_version='4.11',
    #pytorch_version='1.9',
    #py_version='py38',
    image_uri="763104351884.dkr.ecr.us-east-1.amazonaws.com/huggingface-pytorch-inference:1.9.0-transformers4.11.0-gpu-py38-cu111-ubuntu20.04",
    env=hub,
    role=role, 
)
​
# deploy model to SageMaker Inference
predictor = huggingface_model.deploy(
    initial_instance_count=1, # number of instances
    instance_type='ml.g4dn.2xlarge' # ec2 instance type
)
​
predictor.predict({
    'inputs': {
        "past_user_inputs": ["Which movie is the best ?"],
        "generated_responses": ["It's Die Hard for sure."],
        "text": "Can you explain why ?",
    }
})
```

Outputing: 
```
{'generated_text': " I think it's because it's based on a book by the same name by James Bond.",
 'conversation': {'past_user_inputs': ['Which movie is the best ?',
   'Can you explain why ?'],
  'generated_responses': ["It's Die Hard for sure.",
   " I think it's because it's based on a book by the same name by James Bond."]}}
```

@philschmid Looks great, thanks!