哪些 python 深度学习库在运行时编译?
Which python deep learning libraries compile at runtime?
我正在努力研究 python 中的 C 语言优化代码。 python 通过 C 扩展实现高速计算,我已经读过好几遍了。换句话说,每当我使用 numpy 等库时,它基本上都会调用一个 C 扩展来计算结果并 returns 它。
使用 numpy 的 C 扩展
假设我想使用 np.add(x,y)
将两个数字相加。如果我理解正确的话,像 numpy 这样的库不会编译 python 代码,而是已经带有可执行文件,这些可执行文件将简单地采用值 x 和 y 以及 return 结果。对吗?
Theano、Tensorflow 和 PyTorch
特别是,我想知道深度学习库是否也是如此。根据 Theano 的官方文档,它需要 g++ 和 gcc(至少强烈推荐它们)。这是否意味着 Theano 将在 python 脚本的运行时 编译 C(或 C++)代码 ?如果是这样,PyTorch 和 Tensorflow 是否相同?
希望有人能在这里解决我的困惑!非常感谢!
python
中的 C 扩展
numpy
经常使用 C 扩展。例如,您可以在此处 [2].
查看 sort() 函数 [1] 的 C 实现
[1] https://docs.scipy.org/doc/numpy/reference/generated/numpy.sort.html
[2] https://github.com/numpy/numpy/blob/master/numpy/core/src/npysort/quicksort.c.src
深度学习库
深度学习库的大部分后端以及 CUDA 和 CUDNN 使用 C 扩展。代码可以在运行时编译:
[3]http://deeplearning.net/software/theano/extending/pipeline.html#compilation-of-the-computation-graph
[4]https://www.tensorflow.org/xla/jit
[5]https://pytorch.org/blog/the-road-to-1_0/#production--pain-for-researchers
为了回答您的问题,theano
将在 python 脚本运行时编译 C/C++ 代码。对于 theano
,运行时的图形编译时间非常慢:我建议您关注 pytorch
或 tensorflow
而不是 theano
。
如果您是深度学习的新手,也可以快速浏览一下 [6]。
我正在努力研究 python 中的 C 语言优化代码。 python 通过 C 扩展实现高速计算,我已经读过好几遍了。换句话说,每当我使用 numpy 等库时,它基本上都会调用一个 C 扩展来计算结果并 returns 它。
使用 numpy 的 C 扩展
假设我想使用 np.add(x,y)
将两个数字相加。如果我理解正确的话,像 numpy 这样的库不会编译 python 代码,而是已经带有可执行文件,这些可执行文件将简单地采用值 x 和 y 以及 return 结果。对吗?
Theano、Tensorflow 和 PyTorch
特别是,我想知道深度学习库是否也是如此。根据 Theano 的官方文档,它需要 g++ 和 gcc(至少强烈推荐它们)。这是否意味着 Theano 将在 python 脚本的运行时 编译 C(或 C++)代码 ?如果是这样,PyTorch 和 Tensorflow 是否相同?
希望有人能在这里解决我的困惑!非常感谢!
python
中的 C 扩展numpy
经常使用 C 扩展。例如,您可以在此处 [2].
[1] https://docs.scipy.org/doc/numpy/reference/generated/numpy.sort.html
[2] https://github.com/numpy/numpy/blob/master/numpy/core/src/npysort/quicksort.c.src
深度学习库
深度学习库的大部分后端以及 CUDA 和 CUDNN 使用 C 扩展。代码可以在运行时编译:
[3]http://deeplearning.net/software/theano/extending/pipeline.html#compilation-of-the-computation-graph
[4]https://www.tensorflow.org/xla/jit
[5]https://pytorch.org/blog/the-road-to-1_0/#production--pain-for-researchers
为了回答您的问题,theano
将在 python 脚本运行时编译 C/C++ 代码。对于 theano
,运行时的图形编译时间非常慢:我建议您关注 pytorch
或 tensorflow
而不是 theano
。
如果您是深度学习的新手,也可以快速浏览一下 [6]。