Repository: huggingface/transformers
Pull request: Audio encodings now match conv2d weight dtype in Gemma3nAudioSSCPConvBlock

# What does this PR do?

The change ensures that the audio encodings are cast to the same type as `conv.weight` tensor. This is done by appending `to(self.conv.weight.dtype)` to the `audio_encodings_padded` rvalue.  

Fixes an issue where the conv2d forward pass throws an error. Code for reproducible error (run on Mac M1) :


```python
from transformers import pipeline
import torch

pipe = pipeline(
    "image-text-to-text",
    model="google/gemma-3n-e2b-it",
    device=0,
    torch_dtype=torch.bfloat16,
    cache_implementation="static"
)


messages = [
    {
        "role": "user",
        "content": [
            {"type": "audio", "audio": "5676.wav"},
            {"type": "text", "text": "Transcribe this audio file."}
        ]
    }
]

output = pipe(text=messages, max_new_tokens=200, torch_dtype=torch.bfloat16)
print(output[0]["generated_text"][-1]["content"])
```
Full stack trace is attached [error.txt](https://github.com/user-attachments/files/21478915/error.txt).

## Before submitting
- [ ] This PR fixes a typo or improves the docs (you can dismiss the other checks if that's the case).
- [x] 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?


## Suggested Reviewers
@ArthurZucker 



Changed files:
filename: src/transformers/models/gemma3n/modeling_gemma3n.py
patch: @@ -695,7 +695,9 @@ def forward(self, audio_encodings: torch.Tensor) -> torch.Tensor:
         # Input audio_encodings is [B, C_in, T_in, F_in] (e.g., C_in=1)
         # manual_padding is (pad_F_left, pad_F_right, pad_T_top, pad_T_bottom)
         # F.pad applies to last two dims: F_in then T_in
-        audio_encodings_padded = F.pad(audio_encodings, self.manual_padding, mode="constant", value=0.0)
+        audio_encodings_padded = F.pad(audio_encodings, self.manual_padding, mode="constant", value=0.0).to(
+            self.conv.weight.dtype
+        )
         # Expected padded shape for F_in, k_w=3, pad_F=(1,1) -> F_padded = F_in+2
         # Expected padded shape for T_in, k_h=3, pad_T=(0,2) -> T_padded = T_in+2
         audio_encodings_conv = self.conv(audio_encodings_padded)

filename: src/transformers/models/gemma3n/modular_gemma3n.py
patch: @@ -1264,7 +1264,9 @@ def forward(self, audio_encodings: torch.Tensor) -> torch.Tensor:
         # Input audio_encodings is [B, C_in, T_in, F_in] (e.g., C_in=1)
         # manual_padding is (pad_F_left, pad_F_right, pad_T_top, pad_T_bottom)
         # F.pad applies to last two dims: F_in then T_in
-        audio_encodings_padded = F.pad(audio_encodings, self.manual_padding, mode="constant", value=0.0)
+        audio_encodings_padded = F.pad(audio_encodings, self.manual_padding, mode="constant", value=0.0).to(
+            self.conv.weight.dtype
+        )
         # Expected padded shape for F_in, k_w=3, pad_F=(1,1) -> F_padded = F_in+2
         # Expected padded shape for T_in, k_h=3, pad_T=(0,2) -> T_padded = T_in+2
         audio_encodings_conv = self.conv(audio_encodings_padded)