Re-enable building under a free-threaded Python interpreter#4537
Conversation
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
🔗 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. ❌ 1 Awaiting Approval, 1 New FailureAs of commit 796003f with merge base 9b3684a ( NEW FAILURE - The following job has failed:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@claude review, why was the original PR reverted? |
|
Claude finished @vkuzo's task in 1m 37s —— View job Review + answer
Why was the original PR reverted?It wasn't reverted on purpose — it was collateral damage from a whole-file revert, per the PR description and the commit graph:
So the free-threading support was never intentionally rejected — it was overwritten by a coarse-grained revert that reset the entire file. This PR cherry-picks Review of the changeThe change is small, correct, and internally consistent. It funnels every use of
All the Minor observations (non-blocking):
Verdict: LGTM. The revert was accidental (whole-file snapshot in #4446), and re-applying it here is the right fix. I couldn't run the build under a free-threaded interpreter in this environment to empirically confirm, but the logic is sound and matches the documented approach. |
|
lgtm! and sorry for long delay, I was OOO and now back. Could you please fix |
|
Reformatted with ruff, check passes without errors. |
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,
torchaobuilds fine.The
is_freethreadedfunction 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_x86base; the only adaptation from the original is the placement ofis_freethreaded()(both functions are kept).(cherry picked from commit f43befe)