JIT-compiling the extension results in non-functional Python module.

Đang mở
#96 0 bình luận 1 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp, python
Lĩnh vực
build-system

Hướng nghiên cứu

The problem is the empty PYBIND11_MODULE block in extension_cpp/csrc/muladd.cpp, which the reporter loads with torch.utils.cpp_extension.load. Start by reading how load treats is_python_module and whether the module's def calls are what expose functions on the returned Python module. Done means extension_cpp.mymuladd resolves after load, and torch.ops.extension_cpp.mymuladd still works.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

When submitting a bug report, please include the following information (where relevant):

  • OS: Arch Linux
  • PyTorch version: 2.3.0
  • How you installed PyTorch (conda, pip, source): conda
  • Python version: 3.12
  • CUDA/cuDNN version: 12.1 (runtime) / 8.9.2
  • GPU models and configuration: 1070 Ti
  • GCC version (if compiling from source): /

When using torch.utils.cpp_extension.load to JIT compile the extension, the returned module does not provide access to the exported functions.
Code to reproduce (in interactive Python session with working directory extension-cpp):

>>> import torch
>>> from torch.utils.cpp_extension import load
>>> extension_cpp = load(name="extension_cpp", sources=["extension_cpp/csrc/muladd.cpp"])
>>> extension_cpp.mymuladd
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'extension_cpp' has no attribute 'mymuladd'

Note that after the loading, the following does work:

>>> torch.ops.extension_cpp.mymuladd
<OpOverloadPacket(op='extension_cpp.mymuladd')>

I.e., load does seem to have the side-effect of loading the PyTorch op (similar to setting is_python_module=False), but does not provide the functions in the Python module.
I would expect to be able to use extension_cpp in the same way as torch.ops.extension_cpp.

I suspect that this issue is due to the empty PYBIND11_MODULE block.
This seems to be confirmed by the fact that the following modification in muladd.cpp makes extension_cpp.mymuladd available:

PYBIND11_MODULE(TORCH_EXTENSION_NAME, m) {
  m.def("mymuladd", &mymuladd_cpu, "custom pytorch operation 'muladd'");
  m.def("mymul", &mymuladd_cpu, "custom pytorch operation 'mul'");
  m.def("myadd_out", &mymuladd_cpu, "custom pytorch operation 'add_out'");
}

However, I am not sure if this is just a workaround or the actual bug-fix.

Ngôn ngữ chính
Python
Star
1.2k
Fork
250
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của pytorch/extension-cpp

Tất cả issue của pytorch/extension-cpp

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.