Missing num_hidden_layers in T5GemmaConfig
Author: kuihao
Pull request: no
Labels: name: bug

### System Info

- `transformers` version: 4.56.0
- Platform: Linux-5.15.0-151-generic-x86_64-with-glibc2.39
- Python version: 3.12.3
- Huggingface_hub version: 0.34.4
- Safetensors version: 0.5.2
- Accelerate version: 1.10.1
- Accelerate config:    not found
- DeepSpeed version: 0.17.5
- PyTorch version (accelerator?): 2.6.0a0+ecf3bae40a.nv25.01 (CUDA)
- Tensorflow version (GPU?): not installed (NA)
- Flax version (CPU?/GPU?/TPU?): not installed (NA)
- Jax version: not installed
- JaxLib version: not installed
- Using distributed or parallel set-up in script?: **No**
- Using GPU in script?: **Yes**
- GPU type: NVIDIA RTX PRO 6000 Blackwell Max-Q Workstation Edition

### Who can help?

Models:
- text models: @ArthurZucker

### Information

- [x] The official example scripts
- [ ] My own modified scripts

### Tasks

- [x] An officially supported task in the `examples` folder (such as GLUE/SQuAD, ...)
- [ ] My own task or dataset (give details below)

### Reproduction

Running this code will result in an `AttributeError`.
```python
# pip install accelerate
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch

tokenizer = AutoTokenizer.from_pretrained("google/t5gemma-b-b-ul2")
model = AutoModelForSeq2SeqLM.from_pretrained(
    "google/t5gemma-b-b-ul2",
    device_map="auto",
)

input_text = "Write me a poem about Machine Learning. Answer:"
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids, max_new_tokens=32)
print(tokenizer.decode(outputs[0]))
```

```bash
Traceback (most recent call last):
  File "/data/t5gemma_example.py", line 15, in <module>
    outputs = model.generate(**input_ids, max_new_tokens=32)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/torch/utils/_contextlib.py", line 116, in decorate_context
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/transformers/generation/utils.py", line 2399, in generate
    self._prepare_cache_for_generation(
  File "/usr/local/lib/python3.12/dist-packages/transformers/generation/utils.py", line 2007, in _prepare_cache_for_generation
    else EncoderDecoderCache(DynamicCache(**dynamic_cache_kwargs), DynamicCache(**dynamic_cache_kwargs))
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/transformers/cache_utils.py", line 1018, in __init__
    for _ in range(config.num_hidden_layers)
                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/dist-packages/transformers/configuration_utils.py", line 207, in __getattribute__
    return super().__getattribute__(key)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'T5GemmaConfig' object has no attribute 'num_hidden_layers'
```

**Proposed Workaround**
The bug can be temporarily resolved by manually adding the num_hidden_layers attribute to the model's configuration object before generation. The value can be taken from either the encoder or decoder configuration, as they are the same.

```python
# pip install accelerate
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
import torch

tokenizer = AutoTokenizer.from_pretrained("google/t5gemma-b-b-ul2")
model = AutoModelForSeq2SeqLM.from_pretrained(
    "google/t5gemma-b-b-ul2",
    device_map="auto",
)

# Workaround to resolve the missing attribute
if not hasattr(model.config, "num_hidden_layers"):
    model.config.num_hidden_layers = model.config.encoder.num_hidden_layers

input_text = "Write me a poem about Machine Learning. Answer:"
input_ids = tokenizer(input_text, return_tensors="pt").to("cuda")

outputs = model.generate(**input_ids, max_new_tokens=32)
print(tokenizer.decode(outputs[0]))
```


### Expected behavior

The `T5GemmaConfig` object should include the `num_hidden_layers` attribute, which is a common and necessary property for many functionalities within the `transformers` library. The model should be able to generate outputs without needing a manual workaround.

Comments:
we'll update the `attribute_map` to make sure!

👋 

#40939 fixes this issue 🤗 


Workaround when using a pipeline object:
```python
import torch
from transformers import pipeline

pipe = pipeline(
    "text2text-generation",
    model="google/t5gemma-b-b-prefixlm-it",
    torch_dtype = torch.bfloat16,
    device="mps",  # replace with "mps" to run on a Mac device
)

# Workaround to resolve the missing attribute
model = pipe.model.model
if not hasattr(model.config, "num_hidden_layers"):
    print("Adding num_hidden_layers config attribute")
    model.config.num_hidden_layers = model.config.encoder.num_hidden_layers
```