Pytorch Out of tree backend updates/changes question

Since I try to run OpenCL backend on 2.4/nightly I have things I can’t understand and I can’t find reference there: rfcs/RFC-0037-Interoperability-Standard-of-3rd-Backend-Integration-Mechanism.md at 9bd181e74225af94547c9fefcbeeca1cae907193 · pytorch/rfcs · GitHub

I indeed need to change one of the Allocator method to non-cost but other issues keeps me failing.

After I load the module and run trivial test like this

import torch
import numpy as np

torch.ops.load_library("build/libpt_ocl.so")
torch.utils.rename_privateuse1_backend('ocl')
torch.utils.generate_methods_for_privateuse1_backend()
dev='ocl:0'
t1=torch.ones((20,10),device=dev)

It fails with an error:

 File "/home/artik/Projects/dlprim_backend/test.py", line 8, in <module>
    t1=torch.ones((20,10),device=dev)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ModuleNotFoundError: No module named 'torch.ocl'

Same happens if I try to load it like this

import torch
import numpy as np
from build import ocl
torch.utils.rename_privateuse1_backend('ocl')
torch.utils.generate_methods_for_privateuse1_backend()
dev='ocl:0'
t1=torch.ones((20,10),requires_grad=True,device=dev)

or even try to add torch.ocl = ocl line

What do I miss

Same issue with example I found Failure to run and build in nightly 2.4 · Issue #7 · bdhirsh/pytorch_open_registration_example · GitHub

Anybody? @albanD

I don’t even understand where the torch tries to access torch.BACKENDNAME - it isn’t shown in the stack trace

Hey!

Sorry about that, it seems like the doc is not up to date at torch.utils.rename_privateuse1_backend — PyTorch 2.3 documentation and we should always register this module, not just for amp.

In this case, adding a simple

torch._register_device_module("ocl", object())

after renaming the backend fixes the issue.

Can you open an issue on the pytorch/pytorch repo as well so we can fix this. We shouldn’t require this module if we don’t access anything on it!

Ok thanks. I missed this register_device_module. Thanks!

Now it passes this stage