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

Ouverte
#96 0 commentaires 1 réaction 0 personnes assignées Voir sur GitHub

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
35/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
cpp, python
Domaine
build-system

Piste de recherche

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.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

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.

Langage dominant
Python
Étoiles
1.2k
Forks
250
Métriques de merge des PR
Aucune PR mergée en 30 j

Préparer son environnement

Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de pytorch/extension-cpp

Toutes les issues de pytorch/extension-cpp

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.