Aviso "All model checkpoint layers were used" mas camadas são inicializadas do zero
Author: JessicaVicentini99
Pull request: no
Labels: name: bug

### System Info

After updating the Transformers library to [4.44.2], I am getting the following warning when loading the `TFBertForSequenceClassification` model with the `neuralmind/bert-base-portuguese-cased` checkpoint:
```

"All model checkpoint layers were used when initializing TFBertForSequenceClassification.

Some layers of TFBertForSequenceClassification were not initialized from the model checkpoint at neuralmind/bert-base-portuguese-cased and are newly initialized: ['classifier', 'bert/pooler/dense/kernel:0', 'bert/pooler/dense/bias:0']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
[<ipython-input-68-1bdee581355e>](https://localhost:8080/#) in <cell line: 1>()
----> 1 model = build_model(MODEL_NAME, MAX_LEN, LEARNING_RATE)

3 frames
[/usr/local/lib/python3.10/dist-packages/transformers/modeling_tf_utils.py](https://localhost:8080/#) in input_processing(func, config, **kwargs)
    528                 output[parameter_names[i]] = input
    529             else:
--> 530                 raise ValueError(
    531                     f"Data of type {type(input)} is not allowed only {allowed_types} is accepted for"
    532                     f" {parameter_names[i]}."

ValueError: Exception encountered when calling layer 'tf_bert_for_sequence_classification_7' (type TFBertForSequenceClassification).

Data of type <class 'keras.src.backend.common.keras_tensor.KerasTensor'> is not allowed only (<class 'tensorflow.python.framework.tensor.Tensor'>, <class 'bool'>, <class 'int'>, <class 'transformers.utils.generic.ModelOutput'>, <class 'tuple'>, <class 'list'>, <class 'dict'>, <class 'numpy.ndarray'>) is accepted for input_ids.

Call arguments received by layer 'tf_bert_for_sequence_classification_7' (type TFBertForSequenceClassification):
  • input_ids=['<KerasTensor shape=(None, 512), dtype=int32, sparse=False, name=input_word_ids>', '<KerasTensor shape=(None, 512), dtype=int32, sparse=False, name=input_mask>', '<KerasTensor shape=(None, 512), dtype=int32, sparse=False, name=segment_ids>']
  • attention_mask=None
  • token_type_ids=None
  • position_ids=None
  • head_mask=None
  • inputs_embeds=None
  • output_attentions=None
  • output_hidden_states=None
  • return_dict=None
  • labels=None
  • training=False"

```
Previously, I was using the [4.35.2] version of the library and the model loaded without any issues. 

My code:


```
def build_model(MODEL_NAME, MAX_LEN, LEARNING_RATE):
  input_word_ids = tf.keras.Input(shape=(MAX_LEN,), dtype=tf.int32, name='input_word_ids')
  input_mask = tf.keras.Input(shape=(MAX_LEN,), dtype=tf.int32, name='input_mask')
  segment_ids = tf.keras.Input(shape=(MAX_LEN,), dtype=tf.int32,name="segment_ids")
  bert_model = TFAutoModelForSequenceClassification.from_pretrained(
      MODEL_NAME,
      num_labels=2
    )
  output = bert_model([input_word_ids, input_mask, segment_ids])
 
  logits = output.logits  # Acessa os logits da saída da camada BERT
  probs = tf.keras.layers.Softmax()(logits)

  
  model = tf.keras.Model(inputs=[input_word_ids, input_mask, segment_ids], outputs=[probs])

  model.compile(optimizer=Adam(learning_rate=LEARNING_RATE), loss='sparse_categorical_crossentropy', metrics=['accuracy'])


  return model

model = build_model(MODEL_NAME, MAX_LEN, LEARNING_RATE)
```

### Who can help?

_No response_

### Information

- [ ] The official example scripts
- [X] My own modified scripts

### Tasks

- [ ] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [X] My own task or dataset (give details below)

### Reproduction

call the function build_model

### Expected behavior

build the model 

Comments:
cc @Rocketknight1 for the TF model question

Hi @JessicaVicentini99, these kinds of errors are caused by incompatibilities between Keras 2 and Keras 3. Transformers only supports Keras 2, but newer versions of TensorFlow have started to install Keras 3 by default. This also means that `tf.keras` will always create Keras 3 objects on newer version of TensorFlow, which Transformers does not understand.

To fix this issue, you can do one of two things:

1) Downgrade to an older version of `tensorflow`
2) Install the compatibility package `tf-keras` using `pip install tf-keras`. Then, in your code, `import tf_keras as keras`, and finally replace `tf.keras` in your code with just `keras`. This will correctly use Keras 2 objects, and everything should work!

> Hi @JessicaVicentini99, these kinds of errors are caused by incompatibilities between Keras 2 and Keras 3. Transformers only supports Keras 2, but newer versions of TensorFlow have started to install Keras 3 by default. This also means that `tf.keras` will always create Keras 3 objects on newer version of TensorFlow, which Transformers does not understand.
> 
> To fix this issue, you can do one of two things:
> 
> 1. Downgrade to an older version of `tensorflow`
> 2. Install the compatibility package `tf-keras` using `pip install tf-keras`. Then, in your code, `import tf_keras as keras`, and finally replace `tf.keras` in your code with just `keras`. This will correctly use Keras 2 objects, and everything should work!

It worked, thank you very much :D