XNNPACK 后端常见问题排查方法

介绍 ExecuTorch 中 XNNPACK 后端的三类常见问题:后端未注册的编译链接原因、推理变慢的线程与算子分析手段,以及算子未被分区委托时的调试日志开启方式。

## 解决问题[#](<https://docs.pytorch.org/executorch/stable/backends/xnnpack/xnnpack-troubleshooting.html#troubleshooting>) 本页面介绍您在使用XNNPACK后端时可能遇到的常见问题,以及如何调试和解决这些问题. ## XNNPACK 后端未找到[#](<https://docs.pytorch.org/executorch/stable/backends/xnnpack/xnnpack-troubleshooting.html#xnnpack-backend-not-found>) 此错误表明 XNNPACK 后端没有在运行时间注册。 这可能是因为后端没有编译或链接, 或者是注册代码被优化了 。 XNNPACK后端默认为Python,Android,iOS以及大多数CMake预设中构建. - 设定 `EXECUTORCH_BUILD_XNNPACK=ON` 从源创建时 CMake 选项 。 - 要么在 CMake 配置中传递选项,要么在包含 ExecuTorch 之前在用户 CMake 逻辑中设置选项 。 - 见 [建置来源](<https://docs.pytorch.org/executorch/stable/using-executorch-building-from-source.html>). - 在iOS上,链接到 `backend_xnnpack` [框架](<https://docs.pytorch.org/executorch/stable/using-executorch-ios.html>). - 如果仍然找不到后端, 请链接到 `WHOLE_ARCHIVE`. - 过 `"LINK_LIBRARY:WHOLE_ARCHIVE,xnnpack_backend>"` 改为: `target_link_libraries` 在CMake中。 (中文(简体) ). ## 缓慢的性能[#](<https://docs.pytorch.org/executorch/stable/backends/xnnpack/xnnpack-troubleshooting.html#slow-performance>) - 尝试使用线程计数 [不安全_ 重置_ 线程池](<https://docs.pytorch.org/executorch/stable/using-executorch-faqs.html#inference-is-slow-performance-troubleshooting>). - 小模型可能从使用比默认更少的线程中受益. - 尝试在 1 和 4 线程之间的值,并在您的模型上测量性能. - 使用( U) [业务层面的概况](<https://docs.pytorch.org/executorch/stable/tutorials/devtools-integration-tutorial.html>) 以了解哪些操作员花费的时间最多。 - XNNPACK后端为委托运营商提供运营商级别的时间. - 参见一般性能故障解析提示 [处理性能问题](<https://docs.pytorch.org/executorch/stable/using-executorch-faqs.html#inference-is-slow-performance-troubleshooting>). ## 调试节点为何不分区[#](<https://docs.pytorch.org/executorch/stable/backends/xnnpack/xnnpack-troubleshooting.html#debugging-why-nodes-are-not-partitioned>) - 要调试操作员未被授权给 XNNPACK 的案件, 您可以先启用内部调试日志 。 **to_edge_transform_and_lower** 从分区器中。 这将打印诊断信息, 解释特定节点为何无法分区 。 ``` # caption: Enable internal partition debug logging import logging logger = logging.getLogger("executorch.backends.xnnpack.partition") logger.setLevel(logging.DEBUG) if not logger.handlers: ch = logging.StreamHandler() ch.setLevel(logging.DEBUG) formatter = logging.Formatter("[%(levelname)s] %(name)s: %(message)s") ch.setFormatter(formatter) logger.addHandler(ch) ```

查看原始来源