使用 SIMD 和多线程增强 TensorFlow.js WebAssembly 后端

{"type":"doc","content":[{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong"}],"text":"本文最初发表在 TensorFlow 官博,经原作者授权,InfoQ 中文站翻译并分享。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"今年三月,我们为 TensorFlow.js "},{"type":"link","attrs":{"href":"https:\/\/blog.tensorflow.org\/2020\/03\/introducing-webassembly-backend-for-tensorflow-js.html","title":"","type":null},"content":[{"type":"text","text":"引入"}]},{"type":"text","text":"了一个新的 WebAssembly(Wasm)加速后端。今天,我们很高兴的宣布一个重大的性能更新:从 TensorFlow.js 2.3.0 版本开始,通过 "},{"type":"link","attrs":{"href":"https:\/\/github.com\/google\/XNNPACK","title":"","type":null},"content":[{"type":"text","text":"XNNPACK"}]},{"type":"text","text":"(一个高度优化的神经网络运算符库)利用"},{"type":"link","attrs":{"href":"https:\/\/github.com\/WebAssembly\/simd","title":"","type":null},"content":[{"type":"text","text":" SIMD(向量)指令"}]},{"type":"text","text":"和"},{"type":"link","attrs":{"href":"https:\/\/github.com\/WebAssembly\/threads","title":"","type":null},"content":[{"type":"text","text":"多线程"}]},{"type":"text","text":",我们的 Wasm 后端速度提高了 10 倍。"}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"基准测试"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"SIMD 和多线程为我们的 Wasm 后端带来了重大的性能提升。下面是 Google Chrome 浏览器的基准测试,展示了 "},{"type":"link","attrs":{"href":"https:\/\/github.com\/tensorflow\/tfjs-models\/tree\/master\/blazeface","title":"","type":null},"content":[{"type":"text","text":"BlazeFace"}]},{"type":"text","text":" 的改进。BlazeFace 是一个具有 10 万个参数和大约 2000 万次乘加运算的轻量级模型。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"(表中所列出的时间为每次推断的毫秒数)"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"embedcomp","attrs":{"type":"table","data":{"content":"

设备

普通 JS

WebGL

Wasm

Wasm+SIMD

Wasm+SIMD+线程

Pixel 4

368

28

28

15.9

N\/A*

第 6 代 ThnkPad X1,Linux

301.0

25.0

15.5

7.3

4.1

MacBook Pro 15 2019

209.1

22.7

13.3

7.9

4.0

在 MacBook Pro 15 2019 上运行 Node v.14

201.2

N\/A

25.5

15.2

N\/A**"}}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"更大的模型,如 MobileNet V2,这是一个拥有 350 万个参数和大约 3 亿个乘加运算的中性模型,可以获得更快的加速:"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"embedcomp","attrs":{"type":"table","data":{"content":"

设备

普通 JS

WebGL

Wasm

Wasm+SIMD

Wasm+SIMD+线程

Pixel 4

1628

76.7

182

82

N\/A*

第 6 代 ThinkPad X1,Linux

1489.4

44.8

122.7

34.6

12.4

MacBook Pro 15 2019

893.5

19.6

98.4

30.2

10.3

在 MacBook Pro 15 2019shang yunxing Node v.14

1404.3

N\/A

290.0

64.2

N\/A**"}}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"注:"},{"type":"link","attrs":{"href":"https:\/\/www.chromestatus.com\/feature\/5724132452859904","title":"","type":null},"content":[{"type":"text","text":"由于移动浏览器中的多线程支持仍在进行中"}]},{"type":"text","text":",故 Pixel 4 不支持 TF.js 多线程 Wasm 后端的基准测试。iOS 版本的 SIMD 支持也仍在开发中。TF.js 多线程 Wasm 后端的节点支持即将推出。"}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章