OperatorNotAllowedInGraphError when using TFDebertaV2Model after recent Keras update
Author: BogdanDidenko
Pull request: no
Labels: name: bug

### System Info

System Info
transformers version: 4.44.2
Platform: Google Colab | Apple M1 Max 14.6.1
Python version: 3.10.12
Tensorflow version (GPU?): 2.15.0 (True)
Keras version: 2.15.0
tf_keras: 2.15.1
Huggingface_hub version: 0.23.4
Safetensors version: 0.4.4
Accelerate version: not installed
Accelerate config: not found
Using GPU in script?: Yes
Using distributed or parallel set-up in script?: Yes
Who can help?
@ArthurZucker, @Rocketknight1

I’m encountering an OperatorNotAllowedInGraphError when using TFDebertaV2Model from the Transformers library in graph mode. The code works fine in eager mode. This issue might be related to a recent update in the Keras version, as the same code previously worked on Google Colab.


### Who can help?

_No response_

### Information

- [X] The official example scripts
- [X] 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

```python
tf.config.run_functions_eagerly(True)
encoder = TFAutoModel.from_pretrained('microsoft/deberta-v3-base', cache_dir='./cache')
src_tokens = tf_keras.layers.Input((None,), dtype="int64", name="src_tokens")#, batch_size=1)
src_tokens_mask = tf_keras.layers.Input((None,), dtype="int64", name="src_tokens_mask")#, batch_size=1)
encoder_output = encoder(input_ids=src_tokens, attention_mask=src_tokens_mask)
```

```error
File "/Users/bogdan.didenko/wsc/gec-tf2/venv_310/lib/python3.10/site-packages/transformers/modeling_tf_utils.py", line 1199, in run_call_with_unpacked_inputs  *
        return func(self, **unpacked_inputs)
    File "/Users/bogdan.didenko/wsc/gec-tf2/venv_310/lib/python3.10/site-packages/transformers/models/deberta_v2/modeling_tf_deberta_v2.py", line 1201, in call  *
        outputs = self.deberta(
    File "/Users/bogdan.didenko/wsc/gec-tf2/venv_310/lib/python3.10/site-packages/keras/src/utils/traceback_utils.py", line 122, in error_handler  **
        raise e.with_traceback(filtered_tb) from None
    File "/Users/bogdan.didenko/wsc/gec-tf2/venv_310/lib/python3.10/site-packages/transformers/modeling_tf_utils.py", line 437, in run_call_with_unpacked_inputs
        return func(self, **unpacked_inputs)
    File "/Users/bogdan.didenko/wsc/gec-tf2/venv_310/lib/python3.10/site-packages/transformers/models/deberta_v2/modeling_tf_deberta_v2.py", line 1053, in call
        encoder_outputs = self.encoder(
    File "/Users/bogdan.didenko/wsc/gec-tf2/venv_310/lib/python3.10/site-packages/transformers/models/deberta_v2/modeling_tf_deberta_v2.py", line 423, in call
        layer_outputs = layer_module(
    File "/Users/bogdan.didenko/wsc/gec-tf2/venv_310/lib/python3.10/site-packages/transformers/models/deberta_v2/modeling_tf_deberta_v2.py", line 258, in call
        attention_outputs = self.attention(
    File "/Users/bogdan.didenko/wsc/gec-tf2/venv_310/lib/python3.10/site-packages/transformers/models/deberta_v2/modeling_tf_deberta_v2.py", line 179, in call
        self_outputs = self.self(
    File "/Users/bogdan.didenko/wsc/gec-tf2/venv_310/lib/python3.10/site-packages/transformers/models/deberta_v2/modeling_tf_deberta_v2.py", line 682, in call
        rel_att = self.disentangled_att_bias(query_layer, key_layer, relative_pos, rel_embeddings, scale_factor)
    File "/Users/bogdan.didenko/wsc/gec-tf2/venv_310/lib/python3.10/site-packages/transformers/models/deberta_v2/modeling_tf_deberta_v2.py", line 776, in disentangled_att_bias
        if shape_list(key_layer)[-2] != shape_list(query_layer)[-2]:

    OperatorNotAllowedInGraphError: Exception encountered when calling TFDebertaV2DisentangledSelfAttention.call().
    
    Using a symbolic `tf.Tensor` as a Python `bool` is not allowed. You can attempt the following resolutions to the problem: If you are running in Graph mode, use Eager execution mode or decorate this function with @tf.function. If you are using AutoGraph, you can try decorating this function with @tf.function. If that does not work, then you may be using an unsupported feature or your source code may not be visible to AutoGraph. See https://github.com/tensorflow/tensorflow/blob/master/tensorflow/python/autograph/g3doc/reference/limitations.md#access-to-source-code for more information.
```


### Expected behavior

the code should work

Comments:
Reinstalled transformers and looks like the problem is gone 

Let us know if the problem recurs! I'll close for now, but feel free to reopen the issue if you can reproduce it.