🚨 [gemma 3/4] Fix bidirectional attention masking crossing sliding window boundaries
Author: douglas-reid
Pull request: yes

<!-- ci-dashboard-badge:start -->
[![CI](https://transformers-ci.lor-e.huggingface.cool/badge/pr?pr=46850)](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46850)
<!-- ci-dashboard-badge:end -->

# What does this PR do?

This fixes the behavior of attention masking for image tokens to properly respect sliding window boundaries for Gemma 3/4 models. This was needed to match the intended model behavior for local layers.

- [X] I confirm that this is not a pure code agent PR.

## Before submitting
- [X] Did you read the [contributor guideline](https://huggingface.co/docs/transformers/contributing) and the
      [Pull Request](https://huggingface.co/docs/transformers/pr_checks) checks?
- [X] Was this discussed/approved via a Github issue or the [forum](https://discuss.huggingface.co/)? Please add a link
      to it if that's the case.
- [ ] Did you make sure to update the documentation with your changes according to the [guidelines](https://github.com/huggingface/transformers/tree/main/docs)?
- [X] Did you write any new necessary [tests](https://huggingface.co/docs/transformers/testing)?

<!-- ci-dashboard-recap:start -->

---

### CI recap

**Dashboard:** [View test results in Grafana](https://transformers-ci.lor-e.huggingface.cool/d/pytest-observability-by-pr/pytest-observability-branch?var-pr=46850)
**Latest run:** [28405951213:2](https://github.com/huggingface/transformers/actions/runs/28406342486)
**Result:** `success` | **Jobs:** 7 | **Tests:** 2,337 | **Failures:** 0 | **Duration:** 32m 59s

<!-- ci-dashboard-recap:end -->

Comments:
run-slow: gemma3, gemma4, gemma4_unified

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28355534526)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/gemma3", "models/gemma4", "models/gemma4_unified"]
quantizations: []

The docs for this PR live [here](https://moon-ci-docs.huggingface.co/docs/transformers/pr_46850). All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

**[For maintainers]** Suggested jobs to run (before merge)

run-slow: gemma3, gemma4, gemma4_unified

Applied some test updates and added 🚨 to the PR title.

run-slow: gemma3, gemma4, gemma4_unified

[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28429675853)

This comment contains `run-slow`, running the specified jobs: 

models: ["models/gemma3", "models/gemma4", "models/gemma4_unified"]
quantizations: []

## CI Results
[Workflow Run ⚙️](https://github.com/huggingface/transformers/actions/runs/28429675853)

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [2dfad5da](https://github.com/huggingface/transformers/commit/2dfad5da14de9ea8f85e4518a2a583d4a52a9670) | workflow commit (merge commit) |
| PR | [59c04311](https://github.com/douglas-reid/transformers/commit/59c043115aed45b002b65f67501295f7ea151c5e) | branch commit (from PR) |
| main | [957e6032](https://github.com/huggingface/transformers/commit/957e6032a2b5b95ffd885c6ab9f114976eb895cb) | base commit (on `main`) |

✅ No failing test specific to this PR 🎉 👏 !