[AudioFlamingo3] Fix bfloat16 dtype mismatch in audio encoder positional embedding
Author: snkii
Pull request: yes

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

## What does this PR do?

Fixes a `RuntimeError` when loading `AudioFlamingo3ForConditionalGeneration` with `torch_dtype=torch.bfloat16`.

`AudioFlamingo3ForConditionalGeneration` inherits `_keep_in_fp32_modules_strict = ["embed_positions"]` from `VoxtralForConditionalGeneration`, keeping `embed_positions` in float32 even when the model is loaded in bfloat16. In `AudioFlamingo3AudioEncoder.forward()`, the positional embedding addition was missing the dtype cast that `VoxtralEncoder` already applies:

```python
# Before (AudioFlamingo3) — missing cast
hidden_states = inputs_embeds + self.embed_positions.weight
# inputs_embeds: bfloat16, embed_positions.weight: float32
# → hidden_states upcast to float32
# → LayerNorm(float32 input, bfloat16 weight) → RuntimeError: expected scalar type Float but found BFloat16

# After — consistent with VoxtralEncoder.forward()
hidden_states = (inputs_embeds + self.embed_positions.weight).to(inputs_embeds.dtype)
```

### Verification

MMAU-test (9,000 samples), bfloat16 + FlashAttention-2, scored via the official [sonalkum/MMAU-Eval](https://huggingface.co/spaces/sonalkum/MMAU-Eval) space:

| | accuracy |
|---|---|
| bs=5, before fix (dtype mismatch causes audio embedding contamination across samples) | 57.08% |
| bs=5, after fix | **72.40%** |

## Who can review?

@eustlb @vasqu

Comments:
run-slow: audioflamingo3

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

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

models: ["models/audioflamingo3"]
quantizations: []

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

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [756eb3d5](https://github.com/huggingface/transformers/commit/756eb3d5c2e00d117f2be0a9bcff38caba128f24) | workflow commit (merge commit) |
| PR | [88f842f1](https://github.com/snkii/transformers/commit/88f842f17b0ea39cecb137c092594a52325701a5) | branch commit (from PR) |
| main | [f1a2a70f](https://github.com/huggingface/transformers/commit/f1a2a70f2804720198a071816bc311e765869296) | base commit (on `main`) |

⚠️ **Model CI failed to report results**

The test failure analysis could not be completed. Please check the [workflow run](https://github.com/huggingface/transformers/actions/runs/29342990658) for details.


Run slow failed but the tests passed all :shrug: waiting for the others on a final confirmation but should be good

@vasqu, @snkii can we check if other models that were refactor by #45534 need this fix? E.g. musicflamingo, glmasr, and vibevoice ASR come to mind as they did modular from audioflamingo3

You'll probably have to regenerate the modeling files anyway

Sounds good! Best to group the fixes if possible indeed

@snkii can you run `python utils/modular_model_converter.py` and delete [this line](https://github.com/huggingface/transformers/blob/d9f38e809329cdec8802dfb6ed25173aed2e0aee/src/transformers/models/qwen3_asr/modular_qwen3_asr.py#L281) from Qwen3 ASR modular? that will resolve the failing repo consistency check

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

run-slow: audioflamingo3, glmasr, musicflamingo, qwen3_asr

run-slow: audioflamingo3, glmasr, musicflamingo, qwen3_asr

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

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

models: ["models/audioflamingo3", "models/glmasr", "models/musicflamingo", "models/qwen3_asr"]
quantizations: []

<!-- 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=47258)
**Latest run:** [29349983865:2](https://github.com/huggingface/transformers/actions/runs/29504058309)
**Result:** `success` | **Jobs:** 5 | **Tests:** 918 | **Failures:** 1 | **Duration:** 1m 27s

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

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

Thank you for your contribution 🤗!

## CI Security Gate — automatic approval blocked

This PR was **not** automatically approved for CI because the security gate failed.

**Possible reasons:**
- The PR touches 50 or more files — only PRs with fewer than 50 changed files are automatically approved
- A changed file is outside the allowed directories (`src/`, `tests/`, `docs/`, `utils/`), has a disallowed extension (only `.py`, `.txt`, `.md` permitted outside `tests/` and `docs/`), or is not `.md`/`.yml` inside `docs/`
- A new high-severity security issue was detected in the changed Python files (Bandit check)

See the [workflow run](https://github.com/huggingface/transformers/actions/runs/29504056063) for the exact violations.

A maintainer can review and manually approve CI if a finding is a false positive.

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

### Commit Info
| Context | Commit | Description |
|---------|--------|-------------|
| RUN | [8446c858](https://github.com/huggingface/transformers/commit/8446c858d2b253525586fc2118f9448fe0fd3cd4) | workflow commit (merge commit) |
| PR | [b652c8a4](https://github.com/snkii/transformers/commit/b652c8a4ab2deeed4ab3edf5d5ac0b8b8478830d) | branch commit (from PR) |
| main | [0f33294a](https://github.com/huggingface/transformers/commit/0f33294af580c29cdc79571663c2545cea6e9f34) | base commit (on `main`) |

✅ No failing test specific to this PR 🎉 👏 !


Thanks for the fix(es), merging now :hugs: