# find\_package(Torch REQUIRED) fails - 2.3.1 and nightly

**URL:** <https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176>\
**Category:** hardware-backends\
**Created:** [June 24, 2024, 8:49pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176 "2024-06-24T20:49:13Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![artyom-beilis](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/artyom-beilis/32/207_2.png) [@artyom-beilis](https://dev-discuss.pytorch.org/u/artyom-beilis)\
**Post date:** [June 24, 2024, 8:49pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/1 "2024-06-24T20:49:13Z")

</div>

I’m trying to build dlprimitives/opencl backend for pytorch for 2.3.1 or nightly but it fails in find package

I run cmake:

```
cmake -DCMAKE_PREFIX_PATH=$VIRTUAL_ENV/lib/python3.12/site-packages/torch/share/cmake/Torch ..

```

And get error:

```auto
CMake Error at /home/artik/Projects/venv/pt_3.12_nightly/lib/python3.12/site-packages/torch/share/cmake/Caffe2/public/mkl.cmake:8 (target_include_directories):
  Cannot specify include directories for imported target "caffe2::mkl".
Call Stack (most recent call first):
  /home/artik/Projects/venv/pt_3.12_nightly/lib/python3.12/site-packages/torch/share/cmake/Caffe2/Caffe2Config.cmake:106 (include)
  /home/artik/Projects/venv/pt_3.12_nightly/lib/python3.12/site-packages/torch/share/cmake/Torch/TorchConfig.cmake:68 (find_package)
  CMakeLists.txt:4 (find_package)

```

How can I address this issues?

---

<div class="post-metadata">

**Author:** ![albanD](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/alband/32/9_2.png) [@albanD](https://dev-discuss.pytorch.org/u/albanD)\
**Post date:** [June 25, 2024, 4:50pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/2 "2024-06-25T16:50:10Z")

</div>

Hey!  
I’m not 100% sure but due to the full removal caffe2, some of these cmake and includes have moved. You might need to update the build on your end if you’re pointing to some of these explicitly?

Also I would mention recent discussions on out of tree backend that didn’t exist a long time ago: [RFC-0037-Interoperability-Standard-of-3rd-Backend-Integration-Mechanism by FFFrog · Pull Request #64 · pytorch/rfcs · GitHub](https://github.com/pytorch/rfcs/pull/64) and [torch.utils.rename\_privateuse1\_backend — PyTorch main documentation](https://pytorch.org/docs/main/generated/torch.utils.rename_privateuse1_backend.html#torch.utils.rename_privateuse1_backend).  
Other improvements that are WIP to automatically load these extensions and make them work without an explicit import statement. And also the new unified torch.Stream/torch.Event API to allow more device-generic code.

---

<div class="post-metadata">

**Author:** ![artyom-beilis](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/artyom-beilis/32/207_2.png) [@artyom-beilis](https://dev-discuss.pytorch.org/u/artyom-beilis)\
**Post date:** [June 25, 2024, 4:51pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/3 "2024-06-25T16:51:35Z")

</div>

OK I have just found that I used too old cmake, with cmake 3.26 it passed.

But now I have other issues - GCC is too old. It looks I’ll have to upgrade from Ubuntu 18.04 sooner or later… probably sooner that I wanted to `:-)`

---

<div class="post-metadata">

**Author:** ![artyom-beilis](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/artyom-beilis/32/207_2.png) [@artyom-beilis](https://dev-discuss.pytorch.org/u/artyom-beilis)\
**Post date:** [June 25, 2024, 4:58pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/4 "2024-06-25T16:58:47Z")

</div>

> [@albanD](#):
>
> Also I would mention recent discussions on out of tree backend that didn’t exist a long time ago: [RFC-0037-Interoperability-Standard-of-3rd-Backend-Integration-Mechanism by FFFrog · Pull Request #64 · pytorch/rfcs · GitHub](https://github.com/pytorch/rfcs/pull/64) and [torch.utils.rename\_privateuse1\_backend — PyTorch main documentation](https://pytorch.org/docs/main/generated/torch.utils.rename_privateuse1_backend.html#torch.utils.rename_privateuse1_backend).  
> Other improvements that are WIP to automatically load these extensions and make them work without an explicit import statement. And also the new unified torch.Stream/torch.Event API to allow more device-generic code.

Ok very interesting I really need to read it into details 🙂

thanks…

---

<div class="post-metadata">

**Author:** ![artyom-beilis](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/artyom-beilis/32/207_2.png) [@artyom-beilis](https://dev-discuss.pytorch.org/u/artyom-beilis)\
**Post date:** [June 25, 2024, 6:11pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/5 "2024-06-25T18:11:39Z")

</div>

Ok… it seems lots have changed. My current code does not work with nightly.

```auto
 File "/home/artik/Projects/venv/pt_3.12_nightly/lib/python3.12/site-packages/torch/nn/modules/module.py", line 1165, in convert
    return t.to(
           ^^^^^
ModuleNotFoundError: No module named 'torch.ocl'

```

For 2.3.1 it is

```auto
RuntimeError: Please register PrivateUse1HooksInterface by `RegisterPrivateUse1HooksInterface` first.

```

And reading the manual a looot have changes.

Is there any digest or way to know about these updates? Maybe mailing list.

It seems the opencl backend now works only with 1.13 (I think it worked with 2.0 and 2.1)

Thanks

---

<div class="post-metadata">

**Author:** ![albanD](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/alband/32/9_2.png) [@albanD](https://dev-discuss.pytorch.org/u/albanD)\
**Post date:** [July 1, 2024, 1:38pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/6 "2024-07-01T13:38:30Z")

</div>

Hey!

Yes the “PrivateUse1HooksInterface” will allow you to control a lot more components than you were able to before!  
AFAIK [GitHub - Ascend/torch\_npu](https://github.com/Ascend/torch_npu) is the most extensive end to end example of using this new API.

---

<div class="post-metadata">

**Author:** ![artyom-beilis](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/artyom-beilis/32/207_2.png) [@artyom-beilis](https://dev-discuss.pytorch.org/u/artyom-beilis)\
**Post date:** [July 1, 2024, 4:17pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/7 "2024-07-01T16:17:28Z")

</div>

> AFAIK [GitHub - Ascend/torch\_npu](https://github.com/Ascend/torch_npu) is the most extensive end to end example of using this new API.

Ok, thanks I will look into it.

Probably will come with some more questions. At least there is a progress 🙂

Really need some mailing list/push updates or something to know when there are breaking changes in Out of Tree backend support.

---

<div class="post-metadata">

**Author:** ![albanD](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/alband/32/9_2.png) [@albanD](https://dev-discuss.pytorch.org/u/albanD)\
**Post date:** [July 2, 2024, 6:32pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/8 "2024-07-02T18:32:56Z")

</div>

Yes I would definitely agree with that. Could you leave a comment to that effect on the RFC so that we don’t forget to setup some mechanism for this?

---

<div class="post-metadata">

**Author:** ![artyom-beilis](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/artyom-beilis/32/207_2.png) [@artyom-beilis](https://dev-discuss.pytorch.org/u/artyom-beilis)\
**Post date:** [July 2, 2024, 7:04pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/9 "2024-07-02T19:04:14Z")

</div>

thanks, I added a comment to the RFC

---

<div class="post-metadata">

**Author:** ![artyom-beilis](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/artyom-beilis/32/207_2.png) [@artyom-beilis](https://dev-discuss.pytorch.org/u/artyom-beilis)\
**Post date:** [August 6, 2024, 2:29pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/10 "2024-08-06T14:29:19Z")

</div>

Ok I added very basic hooks interface and now it looks I can work with 2.4.

> <https://github.com/artyom-beilis/pytorch_dlprim/blob/master/src/registeration.cpp#L84>

I have two problems

1. _For some reasons all devices accessed even if I use only one of them_ looks like my bug
2. I badly need documentation about functionality. Prior to this everything was implemented using `DeviceGuardImplInterface` and now relations with Hooks isn’t really clear. While I can see goodies related to seeding/RNG the rest isn’t that clear

I think I’ll add on github discussion.

---

<div class="post-metadata">

**Author:** ![albanD](https://yyz2.discourse-cdn.com/flex036/user_avatar/dev-discuss.pytorch.org/alband/32/9_2.png) [@albanD](https://dev-discuss.pytorch.org/u/albanD)\
**Post date:** [August 6, 2024, 8:35pm UTC](https://dev-discuss.pytorch.org/t/find-package-torch-required-fails-2-3-1-and-nightly/2176/11 "2024-08-06T20:35:31Z")

</div>

[torch.utils.rename\_privateuse1\_backend — PyTorch 2.4 documentation](https://pytorch.org/docs/stable/generated/torch.utils.rename_privateuse1_backend.html#torch.utils.rename_privateuse1_backend) (and the pages linked from there) give some details but a lot is missing indeed.

I am hopping that this stack of PRs [Add device daemon by albanD · Pull Request #131814 · pytorch/pytorch · GitHub](https://github.com/pytorch/pytorch/pull/131814) , by providing a fully working example, will provide some much needed insights into what is happening.  
It is still WIP progress though (see the readme there for the state and next steps).
