@@ -14,6 +14,50 @@ adoption of existing PyTorch applications with zero-code changes on
14
14
out-of-tree devices. For more information,
15
15
see `[RFC] Autoload Device Extension <https://github.com/pytorch/pytorch/issues/122468 >`_.
16
16
17
+ .. note ::
18
+
19
+ This feature is enabled by default and can be disabled using
20
+ ``export TORCH_DEVICE_BACKEND_AUTOLOAD=0 ``.
21
+ If you get an error like this: "Failed to load the backend extension",
22
+ this error has nothing to do with PyTorch, you should disable this feature
23
+ and ask the out-of-tree extension maintainer for help.
24
+
25
+ How to apply this mechanism to out-of-tree extensions?
26
+ --------------------------------------------
27
+
28
+ For example, if you have a backend named ``foo `` and a package named
29
+ ``torch_foo ``. Make sure your package is based on PyTorch 2.5+ and includes
30
+ the following in its ``__init__.py ``:
31
+
32
+ .. code-block :: python
33
+
34
+ def _autoload ():
35
+ print (" No need to import torch_foo anymore! You can run torch.foo.is_available() directly." )
36
+
37
+ Then the only thing you need to do is add an entry point to your Python
38
+ package:
39
+
40
+ .. code-block :: python
41
+
42
+ setup(
43
+ name = " torch_foo" ,
44
+ version = " 1.0" ,
45
+ entry_points = {
46
+ " torch.backends" : [
47
+ " torch_foo = torch_foo:_autoload" ,
48
+ ],
49
+ }
50
+ )
51
+
52
+ Now the ``torch_foo `` module can be imported when running import torch:
53
+
54
+ .. code-block :: python
55
+
56
+ >> > import torch
57
+ No need to import torch_foo anymore! You can run torch.foo.is_available() directly.
58
+ >> > torch.foo.is_available()
59
+ True
60
+
17
61
Examples
18
62
^^^^^^^^
19
63
@@ -63,49 +107,6 @@ in ``torch/__init__.py`` that are defined by out-of-tree extensions.
63
107
Its implementation is in `[RFC] Add support for device extension autoloading
64
108
<https://github.com/pytorch/pytorch/pull/127074> `_.
65
109
66
- .. note ::
67
-
68
- This feature is enabled by default and can be disabled using
69
- ``export TORCH_DEVICE_BACKEND_AUTOLOAD=0 ``.
70
- If you get an error like this: "Failed to load the backend extension",
71
- this error has nothing to do with PyTorch, you should disable this feature
72
- and ask the out-of-tree extension maintainer for help.
73
-
74
- How to apply this to out-of-tree extensions?
75
- --------------------------------------------
76
-
77
- For example, if you have a backend named ``foo `` and a package named
78
- ``torch_foo ``, and your package includes the following in its ``__init__.py ``:
79
-
80
- .. code-block :: python
81
-
82
- def _autoload ():
83
- print (" No need to import torch_foo anymore! You can run torch.foo.is_available() directly." )
84
-
85
- Then the only thing you need to do is add an entry point to your Python
86
- package.
87
-
88
- .. code-block :: python
89
-
90
- setup(
91
- name = " torch_foo" ,
92
- version = " 1.0" ,
93
- entry_points = {
94
- " torch.backends" : [
95
- " torch_foo = torch_foo:_autoload" ,
96
- ],
97
- }
98
- )
99
-
100
- Now the ``torch_foo `` module can be imported when running import torch.
101
-
102
- .. code-block :: python
103
-
104
- >> > import torch
105
- No need to import torch_foo anymore! You can run torch.foo.is_available() directly.
106
- >> > torch.foo.is_available()
107
- True
108
-
109
110
Conclusion
110
111
----------
111
112
0 commit comments