Skip to content

Re-enable building under a free-threaded Python interpreter#4537

Open
nascheme wants to merge 1 commit into
pytorch:mainfrom
nascheme:free-threaded-api-build
Open

Re-enable building under a free-threaded Python interpreter#4537
nascheme wants to merge 1 commit into
pytorch:mainfrom
nascheme:free-threaded-api-build

Conversation

@nascheme

Copy link
Copy Markdown

This PR re-applies the changes from #4428.

Free-threaded interpreters do not support the CPython Limited C API, and hence use of the limited API has to be disabled. With this one change, torchao builds fine.

The is_freethreaded function is in widespread use, and documented as the canonical way of doing this check here:
https://py-free-threading.github.io/running-gil-disabled/#check-if-using-a-free-threaded-build

PR #4428 (commit f43befe) was inadvertently reverted by #4446 ("Back out D105996100 — breaks fbpkg build light_cli"). That back-out was meant to revert only the multi-ISA work in #4159 (D105996100), but instead of computing a reverse diff it restored a whole-file snapshot of setup.py that predated both #4159 and #4428, silently clobbering the free-threading support.

Re-applied on top of the current add_options_for_x86 base; the only adaptation from the original is the placement of is_freethreaded() (both functions are kept).

(cherry picked from commit f43befe)

Free-threaded interpreters do not support the CPython Limited C API,
and hence use of the limited API has to be disabled. With this
one change, `torchao` builds fine.

The `is_freethreaded` function is in widespread use, and documented
as the canonical way of doing this check here:
https://py-free-threading.github.io/running-gil-disabled/#check-if-using-a-free-threaded-build

This re-applies pytorch#4428 (commit f43befe), which was inadvertently
reverted by pytorch#4446 ("Back out D105996100 — breaks `fbpkg build
light_cli`"). That back-out was meant to revert only the multi-ISA
work in pytorch#4159 (D105996100), but instead of computing a reverse diff
it restored a whole-file snapshot of setup.py that predated both
pytorch#4159 and pytorch#4428, silently clobbering the free-threading support.

Re-applied on top of the current `add_options_for_x86` base; the only
adaptation from the original is the placement of `is_freethreaded()`
(both functions are kept).

(cherry picked from commit f43befe)

Assisted-by: Claude
@pytorch-bot

pytorch-bot Bot commented Jun 26, 2026

Copy link
Copy Markdown

🔗 Helpful Links

🧪 See artifacts and rendered test results at hud.pytorch.org/pr/pytorch/ao/4537

Note: Links to docs will display an error until the docs builds have been completed.

This comment was automatically generated by Dr. CI and updates every 15 minutes.

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Jun 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants