57

TensorFlow 到底慢在哪里? - 知乎

 6 years ago
source link: https://www.zhihu.com/question/265848305/answer/311168537?
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

TensorFlow 到底慢在哪里?

登录一下,更多精彩内容等你发现
贡献精彩回答,参与评论互动

单机GPU不太小常见模型使用正确的情况下,TensorFlow不会比任何其他框架显著的慢.

不显著: 大概上下5%以内. 不存在"被吊打".

常见模型: 指没有奇怪的层的CNN, 及标准的RNN/LSTM.

因为Google又不傻..

tensorflow/benchmarks 里的DGX1的数字刚出来的时候就是跟caffe2一样的.

不常见模型/非GPU: 各个框架用的kernel都不一样了, 能跑多快主要看运气. 具体点说,主要看开发者里有没有人恰好认认真真优化了你也恰好在用的这个非主流的kernel.

太小的模型: 1秒能跑成百上千个iteration的时候, 框架overhead会体现出来.

多机: TensorFlow的多机scalability差. 好像最近正在试图做高效的allreduce. uber/horovod就是给TensorFlow加了一个自己写的allreduce op, scalability就好了很多, 勉强也能做到90%.

至于所谓"公开测评文章"说被吊打,那多半都是各个框架使用不正确.

不正确可能的原因太多了..用错kernel的, copy了好多次自己不知道的, 在循环里建图的, 还没算完就计时的, 用Keras的. 当然这锅也不能用户背,毕竟TensorFlow好多官方样例的效率都是有问题的.

我想来回答这个问题就是因为今天reddit上的这个帖子

引用一下soumith(torch/pytorch作者)在帖子里说的话吧:

Amateur benchmarks are hard, and more often than not they are quite wrong.
In recent times I don't think I've seen a single amateur benchmark that didn't screw up in it's first couple of iterations.

断章取义的翻译:"我没见过一个业余测评是做对了的"

UPDATE:
自TF1.12开始, 在8个V100上用半精度在imagenet上训练resnet50, TF的速度远快于pytorch/caffe2..


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK