【发布时间】:2021-06-19 19:54:42
【问题描述】:
下面的链接很好地说明了如何下载预构建的 libtorch windows 二进制文件并将它们集成到 Visual Studio 中。
我下载了 pytorch 1.8.1 的 Debug 和 Release 发行版。我很惊讶在两个扩展的 zip 文件中看到许多重复的目录/文件。 zip 文件都包含标题和 some 源。我很想合并两个层次结构,只保留单独的 bin 和 lib 文件夹,但有些头文件并不相同。
在我的示例项目的编译过程中,我遇到了一个编译器错误,我根据下面的“SBW”注释行进行了修复。
template<bool Condition, class ThenCallback>
decltype(auto) if_constexpr(ThenCallback&& thenCallback) {
#if defined(__cpp_if_constexpr)
// If we have C++17, just use it's "if constexpr" feature instead of wrapping it.
// This will give us better error messages.
if constexpr(Condition) {
if constexpr (detail::function_takes_identity_argument<ThenCallback>::value) {
// SBW 2021.05.12 Disambiguate std.
// https://github.com/pytorch/pytorch/pull/53490/files/2ef3c80214c798afdf165d677fc04025b28166d7
// return std::forward<ThenCallback>(thenCallback)(detail::_identity());
return ::std::forward<ThenCallback>(thenCallback)(detail::_identity());
} else {
// return std::forward<ThenCallback>(thenCallback)();
return ::std::forward<ThenCallback>(thenCallback)();
}
}
#else
// C++14 implementation of if constexpr
return if_constexpr<Condition>(std::forward<ThenCallback>(thenCallback), [] (auto) {});
#endif
}
调试示例项目是了解新库的绝佳方式,因此我为 Debug 构建所做的第一件事就是将 .pdb 文件的副本添加到上面链接中描述的 Post-Build 步骤.
我目前的项目涉及将 libtorch 模型和优化器与现有的本土深度学习代码集成。几年前,我们使用 TensorFlow 开始了这项工作,但当我们发现 TF c++ api 不支持模型训练时,它就停止了。
我们有一个自定义优化器,需要在训练阶段计算雅可比行列式,libtorch 本身不支持,所以我需要了解 autograd 库。在调试时,我很快发现自己处于一个没有附带源代码的堆栈中——Windows 二进制文件下载仅包含源代码的一个子集。
如何获得完整的资源集?
【问题讨论】:
标签: c++ visual-studio libtorch