Fix continuous batching for composite / multimodal configs
Author: jiqing-feng
Pull request: yes

## Summary

`PagedAttentionCache` (continuous batching) reads model dimensions directly from
the top-level config: `num_attention_heads`, `num_key_value_heads`, `head_dim`,
`hidden_size`, `vocab_size`, `num_hidden_layers`, `sliding_window`, `layer_types`.

For composite / multimodal models (e.g. Gemma‑3, `Gemma3Config`) these fields live
on a nested `text_config`, not at the top level. So building the paged cache crashes:

```
AttributeError: 'Gemma3Config' object has no attribute 'num_attention_heads'
  File ".../continuous_batching/cache.py", line 145, in __init__
    self.num_key_value_heads = kv_heads if kv_heads is not None else config.num_attention_heads
```

This makes the continuous-batching path unusable for any multimodal model whose
text decoder is a valid causal LM.

## Fix

Resolve the text config at the start of `PagedAttentionCache.__init__` via the
canonical `config.get_text_config()`. For plain text models this returns the
config unchanged (no-op); for composite models it returns the nested `text_config`
that actually carries the attention dimensions.

```python
# src/transformers/generation/continuous_batching/cache.py
config = config.get_text_config()
self.config = config
```

All subsequent reads (including `group_layers_by_attn_type(config)` and
`self.config.sliding_window`) then resolve correctly.

## Scope / known limitation

This change fixes the config-resolution crash (`AttributeError`) that blocks the
paged cache from being built for **any** composite/multimodal model whose text
decoder is a causal LM. For models with a uniform `head_dim` across all layers,
continuous batching now works end-to-end.

It does **not** address models that use a non-uniform `head_dim` across attention
types. For example, Gemma‑4 uses `head_dim` for sliding-attention layers and
`global_head_dim` for full-attention layers (256 vs 512 in `gemma-4-E4B-it`).
`PagedAttentionCache` allocates a single uniform `head_dim` for all layers, so the
full-attention layers' KV states do not fit the cache slots:

```
RuntimeError: index_copy_(): Source/destination tensor must have same slice shapes.
Destination slice shape: 2 256 at dimension 0 and source slice shape: 2 512 at dimension 0.
```

Supporting per-attention-type `head_dim` in the paged cache is a separate, larger
change and is out of scope for this fix.

## Reproduction

```python
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation import GenerationConfig

mid = "google/gemma-3-4b-it"
tokenizer = AutoTokenizer.from_pretrained(mid, padding_side="left")
model = AutoModelForCausalLM.from_pretrained(mid, dtype=torch.bfloat16, device_map="auto").eval()

inputs = tokenizer(["Write me a poem about Machine Learning."], return_tensors="pt")
batch_inputs = inputs["input_ids"].tolist()

generation_config = GenerationConfig(
    max_new_tokens=32,
    use_cache=True,
    do_sample=False,
    num_blocks=128,
    eos_token_id=tokenizer.eos_token_id,
    pad_token_id=tokenizer.pad_token_id,
)

# Continuous batching path: before the fix this raises
#   AttributeError: 'Gemma3Config' object has no attribute 'num_attention_heads'
# After the fix the paged cache is built from the nested text_config and CB runs end-to-end.
outputs = model.generate_batch(inputs=batch_inputs, generation_config=generation_config)
for request_id in outputs:
    print(tokenizer.decode(outputs[request_id].generated_tokens, skip_special_tokens=True))
```


Comments:
cc @mcpatate @remi-or

**CI Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46864)

Hey @jiqing-feng ! I agree this is a necessary fix, however this would not be enough to support multimodal models, and it would crash somewhere else (eg. attn_impl). The fix is coming quite soon in https://github.com/huggingface/transformers/pull/46376 so I will close this PR for now, thanks for the contribution nevertheless.