Lightning-AI / Lightning-AI/pytorch-lightning

`torch.set_float32_matmul_precision` deprecation

Open
#21,256 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

refactor
Dominant language
Python
Stars
31.4k
Forks
3.8k
Avg merge
6d 7h
Merged PRs (30d)
6

Description

### Outline & Motivation

On PyTorch 2.9 RC, `torch.get_float32_matmul_precision()` will cause the warning
```bash
UserWarning: Please use the new API settings to control TF32 behavior, such as torch.backends.cudnn.conv.fp32_precision = 'tf32' or torch.backends.cuda.matmul.fp32_precision = 'ieee'. Old settings, e.g, torch.backends.cuda.matmul.allow_tf32 = True, torch.backends.cudnn.allow_tf32 = True, allowTF32CuDNN() and allowTF32CuBLAS() will be deprecated after Pytorch 2.9. Please see https://pytorch.org/docs/main/notes/cuda.html#tensorfloat-32-tf32-on-ampere-and-later-devices (Triggered internally at /pytorch/aten/src/ATen/Context.cpp:80.)
```
For my use case, it seems to be coming from
https://github.com/Lightning-AI/pytorch-lightning/blob/dfbee800e0cf244504342f574b422b11ccf15f42/src/lightning/fabric/accelerators/cuda.py#L165
and
https://github.com/Lightning-AI/pytorch-lightning/blob/dfbee800e0cf244504342f574b422b11ccf15f42/src/lightning/fabric/utilities/throughput.py#L610

naively testing `torch.set_float32_matmul_precision("high")` in my REPL didn't seem to throw any errors.

I am unsure about the true extent of the changes necessary to account for this fp32 precision API change imposed since PyTorch 2.9 (some notes: https://docs.pytorch.org/docs/2.9/notes/cuda.html) beyond the examples presented above.

### Pitch

_No response_

### Additional context

_No response_

cc @lantiga @justusschock

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/lightning/fabric/accelerators/cuda.py around line 165 and src/lightning/fabric/utilities/throughput.py around line 610, then compare their precision-related calls with the PyTorch 2.9 CUDA TF32 notes. Check for other affected references and verify under PyTorch 2.9 that the relevant paths no longer emit the deprecation warning while preserving their existing behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python, pytorch
Domain
machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.