> 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 :func:`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 :func:`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: typing.Optional[torch.Tensor] = None,
    kwargs = {}
) -> tuple[torch.Tensor, typing.Optional[torch.Tensor]]
```

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