PyTorch MergeBot
99cc3633f6
Revert "[BE] Modify PyObjectSlot the assume only a single interpreter is in use ( #158407 )"
...
This reverts commit d9426a81d2 .
Reverted https://github.com/pytorch/pytorch/pull/158407 on behalf of https://github.com/ZainRizvi due to Sorry but this is breaking internally, see D78496147 for details. To validate your fixes internally, you can follow the instructions here: https://fburl.com/fixing-ghfirst-reverts ([comment](https://github.com/pytorch/pytorch/pull/158288#issuecomment-3099826158 ))
2025-07-21 23:17:38 +00:00
PyTorch MergeBot
15a50dcf1c
Revert "[BE] Make PyObjectSlot use a global PyInterpreter and remove ( #158427 )"
...
This reverts commit eb73650723 .
Reverted https://github.com/pytorch/pytorch/pull/158427 on behalf of https://github.com/ZainRizvi due to Reverting this as part of reverting the stack for https://github.com/pytorch/pytorch/pull/158288 ([comment](https://github.com/pytorch/pytorch/pull/158427#issuecomment-3099815367 ))
2025-07-21 23:14:57 +00:00
PaliC
eb73650723
[BE] Make PyObjectSlot use a global PyInterpreter and remove ( #158427 )
...
This PR is a bit more involved but effectively works to drastically simplify PyObjectSlot and PyInterpreter.
1) For PyObjectSlot we now use a global pyinterpreter since there only is one. From here we change all of the call sites to rely on this assumption.
2) We also remove the "tags" of the PyInterpreter by deprecating `PyInterpreterStatus`.
For the reviewer, sadly it seems like `functorch/csrc/dim/dim.cpp` needed to get linted, so there is an unreadable amount of changes there. Fortunately, the only actual change in the file is as follows which just removes `getPyInterpreter()` from the `check_pyobj` call.
```
mpy::handle handle_from_tensor(Arena& A, TensorRef t) {
- // fast case: tensor is live in python
- std::optional<PyObject*> mb_obj =
- t->unsafeGetTensorImpl()->pyobj_slot()->check_pyobj(getPyInterpreter(), /*ignore_hermetic_tls=*/false);
- if (mb_obj.has_value() && !t->unsafeGetTensorImpl()->pyobj_slot()->owns_pyobj()) {
- return *mb_obj;
- }
- return A.autorelease(mpy::object::checked_steal(THPVariable_Wrap(*t)));
-}
-}
+ // fast case: tensor is live in python
+ std::optional<PyObject*> mb_obj =
+ t->unsafeGetTensorImpl()->pyobj_slot()->check_pyobj(
+ /*ignore_hermetic_tls=*/false);
+ if (mb_obj.has_value() &&
+ !t->unsafeGetTensorImpl()->pyobj_slot()->owns_pyobj()) {
+ return *mb_obj;
+ }
+ return A.autorelease(mpy::object::checked_steal(THPVariable_Wrap(*t)));
+}
```
Pull Request resolved: https://github.com/pytorch/pytorch/pull/158427
Approved by: https://github.com/albanD
2025-07-18 05:23:00 +00:00
PaliC
d9426a81d2
[BE] Modify PyObjectSlot the assume only a single interpreter is in use ( #158407 )
...
This PR makes some less risky changes to PyObjectSlot as there is a lot of stuff we do not need since there is only one interpreter. Specifically `check_interpreter` and `has_pyobj_nonhermetic` are removed
Pull Request resolved: https://github.com/pytorch/pytorch/pull/158407
Approved by: https://github.com/albanD
ghstack dependencies: #158288 , #158290 , #158291
2025-07-17 05:56:26 +00:00
cyy
4a019047ad
Enable nested namespace check in clang-tidy ( #118506 )
...
It is time to enable nested namespaces in the code.
Pull Request resolved: https://github.com/pytorch/pytorch/pull/118506
Approved by: https://github.com/albanD
2024-01-31 00:32:35 +00:00
Kurt Mohler
4c5e43574c
Reland 2: Add PyObject preservation for UntypedStorage ( #109039 )
...
Relands #103907 after it was reverted. This PR makes the new `ignore_hermetic_tls` argument of `check_pyobj` optional to avoid causing a compilation error in torchdistx
Part of #91395
Pull Request resolved: https://github.com/pytorch/pytorch/pull/109039
Approved by: https://github.com/ezyang
2023-09-12 22:26:05 +00:00
PyTorch MergeBot
59f605be57
Revert "Reland 2: Add PyObject preservation for UntypedStorage ( #109039 )"
...
This reverts commit 419e4e17a2 .
Reverted https://github.com/pytorch/pytorch/pull/109039 on behalf of https://github.com/huydhn due to Sorry for reverting your change but it is failing linter job in trunk, probably due to a landrace ([comment](https://github.com/pytorch/pytorch/pull/109039#issuecomment-1715147020 ))
2023-09-12 07:26:11 +00:00
Kurt Mohler
419e4e17a2
Reland 2: Add PyObject preservation for UntypedStorage ( #109039 )
...
Relands #103907 after it was reverted. This PR makes the new `ignore_hermetic_tls` argument of `check_pyobj` optional to avoid causing a compilation error in torchdistx
Part of #91395
Pull Request resolved: https://github.com/pytorch/pytorch/pull/109039
Approved by: https://github.com/ezyang
2023-09-12 01:19:40 +00:00
PyTorch MergeBot
68238606f3
Revert "Reland: Add PyObject preservation for UntypedStorage ( #103907 )"
...
This reverts commit 56b848157c .
Reverted https://github.com/pytorch/pytorch/pull/103907 on behalf of https://github.com/huydhn due to Sorry for reverting your change, but it is failing torchdistx build which uses check_pyobj here 9c1b9f5cb2/src/python/torchdistx/_C/deferred_init.cc (L87) ([comment](https://github.com/pytorch/pytorch/pull/103907#issuecomment-1712121158 ))
2023-09-08 19:27:07 +00:00
Kurt Mohler
56b848157c
Reland: Add PyObject preservation for UntypedStorage ( #103907 )
...
This relands #97470 after #102553 reverted it. This PR attempts to fix the internal failure by avoiding an unnecessary intermediate storage buffer allocation in `c10::newStorageImplFromRefcountedDataPtr`.
Part of #91395
Pull Request resolved: https://github.com/pytorch/pytorch/pull/103907
Approved by: https://github.com/ezyang
2023-09-07 04:24:11 +00:00
Shiyan Deng
685505353a
Back out "Add PyObject preservation for UntypedStorage ( #97470 )" ( #102553 )
...
Summary:
Original commit changeset: c24708d18ccb
Original Phabricator Diff: D46159983
Test Plan: SL tests and CI
Differential Revision: D46284986
Pull Request resolved: https://github.com/pytorch/pytorch/pull/102553
Approved by: https://github.com/DanilBaibak
2023-06-01 17:23:43 +00:00
Kurt Mohler
5fe629e314
Add PyObject preservation for UntypedStorage ( #97470 )
...
Part of #91395
Pull Request resolved: https://github.com/pytorch/pytorch/pull/97470
Approved by: https://github.com/ezyang
2023-05-23 01:27:30 +00:00
cyy
37f7c00a8a
More fixes and improved clang-tidy checkers ( #93213 )
...
Pull Request resolved: https://github.com/pytorch/pytorch/pull/93213
Approved by: https://github.com/Skylion007
2023-02-01 14:44:17 +00:00
Kurt Mohler
3a0053abd6
Move PyObject code out of TensorImpl into new PyObjectSlot class ( #92169 )
...
Redo of PR #92099
Part of #91395
Pull Request resolved: https://github.com/pytorch/pytorch/pull/92169
Approved by: https://github.com/albanD
2023-01-14 02:55:32 +00:00