From 106be6931e4d3478de4c7417a9691e057070f595 Mon Sep 17 00:00:00 2001 From: Peter Goldsborough Date: Wed, 24 Oct 2018 10:22:38 -0700 Subject: [PATCH 1/2] Create FAQ for C++ extensions --- advanced_source/cpp_extension.rst | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/advanced_source/cpp_extension.rst b/advanced_source/cpp_extension.rst index 5a4b7242e4d..8b040342bab 100644 --- a/advanced_source/cpp_extension.rst +++ b/advanced_source/cpp_extension.rst @@ -1033,3 +1033,34 @@ mechanism as well as a motivation for using them. You can find the code examples displayed in this note `here `_. If you have questions, please use `the forums `_. + +FAQ +--- + +Listed below are a number of common issues users face with C++ extensions. + +Undefined symbol errors from PyTorch/ATen/Caffe2 +================================================ + +**Problem**: You import your extension and get an ``ImportError`` stating that +some C++ symbol from PyTorch or ATen is undefined. For example:: + + >>> import extension + Traceback (most recent call last): + File "", line 1, in + ImportError: /home/user/.pyenv/versions/3.7.1/lib/python3.7/site-packages/extension.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZN2at19UndefinedTensorImpl10_singletonE + +**Fix**: The fix is to ``import torch`` before you import your extension. This will make +the symbols from the PyTorch dynamic (shared) library that your extension +depends on available, allowing them to be resolved once you import your extension. + +I created a tensor using a function from ``at::`` and get errors +================================================================ + +**Problem**: You created a tensor using e.g. ``at::ones`` or ``at::randn`` or +any other tensor factory from the ``at::`` namespace and are getting errors. + +**Fix**: Replace ``at::`` with ``torch::`` for factory function calls. You +should never use factory functions from the ``at::`` namespace, as they will +create tensors. The corresponding ``torch::`` functions will create variables, +and you should only ever deal with variables in your code. From 74547676d5cf66be0b48333acb728d47ba6c1236 Mon Sep 17 00:00:00 2001 From: Peter Goldsborough Date: Thu, 25 Oct 2018 09:35:00 -0700 Subject: [PATCH 2/2] Link to FAQ instead of embedding it --- advanced_source/cpp_extension.rst | 40 ++++--------------------------- 1 file changed, 5 insertions(+), 35 deletions(-) diff --git a/advanced_source/cpp_extension.rst b/advanced_source/cpp_extension.rst index 8b040342bab..8790f4cd452 100644 --- a/advanced_source/cpp_extension.rst +++ b/advanced_source/cpp_extension.rst @@ -1029,38 +1029,8 @@ Conclusion ---------- You should now be equipped with a good overview of PyTorch's C++ extension -mechanism as well as a motivation for using them. You can find the code examples -displayed in this note `here -`_. If you have -questions, please use `the forums `_. - -FAQ ---- - -Listed below are a number of common issues users face with C++ extensions. - -Undefined symbol errors from PyTorch/ATen/Caffe2 -================================================ - -**Problem**: You import your extension and get an ``ImportError`` stating that -some C++ symbol from PyTorch or ATen is undefined. For example:: - - >>> import extension - Traceback (most recent call last): - File "", line 1, in - ImportError: /home/user/.pyenv/versions/3.7.1/lib/python3.7/site-packages/extension.cpython-37m-x86_64-linux-gnu.so: undefined symbol: _ZN2at19UndefinedTensorImpl10_singletonE - -**Fix**: The fix is to ``import torch`` before you import your extension. This will make -the symbols from the PyTorch dynamic (shared) library that your extension -depends on available, allowing them to be resolved once you import your extension. - -I created a tensor using a function from ``at::`` and get errors -================================================================ - -**Problem**: You created a tensor using e.g. ``at::ones`` or ``at::randn`` or -any other tensor factory from the ``at::`` namespace and are getting errors. - -**Fix**: Replace ``at::`` with ``torch::`` for factory function calls. You -should never use factory functions from the ``at::`` namespace, as they will -create tensors. The corresponding ``torch::`` functions will create variables, -and you should only ever deal with variables in your code. +mechanism as well as a motivation for using them. You can find the code +examples displayed in this note `here +`_. If you have questions, please use +`the forums `_. Also be sure to check our `FAQ +`_ in case you run into any issues.