Fix Longformer and LED
Author: jplu
Pull request: yes

# What does this PR do?

This PR fix TF Longformer and LED when `inputs_embeds`/`decoder_inputs_embeds` are used as main input instead of `input_ids`/`decoder_input_ids`.

Here a quick test that shows the bug for Longformer:
```python
from transformers.models.longformer.modeling_tf_longformer import TFLongformerMainLayer
from tensorflow.keras.layers import Input, Dense
from tensorflow.keras.models import Model
from transformers import LongformerConfig
import tensorflow as tf
import numpy as np

class CustomLongFormer(tf.keras.layers.Layer):
    def __init__(self, name='longformer', **kwargs):
        super().__init__(name=name, **kwargs)
        config = LongformerConfig(attention_window=4, num_hidden_layers=1, vocab_size=10)
        self.longformer = TFLongformerMainLayer(config)

    def call(self, inputs):
        x = self.longformer(inputs)[0]
        return x


longformer = CustomLongFormer()
inputs_embeds = Input(shape=(None, None), dtype='float32', name="inputs_embeds")
output = longformer({"inputs_embeds": inputs_embeds})
output = Dense(9, activation='softmax')(output)
model = Model({"inputs_embeds": inputs_embeds}, output)
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')

x = np.array([np.random.uniform(0,1, (3, 768))] * 100)
y = np.array([[1]*3] * 100)
model.fit(x=x, y=y, epochs=10, batch_size=4, validation_split=0.1)
```

And the one for LED:
```python
from transformers.models.led.modeling_tf_led import TFLEDMainLayer
from tensorflow.keras.layers import Input, Dense
from tensorflow.keras.models import Model
from transformers import LEDConfig
import tensorflow as tf
import numpy as np

class CustomLED(tf.keras.layers.Layer):
    def __init__(self, name='longformer', **kwargs):
        super().__init__(name=name, **kwargs)
        config = LEDConfig(attention_window=4, num_hidden_layers=1, vocab_size=10)
        self.led = TFLEDMainLayer(config)

    def call(self, inputs):
        x = self.led(inputs)[0]
        return x


led = CustomLED()
inputs_embeds = Input(shape=(None, None), dtype='float32', name="inputs_embeds")
decoder_inputs_embeds = Input(shape=(None, None), dtype='float32', name="decoder_inputs_embeds")
output = led({"inputs_embeds": inputs_embeds, "decoder_inputs_embeds": decoder_inputs_embeds})
output = Dense(9, activation='softmax')(output)
model = Model({"inputs_embeds": inputs_embeds, "decoder_inputs_embeds": decoder_inputs_embeds}, output)
model.compile(optimizer='adam', loss='sparse_categorical_crossentropy')

x = np.array([np.random.uniform(0,1, (3, 1024))] * 100)
y = np.array([[1]*3] * 100)
model.fit(x={"inputs_embeds": x, "decoder_inputs_embeds": x}, y=y, epochs=10, batch_size=4, validation_split=0.1)
```

The reason is because the graph compiled is different than the one when the usual `input_ids`/`decoder_input_ids` are used. Knowing that we are not testing this case (in graph execution) other models might be involved in a similar bug. Hence, I put in my TODO list to create a test that will test if all the models can be used with different combinaison of inputs in graph mode.

# Fix issue
#9864 

Comments:
I'm working on this 👍  Should this belong to this PR or to another one?

I think it can be done in this PR.

I have added a quick test for graph execution with `inputs_embeds`. Later I will add the same for XLA as well but as all the models are not compliant I will handle this in same than the "usual" XLA test with `input_ids`.

And surprisingly all the models are now passing this test 😄 

Hi, I'm using transformers 2.31.0 (latest and stable as per Aug 9, 2023) but this PR doesn't seem to have been merged in the main branch, or reverted back to the original. I need this to save my extended model to file, or it will raise an error. Have these changes been overlooked, or is there a deeper issue?

See: https://github.com/huggingface/transformers/blob/v4.31.0/src/transformers/models/longformer/modeling_tf_longformer.py#L1821