Use tiny ONNX models for text modality
Author: lewtun
Pull request: yes

# What does this PR do?

Partially addresses https://github.com/huggingface/transformers/issues/18819

This PR uses the new tiny random models from @ydshieh to speed up the ONNX tests for the **text** modality. This brings the slow ONNX tests down to about 1.5h. The other modalities will be added once we have tiny models that can run a forward pass in general. 

Note that the following text models didn't work when running

```
RUN_SLOW=1 pytest -v tests/onnx/test_onnx_v2.py -x -k "model_arch"
```
so have been excluded for now:

**hf-internal-testing/tiny-random-IBertModel**

* Cannot export model to ONNX

**hf-internal-testing/tiny-random-LayoutLMv3Model**

* Not strictly a text model, but caught this in my testing:

```
tests/onnx/test_onnx_v2.py:423: in test_pytorch_export
    self._onnx_export(test_name, name, model_name, feature, onnx_config_class_constructor)
        feature    = 'default'
        model_name = 'hf-internal-testing/tiny-random-LayoutLMv3Model'
        name       = 'layoutlmv3'
        onnx_config_class_constructor = functools.partial(<bound method OnnxConfig.from_model_config of <class 'transformers.models.layoutlmv3.configuration_layoutlmv3.LayoutLMv3OnnxConfig'>>, task='default')
        self       = <tests.onnx.test_onnx_v2.OnnxExportTestCaseV2 testMethod=test_pytorch_export_091_layoutlmv3_default>
        test_name  = 'layoutlmv3_default'
tests/onnx/test_onnx_v2.py:351: in _onnx_export
    self.fail(f"{name}, {feature} -> {e}")
E   AssertionError: layoutlmv3, default -> The size of tensor a (12545) must match the size of tensor b (5) at non-singleton dimension 1
```

**hf-internal-testing/tiny-random-LongformerModel**

* Might be related to #20292 

```
self = <onnxruntime.capi.onnxruntime_inference_collection.InferenceSession object at 0x7fc37b5d0a90>, output_names = ['last_hidden_state', 'pooler_output']
input_feed = {'attention_mask': array([[1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1, 1, 1],
       [1, 1, 1, 1, 1, 1, 1...put_ids': array([[0, 3, 3, 3, 3, 3, 3, 3, 2],
       [0, 3, 3, 3, 3, 3, 3, 3, 2],
       [0, 3, 3, 3, 3, 3, 3, 3, 2]])}
run_options = None

    def run(self, output_names, input_feed, run_options=None):
        """
        Compute the predictions.
    
        :param output_names: name of the outputs
        :param input_feed: dictionary ``{ input_name: input_value }``
        :param run_options: See :class:`onnxruntime.RunOptions`.
        :return: list of results, every result is either a numpy array,
            a sparse tensor, a list or a dictionary.
    
        ::
    
            sess.run([output_name], {input_name: x})
        """
        num_required_inputs = len(self._inputs_meta)
        num_inputs = len(input_feed)
        # the graph may have optional inputs used to override initializers. allow for that.
        if num_inputs < num_required_inputs:
            raise ValueError("Model requires {} inputs. Input Feed contains {}".format(num_required_inputs, num_inputs))
        if not output_names:
            output_names = [output.name for output in self._outputs_meta]
        try:
>           return self._sess.run(output_names, input_feed, run_options)
E           onnxruntime.capi.onnxruntime_pybind11_state.RuntimeException: [ONNXRuntimeError] : 6 : RUNTIME_EXCEPTION : Non-zero status code returned while running Reshape node. Name:'Reshape_2943' Status Message: /Users/runner/work/1/s/onnxruntime/core/providers/cpu/tensor/reshape_helper.h:41 onnxruntime::ReshapeHelper::ReshapeHelper(const onnxruntime::TensorShape &, onnxruntime::TensorShapeVector &, bool) gsl::narrow_cast<int64_t>(input_shape.Size()) == size was false. The input tensor cannot be reshaped to the requested shape. Input shape:{3,4,2,5}, requested shape:{3,1,9,5}
```

**hf-internal-testing/tiny-random-BlenderbotSmallModel**

* Problem with tokenizer vocab

```
self = <[AttributeError("'ByteLevelBPETokenizer' object has no attribute '_tokenizer'") raised in repr()] ByteLevelBPETokenizer object at 0x7fc2a041e610>
vocab = '/Users/lewtun/.cache/huggingface/hub/models--hf-internal-testing--tiny-random-BlenderbotSmallModel/snapshots/1eff1bdb5f97b473480b1ec8af85f58439e88906/vocab.json'
merges = '/Users/lewtun/.cache/huggingface/hub/models--hf-internal-testing--tiny-random-BlenderbotSmallModel/snapshots/1eff1bdb5f97b473480b1ec8af85f58439e88906/merges.txt'
add_prefix_space = False, lowercase = False, dropout = None, unicode_normalizer = None, continuing_subword_prefix = None, end_of_word_suffix = None, trim_offsets = True

    def __init__(
        self,
        vocab: Optional[Union[str, Dict[str, int]]] = None,
        merges: Optional[Union[str, Dict[Tuple[int, int], Tuple[int, int]]]] = None,
        add_prefix_space: bool = False,
        lowercase: bool = False,
        dropout: Optional[float] = None,
        unicode_normalizer: Optional[str] = None,
        continuing_subword_prefix: Optional[str] = None,
        end_of_word_suffix: Optional[str] = None,
        trim_offsets: bool = False,
    ):
        if vocab is not None and merges is not None:
            tokenizer = Tokenizer(
>               BPE(
                    vocab,
                    merges,
                    dropout=dropout,
                    continuing_subword_prefix=continuing_subword_prefix or "",
                    end_of_word_suffix=end_of_word_suffix or "",
                )
            )
E           Exception: Error while initializing BPE: Token `_</w>` out of vocabulary
```

**hf-internal-testing/tiny-random-MarianModel**

* Problem with config

```
self = <[AttributeError("'Embedding' object has no attribute 'padding_idx'") raised in repr()] Embedding object at 0x7fd700e63d00>, num_embeddings = 99, embedding_dim = 16
padding_idx = 58100, max_norm = None, norm_type = 2.0, scale_grad_by_freq = False, sparse = False, _weight = None, device = None, dtype = None

    def __init__(self, num_embeddings: int, embedding_dim: int, padding_idx: Optional[int] = None,
                 max_norm: Optional[float] = None, norm_type: float = 2., scale_grad_by_freq: bool = False,
                 sparse: bool = False, _weight: Optional[Tensor] = None,
                 device=None, dtype=None) -> None:
        factory_kwargs = {'device': device, 'dtype': dtype}
        super(Embedding, self).__init__()
        self.num_embeddings = num_embeddings
        self.embedding_dim = embedding_dim
        if padding_idx is not None:
            if padding_idx > 0:
>               assert padding_idx < self.num_embeddings, 'Padding_idx must be within num_embeddings'
E               AssertionError: Padding_idx must be within num_embeddings
```

**hf-internal-testing/tiny-random-MBartModel**

* Problem with embedding config

```
    def embedding(
        input: Tensor,
        weight: Tensor,
        padding_idx: Optional[int] = None,
        max_norm: Optional[float] = None,
        norm_type: float = 2.0,
        scale_grad_by_freq: bool = False,
        sparse: bool = False,
    ) -> Tensor:
    
        if has_torch_function_variadic(input, weight):
            return handle_torch_function(
                embedding,
                (input, weight),
                input,
                weight,
                padding_idx=padding_idx,
                max_norm=max_norm,
                norm_type=norm_type,
                scale_grad_by_freq=scale_grad_by_freq,
                sparse=sparse,
            )
        if padding_idx is not None:
            if padding_idx > 0:
                assert padding_idx < weight.size(0), "Padding_idx must be within num_embeddings"
            elif padding_idx < 0:
                assert padding_idx >= -weight.size(0), "Padding_idx must be within num_embeddings"
                padding_idx = weight.size(0) + padding_idx
        else:
            padding_idx = -1
        if max_norm is not None:
            # Note [embedding_renorm contiguous]
            # `embedding_renorm_` will call .contiguous() on input anyways, so we
            # call it here and take advantage of the improved locality in the
            # `embedding` call below too.
            input = input.contiguous()
            # Note [embedding_renorm set_grad_enabled]
            # XXX: equivalent to
            # with torch.no_grad():
            #   torch.embedding_renorm_
            # remove once script supports set_grad_enabled
            _no_grad_embedding_renorm_(weight, input, max_norm, norm_type)
>       return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse)
E       IndexError: index out of range in self
```

Comments:
_The documentation is not available anymore as the PR was closed or merged._

@lewtun  Thank you for working on this 💯 

I force pushed a commit to resolve a conflict on `main`.

Thank you for sharing the models that are not working. Keep in mind that there are some difficulty in the tiny model creation :
- no model tester
- can't convert tokenizer/processor correctly
- no super easy to to set some config attributes correctly for a few particular models
- etc.

We might need a few more iterations to make things more stable (i.e. need to create new tiny models), but I will take care of the failing ONNX tests if the new tiny models break the tests.

Let me merge later today once the tests pass with the new set of tiny models (which is currently being built)

> Let me merge later today once the tests pass with the new set of tiny models (which is currently being built)

Sounds great! Let me know if you need any help 🙏 

Running on CPU with only the new tiny random mdoels

> 293 passed, 2 skipped, 23628 warnings in 760.95s (0:12:40)

🚀 🚀 🚀 🚀 

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_20333). All of your documentation changes will be reflected on that endpoint.