[Qwen2.5-VL] Fix torch.finfo() TypeError for integer attention_mask_tensor
Author: dsnsabari
Pull request: yes

What does this PR do?
This PR fixes a critical TypeError in the Qwen2.5-VL model that occurs when processing attention masks with integer dtypes. The error torch.finfo() requires a floating point input type was preventing model inference when using frameworks like Unsloth.
Problem
The issue occurs in modeling_qwen2_5_vl.py at line 1292 where torch.finfo() is called on attention mask tensors that may have integer dtypes:
pythonattention_mask_tensor = attention_mask_tensor / torch.finfo(attention_mask_tensor.dtype).min
Since torch.finfo() only supports floating-point types, this crashes when the attention mask tensor has an integer dtype.
Solution
Added dtype checking to use the appropriate function:

torch.iinfo() for integer dtypes
torch.finfo() for floating-point dtypes

This maintains backward compatibility while fixing the crash for integer attention masks.
Impact

✅ Fixes model crashes during vision inference with Unsloth
✅ Enables support for integer dtype attention masks
✅ Maintains existing functionality for float dtype tensors
✅ No breaking changes to existing code

<!-- Remove if not applicable -->
Fixes # (issue)
Before submitting

 This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
 Did you read the [contributor guideline](https://github.com/huggingface/transformers/blob/main/CONTRIBUTING.md#create-a-pull-request),
Pull Request section?
 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? Here are the
[documentation guidelines](https://github.com/huggingface/transformers/tree/main/docs), and
[here are tips on formatting docstrings](https://github.com/huggingface/transformers/tree/main/docs#writing-source-documentation).
 Did you write any new necessary tests?

Additional Testing Details

✅ Tested with integer attention mask dtypes (torch.int32, torch.int64)
✅ Tested with floating-point attention mask dtypes (torch.float16, torch.float32)
✅ Verified compatibility with Unsloth framework
✅ Confirmed no regression in existing Qwen2.5-VL functionality
✅ Added unit tests covering both dtype paths

Who can review?
@amyeroberts @qubvel - This is a vision model fix for Qwen2.5-VL dtype compatibility
Priority: High - This is a blocking issue that prevents model inference in common usage scenarios with Unsloth and other frameworks that may use integer attention masks.
Backward Compatibility: ✅ Fully backward compatible - no changes to existing API or behavior for floating-point tensors.

Comments:
@zucchini-nlp okay.

The CI is still red @dsnsabari 

@zucchini-nlp ,Yes, I encountered some other issues when I tried to run make fix-copies. I am fixing them on my local system.

@zucchini-nlp, The CI issue has been fixed. Please check it. 

Thanks, looks like changes in Qwen2-VL and Qwen2-5-Omni were reverted when fixing CI. Can you take a look?

@zucchini-nlp sure.

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

@zucchini-nlp ,  Qwen2-5-Omni doesn't have an attention mask for torch.finfo(). I have updated the Qwen2-VL code with a fix. Please find the search results from the main branch; it shows only five files.
<img width="1114" height="1024" alt="Screenshot 2025-07-11 160617" src="https://github.com/user-attachments/assets/e7ac43d0-17b8-4a3c-b00e-463d6bed3045" />


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

run-slow: glm4v, qwen2_5_vl, qwen2_vl