本文介绍了torch.utils.ffi 已弃用.如何改用cpp扩展?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试运行使用来自 torch.utils.ffi(已弃用)的 wrap_function 的代码.我正在努力弄清楚如何按照错误消息的建议使用 cpp 扩展名,有人可以帮忙吗?

I am trying to run code that is using wrap_function from torch.utils.ffi (which has deprecated). I am struggling to figure out how to use cpp extensions instead as suggested by the error message, can any anyone help please?

我需要替换的代码:

from torch.utils.ffi import _wrap_function
from ._nms import lib as _lib, ffi as _ffi

__all__ = []
def _import_symbols(locals):
    for symbol in dir(_lib):
        fn = getattr(_lib, symbol)
        if callable(fn):
            locals[symbol] = _wrap_function(fn, _ffi)
        else:
            locals[symbol] = fn
        __all__.append(symbol)

_import_symbols(locals())

我尝试在 python 3.6 和 python 2.7 中运行代码,请参阅下面的错误消息,

I have tried running the code in both python 3.6 and python 2.7, see error message below,

  File "build.py", line 3, in <module>
    from torch.utils.ffi import create_extension
  File "/usr/local/lib/python2.7/dist-packages/torch/utils/ffi/__init__.py", line 1, in <module>
    raise ImportError("torch.utils.ffi is deprecated. Please use cpp extensions instead.")
ImportError: torch.utils.ffi is deprecated. Please use cpp extensions instead.

推荐答案

检查

from torch.utils.cpp import ....
#or
from torch.utils.cpp_extension import ....
#or
from torch.utils.cpp_extension_versioner import...

它在我的电脑上看起来不错

it looks good at my PC

这篇关于torch.utils.ffi 已弃用.如何改用cpp扩展?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-17 17:14