mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
Modernize the development installation:
```bash
# python setup.py develop
python -m pip install --no-build-isolation -e .
# python setup.py install
python -m pip install --no-build-isolation .
```
Now, the `python setup.py develop` is a wrapper around `python -m pip install -e .` since `setuptools>=80.0`:
- pypa/setuptools#4955
`python setup.py install` is deprecated and will emit a warning during run. The warning will become an error on October 31, 2025.
- 9c4d383631/setuptools/command/install.py (L58-L67)
> ```python
> SetuptoolsDeprecationWarning.emit(
> "setup.py install is deprecated.",
> """
> Please avoid running ``setup.py`` directly.
> Instead, use pypa/build, pypa/installer or other
> standards-based tools.
> """,
> see_url="https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html",
> due_date=(2025, 10, 31),
> )
> ```
- pypa/setuptools#3849
Additional Resource:
- [Why you shouldn't invoke setup.py directly](https://blog.ganssle.io/articles/2021/10/setup-py-deprecated.html)
Pull Request resolved: https://github.com/pytorch/pytorch/pull/156027
Approved by: https://github.com/ezyang
PyTorch OpenReg
This folder contains a self-contained example of a PyTorch out-of-tree backend leveraging the "PrivateUse1" backend from core.
How to use
Install as standalone with python -m pip install -e .
(or python -m pip install .
)
from this folder. You can run test via python {PYTORCH_ROOT_PATH}/test/test_openreg.py
.
Design principles
For simplicity anything that can be implemented from python is done so. A real implementation will most likely want to call these different APIs from c++ directly.
The current version sends everything back to python and contains enough implementation to run basic model, transfer host/device and printing.
The codebase is split as follows:
pytorch_openreg/__init__.py
- imports torch to get core state initialized.
- imports
._aten_impl
to register our aten op implementations to torch. - imports
.C
to load our c++ extension that registers more ops, allocator and hooks. - renames the PrivateUse1 backend and register our python-side module.
pytorch_openreg/_aten_impl.py
- Define a new
torch.Library
that registers a fallback that will be called whenever a backend kernel for PrivateUse1 is called. It contains the logic to handle all kind of native functions, computing the output metadata, allocating it and only calling into the device daemon to perform computation.
- Define a new
pytorch_openreg/_device_daemon.py
- contains the Allocator (responsible for allocating memory on the device side and host side, as int8 buffers).
- contains
Driver
, which as user-process driver to deal with some information needed to be done in driver. - contains
Executor
, which as device-process exector to do something related device logic.
pytorch_openreg/_meta_parser.py
mainly contain utilities to send objects over the wire from the user process to the device process.- The main class there is
OpenRegTensorMeta
that contains all the metadata sent to the device which should be enough for it to populate the output Tensor.
- The main class there is
Next steps
The main next step would be to:
- Replace the current
open_registration_extension.cpp
test in PyTorch CI with this.