FAQ#
Listed below are a number of common issues users face with the various parts ofthe C++ API.
C++ Extensions#
Undefined symbol errors from PyTorch/ATen#
Problem: You import your extension and get anImportError stating thatsome C++ symbol from PyTorch or ATen is undefined. For example:
>>>importextensionTraceback(mostrecentcalllast):File"<stdin>",line1,in<module>ImportError:/home/user/.pyenv/versions/3.7.1/lib/python3.7/site-packages/extension.cpython-37m-x86_64-linux-gnu.so:undefinedsymbol:_ZN2at19UndefinedTensorImpl10_singletonE
Fix: The fix is toimporttorch before you import your extension. This will makethe symbols from the PyTorch dynamic (shared) library that your extensiondepends on available, allowing them to be resolved once you import your extension.
I created a tensor using a function fromat:: and get errors#
Problem: You created a tensor using e.g.at::ones orat::randn orany other tensor factory from theat:: namespace and are getting errors.
Fix: Replaceat:: withtorch:: for factory function calls. Youshould never use factory functions from theat:: namespace, as they willcreate tensors. The correspondingtorch:: functions will create variables,and you should only ever deal with variables in your code.