Repository: pytorch
Issue: Python 3.13 support for PyTorch
Labels: module: build,triaged,module: python frontend

### Update Jan 13 2025:

Now that enablement in trunk has been done and 3.13/3.13t are officially released, revamping this to be a support matrix for what works today and what we plan on adding:

Source build 
| OS | 3.13 | 3.13t |
| -- | -- | -- |
| Linux | :white_check_mark:  | :white_check_mark: |
| MacOS | :white_check_mark: | :white_check_mark: |
| Windows | :white_check_mark: | :white_check_mark: |

Nightlies (As of Jan 13 2025):
| OS | 3.13 | 3.13t |
| -- | -- | -- |
| Linux | :white_check_mark:  | :white_check_mark: |
| Linux Aarch64 | :white_check_mark:   | :x: |
| MacOS | :white_check_mark:  | :x: |
| Windows | :white_check_mark:  | :x: |

Release 2.5.0
| OS | 3.13 | 3.13t |
| -- | -- | -- |
| Linux | :white_check_mark:  | :x: |
| Linux Aarch64 | :x:   | :x: |
| MacOS | :x: | :x: |
| Windows | :x: | :x: |

Release 2.5.1 
| OS | 3.13 | 3.13t |
| -- | -- | -- |
| Linux | :white_check_mark:  | :x: |
| Linux Aarch64 | :x:   | :x: |
| MacOS | :x: | :x: |
| Windows | :x: | :x: |

Release 2.6 
| OS | 3.13 | 3.13t |
| -- | -- | -- |
| Linux | :white_check_mark:  | :white_check_mark: |
| Linux Aarch64 | :white_check_mark:  | :x: |
| MacOS | :white_check_mark: | :x: |
| Windows | :white_check_mark: | :x: |

Release 2.7 (tentative)
| OS | 3.13 | 3.13t |
| -- | -- | -- |
| Linux | :white_check_mark:  | :white_check_mark: |
| Linux Aarch64 | :white_check_mark:  | :white_check_mark: |
| MacOS | :white_check_mark: | :white_check_mark: |
| Windows | :white_check_mark: | :white_check_mark: |

### Original post

Python 3.13 is coming out in the near future - RC1 is planned for July 30 (first point at which the ABI is stable and packages can start releasing wheels for 3.13), and the fina release is planned for 1 Oct 2024 (see [PEP 719](https://peps.python.org/pep-0719/)). 

I see that work on supporting 3.13 has started (gh-121979, gh-130030; Cc @atalman), but I couldn't find a tracking issue for the current status of it, so I thought it'd be useful to have one. The other motivation to open an issue now: we're working on implementing support for free-threaded CPython (a.k.a. "no-GIL", [PEP 703](https://peps.python.org/pep-0703/)) and are interested to start work on a first package that depends on PyTorch. Support for the default CPython 3.13 is a pre-requisite for starting that work though.

Here is a hopefully useful breakdown in steps to support Python 3.13:
- [x] PyTorch builds from source on 3.13 (done in https://github.com/pytorch/pytorch/pull/126033 )
- [x] Nightly `cp313` wheels available for all platforms (waiting until final cpython rc)
- [x] `torch.compile` support for 3.13 (WIP @williamwen42 )
- [x] PyTorch builds from source with free-threaded CPython (blocked on dependency support + update in core, tracking PR https://github.com/pytorch/pytorch/pull/130689)
- [x] `cp313t` (free-threaded) nightly wheels available (blocked on ft build and dependencies)


Python 3.13 CD:

- [x] Nightly `cp313` Linux wheels available: https://github.com/pytorch/pytorch/pull/130030 
- [x] https://github.com/pytorch/builder/pull/2035 
- [x] Nightly windows wheels : https://github.com/pytorch/pytorch/pull/138095
- [x] Nightly macos: https://github.com/pytorch/pytorch/pull/140137
- [x] Nightly aarch64 wheels : https://github.com/pytorch/pytorch/pull/138629
- [x] https://github.com/pytorch/pytorch/pull/136001
- [x] https://github.com/pytorch/pytorch/pull/137127
- [x] https://github.com/pytorch/builder/pull/2001
- [x] https://github.com/pytorch/pytorch/pull/142294

Python 3.13 CI & torch.compile:

- [x] https://github.com/pytorch/pytorch/pull/143162
- [x] https://github.com/pytorch/pytorch/pull/143078 
- [x] https://github.com/pytorch/pytorch/pull/143074
- [x] #141264
- [x] #141951
- [x] #141950
- [x] #141887
- [x] #141886
- [x] #141860
- [x] #141859
- [x] #140733
- [x] #139533
- [x] #141862
- [x] #141858
- [x] #141674
- [x] #141673
- [x] #141623
- [x] #141621
- [x] #141605
- [x] #141577
- [x] #141572
- [x] #142003
- [x] #141409

`torch.compile` is broken out separately based on the history for Python 3.12 (see gh-110436 for general support, and gh-120233 for `torch.compile`).

The status of dependencies should be fine AFAIK. E.g. Pybind11 2.13.1 has full support, and SymPy `1.13.0rc4` has too (xref [sympy#26692](https://github.com/sympy/sympy/issues/26692)). 

For free-threaded support we should probably open a separate tracking issue once regular 3.13 support is in good shape. I'll note here that Pybind11 and NumPy already have mostly-complete support for it, and NumPy should release (experimental) wheels shortly after Python 3.13.0rc1).

cc @malfet @seemethere @albanD