> This page is for version 0.5.0 · 26.06.
> For other versions, use one of these documentation indexes:
> - Nightly (default): https://docs.nvidia.com/nemo/automodel/nightly/llms.txt
> - Latest: https://docs.nvidia.com/nemo/automodel/latest/llms.txt
> - 0.5.0 · 26.06: https://docs.nvidia.com/nemo/automodel/v0.5/llms.txt
> - 0.4.0 · 26.04: https://docs.nvidia.com/nemo/automodel/v0.4/llms.txt

> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.nvidia.com/nemo/automodel/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.nvidia.com/nemo/automodel/_mcp/server.

# nemo_automodel.components.models.gemma4_moe.sdpa_fp32

fp32 SDPA attention for Gemma4 (fix for #2208: fused bf16 SDPA NaNs on Hopper).

## Module Contents

### Functions

| Name                                                                                                                | Description                                                                        |
| ------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------- |
| [`enable_gemma4_sdpa_fp32`](#nemo_automodel-components-models-gemma4_moe-sdpa_fp32-enable_gemma4_sdpa_fp32)         | Install `sdpa_fp32_attention_forward` as the process-wide `"sdpa"` implementation. |
| [`sdpa_fp32_attention_forward`](#nemo_automodel-components-models-gemma4_moe-sdpa_fp32-sdpa_fp32_attention_forward) | Run SDPA with fp32 query/key/value and cast the output back to the input dtype.    |

### API

```python
nemo_automodel.components.models.gemma4_moe.sdpa_fp32.enable_gemma4_sdpa_fp32() -> None
```

Install `sdpa_fp32_attention_forward` as the process-wide `"sdpa"` implementation.

```python
nemo_automodel.components.models.gemma4_moe.sdpa_fp32.sdpa_fp32_attention_forward(
    module: torch.nn.Module,
    query: torch.Tensor,
    key: torch.Tensor,
    value: torch.Tensor,
    attention_mask: torch.Tensor | None = None,
    kwargs = {}
) -> tuple[torch.Tensor, torch.Tensor | None]
```

Run SDPA with fp32 query/key/value and cast the output back to the input dtype.