forked from pytorch/pytorch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[RFC] Add support for device extension autoloading (pytorch#127074)
Fixes pytorch#122468 - Load device extensions at the end of `torch/__init__.py` - Enabled by default, or you can disable it with `TORCH_DEVICE_BACKEND_AUTOLOAD=0` run test: ```python python test/run_test.py -i test_autoload_enable python test/run_test.py -i test_autoload_disable ``` doc: https://docs-preview.pytorch.org/pytorch/pytorch/127074/miscellaneous_environment_variables.html co-author: @jgong5 @bsochack @bkowalskiINTEL @jczaja @FFFrog @hipudding Co-authored-by: albanD <[email protected]> Co-authored-by: Jiong Gong <[email protected]> Pull Request resolved: pytorch#127074 Approved by: https://github.com/albanD, https://github.com/jgong5
- Loading branch information
1 parent
6c4efd4
commit 312652c
Showing
7 changed files
with
136 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
""" | ||
This is a device backend extension used for testing. | ||
See this RFC: https://github.com/pytorch/pytorch/issues/122468 | ||
""" | ||
|
||
import os | ||
|
||
|
||
def _autoload(): | ||
# Set the environment variable to true in this entrypoint | ||
os.environ["IS_CUSTOM_DEVICE_BACKEND_IMPORTED"] = "1" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Owner(s): ["module: PrivateUse1"] | ||
|
||
import os | ||
|
||
from torch.testing._internal.common_utils import run_tests, TestCase | ||
|
||
|
||
class TestDeviceBackendAutoload(TestCase): | ||
def test_autoload(self): | ||
switch = os.getenv("TORCH_DEVICE_BACKEND_AUTOLOAD", "0") | ||
|
||
# After importing the extension, the value of this environment variable should be true | ||
# See: test/cpp_extensions/torch_test_cpp_extension/__init__.py | ||
is_imported = os.getenv("IS_CUSTOM_DEVICE_BACKEND_IMPORTED", "0") | ||
|
||
# Both values should be equal | ||
self.assertEqual(is_imported, switch) | ||
|
||
|
||
if __name__ == "__main__": | ||
run_tests() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters