Qwen2.5-VL fix redundant cu_window_seqlens
Author: John-Ge
Pull request: yes

### What does this PR do?
This PR removes redundant cu_window_seqlens in Qwen2.5-VL
The original cu_window_seqlens is [link to code](https://github.com/huggingface/transformers/blob/356b3cd71d7bfb51c88fea3e8a0c054f3a457ab9/src/transformers/models/qwen2_5_vl/modular_qwen2_5_vl.py#L304)

```python
    def get_window_index(self, grid_thw):
        window_index: list = []
        cu_window_seqlens: list = [0]
        window_index_id = 0
        vit_merger_window_size = self.window_size // self.spatial_merge_size // self.patch_size

        for grid_t, grid_h, grid_w in grid_thw:
            llm_grid_h, llm_grid_w = (
                grid_h // self.spatial_merge_size,
                grid_w // self.spatial_merge_size,
            )
            index = torch.arange(grid_t * llm_grid_h * llm_grid_w).reshape(grid_t, llm_grid_h, llm_grid_w)
            pad_h = vit_merger_window_size - llm_grid_h % vit_merger_window_size
            pad_w = vit_merger_window_size - llm_grid_w % vit_merger_window_size
            num_windows_h = (llm_grid_h + pad_h) // vit_merger_window_size
            num_windows_w = (llm_grid_w + pad_w) // vit_merger_window_size
            index_padded = F.pad(index, (0, pad_w, 0, pad_h), "constant", -100)
            index_padded = index_padded.reshape(
                grid_t,
                num_windows_h,
                vit_merger_window_size,
                num_windows_w,
                vit_merger_window_size,
            )
            index_padded = index_padded.permute(0, 1, 3, 2, 4).reshape(
                grid_t,
                num_windows_h * num_windows_w,
                vit_merger_window_size,
                vit_merger_window_size,
            )
            seqlens = (index_padded != -100).sum([2, 3]).reshape(-1)
            index_padded = index_padded.reshape(-1)
            index_new = index_padded[index_padded != -100]
            window_index.append(index_new + window_index_id)
            cu_seqlens_tmp = seqlens.cumsum(0) * self.spatial_merge_unit + cu_window_seqlens[-1]
            cu_window_seqlens.extend(cu_seqlens_tmp.tolist())
            window_index_id += (grid_t * llm_grid_h * llm_grid_w).item()
        window_index = torch.cat(window_index, dim=0)

        return window_index, cu_window_seqlens
```

If the grid_thw is `torch.tensor([1, 8, 8])` and the `vit_merger_window_size=4`, the return of above code should have:
`cu_window_seqlens = [0, 16, 32, 32, 48, 64, 64, 64, 64, 64]` 
which has redudant length as there are many 32 and 64 in the list. 

This is because `pad_h = vit_merger_window_size - llm_grid_h % vit_merger_window_size = 4` which should have been 0, incuring extra window padding. 
This extra numbers are later removed in `cu_window_seqlens = torch.unique_consecutive(cu_window_seqlens)`. Hence, the redundant numbers do not cause error.

We could remove these numbers to minimize the extra operations. My PR are very simple just calculate the correct window padding and remove the deduplication.

```python
# for correct padding size
pad_h = vit_merger_window_size - llm_grid_h % vit_merger_window_size if llm_grid_h % vit_merger_window_size != 0 else 0
pad_w = vit_merger_window_size - llm_grid_w % vit_merger_window_size if llm_grid_w % vit_merger_window_size != 0 else 0
# remove the deduplication
# cu_window_seqlens = torch.unique_consecutive(cu_window_seqlens)
```


Comments:
Hi 👋, thank you for opening this pull request! The pull request is converted to draft by default. The CI will be paused while the PR is in draft mode. When it is ready for review, please click the `Ready for review` button (at the bottom of the PR page). This will assign reviewers and trigger CI.

nice catch！could you modify `modeling_qwen2_5_vl.py` in the same way to pass consistency check?🤗

> nice catch！could you modify `modeling_qwen2_5_vl.py` in the same way to pass consistency check?🤗

Thank you! I am modifying code in the file `modeling_qwen2_5_vl.py`.

cc @zucchini-nlp 

Thanks, will review when PR is marked ready for review 🤗