windows - 使用 LTCG 构建 TensorFlow
问题描述
我正在尝试使用启用了 LTCG(链接时间代码生成)的 VS 2017 在 Windows 上构建 Tensorflow 1.14。我在构建过程中遇到了这个崩溃:
external/bazel_tools/tools/def_parser/def_parser.exe bazel-out/x64_windows-opt/bin/tensorflow/contrib/layers/python/ops/_sparse_feature_cross_op.so.gen.def _sparse_feature_cross_op.so @bazel-out/x64_windows-opt/bin/tensorflow/contrib/layers/python/ops/_sparse_feature_cross_op.so.gen.def-0.params
ERROR: E:/tensorflow/tensorflow/contrib/layers/BUILD:22:1: DefParser tensorflow/contrib/layers/python/ops/_sparse_feature_cross_op.so.gen.def failed (Exit -1073741819): def_parser.exe failed: error executing command
我的环境是:
Tensorflow 版本:1.14(无源代码编辑)。取自https://github.com/tensorflow/tensorflow.git,分支 r1.14
Visual Studio 版本:VS 2017
巴泽尔版本:0.25.2
脚步:
set BAZEL_VC=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC
set BAZEL_VC_FULL_VERSION=14.16.27023
set BAZEL_VS=C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise
python .\configure.py
<Use all of the defaults>
bazel build -s --config=opt --copt=/GL --linkopt=/LTCG //tensorflow/tools/pip_package:build_pip_package
我尝试了各种版本的 bazel(0.21、0.26、0.27、0.28),并且在更改 BAZEL_* 环境变量时也尝试了 VS 2019,但我仍然遇到同样的错误。我已经在external/bazel_tools/tools/def_parser/def_parser.exe bazel-out/x64_windows-opt/bin/tensorflow/contrib/layers/python/ops/_sparse_feature_cross_op.so.gen.def _sparse_feature_cross_op.so @bazel-out/x64_windows-opt/bin/tensorflow/contrib/layers/python/ops/_sparse_feature_cross_op.so.gen.def-0.params
本地运行了该命令,但它确实以 -1073741819 错误代码崩溃。
有没有人有使用 LTCG 构建 Tensorflow 或使用 Bazel 和 LTCG 的经验?
解决方案
TF 1.14 需要 Bazel 0.24.1,AFAIK 它不适用于较新的 Bazel 版本 (>= 0.25)。
我不知道问题可能是什么,但我可以告诉你如何调试它。
您需要获取 Bazel 0.24.1 的源代码,将调试日志添加到 DEF 解析器,从源代码构建 Bazel,然后使用生成的二进制文件构建 TensorFlow。
为此:
- 下载Bazel 0.24.1 版本
- 下载并提取0.24.1 源代码 或git clone Bazel 的 GitHub 树并查看 0.24.1 标签
- 将调试日志记录/ printf 调用添加到您认为合适的third_party/def_parser/*
- 使用 0.24.1 发行版二进制文件,
bazel build //src:bazel.exe
在修补的源代码树中运行 - 使用结果
bazel-bin\src\bazel.exe
构建 TensorFlow - 如果您需要添加更多调试日志记录,请重复步骤 3..5
推荐阅读
- algorithm - 为什么 DP 解决“您可以从卡中获得的最大积分”问题的速度太慢?
- c - 菜单中的 Fgets() 和 sscanf()
- wordpress - 如果我在删除插件 w3 总缓存之前没有关闭常规设置下的所有缓存怎么办
- flutter - Flutter - 在点击时动画小部件以从 GridView 移动到 BottomBar
- amazon-web-services - 为什么我无法使用 webtoken 访问 AWS Airflow 的 UI?
- c# - 如何从 Bing 地图中删除所有现有的图钉?
- python - 网络抓取问题 求职网站
- python - 在具有 tf.while_loop (TF 2.0) 的函数上使用 tf.vectorized_map 的问题
- python - Firebase UID 和设置自定义管理规则和权限
- php - 如何使用来自 json 的值创建一个数组