Low-latency RNN inference using Cellular Batching Jinyang - - PowerPoint PPT Presentation

low latency rnn inference using cellular batching
SMART_READER_LITE
LIVE PREVIEW

Low-latency RNN inference using Cellular Batching Jinyang - - PowerPoint PPT Presentation

Low-latency RNN inference using Cellular Batching Jinyang Li joint work with Pin Gao, Lingfan Yu, Yongwei Wu New York University


slide-1
SLIDE 1

Low-­‑latency ¡RNN ¡inference ¡using ¡ Cellular ¡Batching ¡ ¡

Jinyang ¡Li ¡

joint ¡work ¡with ¡Pin ¡Gao, ¡Lingfan ¡Yu, ¡Yongwei ¡Wu ¡

¡ ¡

New ¡York ¡University ¡ ¡ ¡ ¡ ¡ ¡Tsinghua ¡University ¡

slide-2
SLIDE 2

Lifecycle ¡of ¡DNN ¡deployments ¡

  • pGmal ¡weights ¡θopt ¡

[0.1, ¡0.2, ¡...] ¡ predicGons ¡

Training: ¡ Inference ¡

IteraGvely ¡modify ¡ weights ¡θ ¡ Use ¡fixed ¡weights ¡ ¡θopt ¡

slide-3
SLIDE 3

DNN ¡Serving ¡must ¡provide ¡low ¡latency ¡

Training: ¡ Inference: ¡

All ¡samples ¡are ¡ available ¡at ¡once ¡

Goal ¡

good ¡ throughput ¡ ¡ Request ¡arrives ¡one ¡ at ¡a ¡Gme ¡

Goal ¡

good ¡throughput ¡ & ¡low ¡latency ¡

slide-4
SLIDE 4

0 ¡ 2000 ¡ 4000 ¡ 6000 ¡

2 ¡ 4 ¡ 8 ¡ 16 ¡ 32 ¡ 64 ¡ 128 ¡ 256 ¡ 512 ¡ 1024 ¡ 2048 ¡ 4096 ¡

The ¡hardware ¡reality: ¡batching ¡ improves ¡performance ¡

Batch ¡size ¡ Latency ¡(us) ¡

Nvidia ¡Tesla ¡v100, ¡one ¡LSTM ¡step ¡(hidden ¡state ¡size ¡1024) ¡

0 ¡ 300000 ¡ 600000 ¡ 900000 ¡ Throughput ¡(reqs/sec) ¡

slide-5
SLIDE 5

Background ¡on ¡Recurrent ¡Neural ¡Network ¡

input: ¡x ¡ hidden ¡ ¡ state: ¡h ¡

unfold ¡

fθ fθ fθ

x2 ¡ x0 ¡ x1 ¡ h0 ¡ h1 ¡ h2 ¡

slide-6
SLIDE 6

RNN’s ¡batching ¡challenge: ¡ ¡ chain-­‑RNNs ¡

  • How ¡to ¡batch ¡chains ¡of ¡different ¡lengths? ¡

LSTM ¡ cell ¡ LSTM ¡ cell ¡ LSTM ¡ cell ¡ “Volta” ¡ “GPU” ¡ “is” ¡ “fast” ¡ Volta ¡CPU ¡is... ¡ LSTM ¡ cell ¡ “I” ¡ “love” ¡ LSTM ¡ cell ¡ “california” ¡ I ¡love ¡... ¡

slide-7
SLIDE 7

State-­‑of-­‑the-­‑art ¡soluGon: ¡padding ¡

  • TensorFlow, ¡MXNet, ¡PyTorch, ¡CNTK ¡batch ¡via ¡

padding ¡

LSTM ¡ cell ¡ LSTM ¡ cell ¡ LSTM ¡ cell ¡ “Volta” ¡ “GPU” ¡ “is” ¡ “fast” ¡ LSTM ¡ cell ¡ “I” ¡ “love” ¡ LSTM ¡ cell ¡ “california” ¡ Volta ¡CPU ¡is... ¡ I ¡love ¡... ¡

slide-8
SLIDE 8

State-­‑of-­‑the-­‑art ¡soluGon: ¡padding ¡

  • TensorFlow, ¡MXNet, ¡PyTorch, ¡CNTK ¡batch ¡via ¡

padding ¡

LSTM ¡ cell ¡ LSTM ¡ cell ¡ LSTM ¡ cell ¡ “Volta” ¡ “GPU” ¡ “is” ¡ “fast” ¡ “I” ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ “love” ¡ “california” ¡ Volta ¡CPU ¡is... ¡ I ¡love ¡... ¡ xxxx ¡

slide-9
SLIDE 9

RNN’s ¡batching ¡challenge: ¡ ¡ TreeLSTM ¡

  • How ¡to ¡batch ¡trees ¡of ¡different ¡structures? ¡

LSTM ¡ cell ¡ LSTM ¡ leaf ¡ LSTM ¡ cell ¡ LSTM ¡ leaf ¡ LSTM ¡ leaf ¡ LSTM ¡ cell ¡ LSTM ¡ leaf ¡ LSTM ¡ leaf ¡ “kids” ¡ “love” ¡ “dogs” ¡ “cats” ¡ “sleep” ¡

slide-10
SLIDE 10

State-­‑of-­‑the-­‑art ¡soluGons: ¡graph ¡batching ¡

  • TensorFlow-­‑Fold ¡and ¡DyNet ¡merge ¡dataflow ¡

graphs ¡

LSTM ¡ cell ¡ LSTM ¡ leaf ¡ LSTM ¡ cell ¡ LSTM ¡ leaf ¡ LSTM ¡ leaf ¡ LSTM ¡ cell ¡ LSTM ¡ leaf ¡ LSTM ¡ leaf ¡ “kids” ¡ “love” ¡ “dogs” ¡ “cats” ¡ “sleep” ¡

slide-11
SLIDE 11

State-­‑of-­‑the-­‑art ¡soluGons: ¡graph ¡batching ¡

  • TensorFlow-­‑Fold ¡and ¡DyNet ¡merge ¡dataflow ¡

graphs ¡

LSTM ¡ cell ¡ LSTM ¡ leaf ¡ LSTM ¡ cell ¡ LSTM ¡ leaf ¡ LSTM ¡ leaf ¡ “kids” ¡ “love” ¡ “dogs” ¡ “cats” ¡ “sleep” ¡

slide-12
SLIDE 12

ExisGng ¡batching ¡techniques ¡do ¡not ¡ work ¡well ¡for ¡RNNs ¡

  • Long ¡delay ¡

– New ¡request ¡has ¡to ¡wait ¡for ¡current ¡batch ¡to ¡finish ¡

  • SubopGmal ¡Throughput ¡

– Padding ¡wastes ¡computaGon ¡ – Not ¡every ¡operator ¡is ¡batched ¡thoroughly ¡in ¡the ¡ merged ¡graph. ¡

slide-13
SLIDE 13

Talk ¡outline ¡

  • MoGvaGon: ¡ ¡

– ExisGng ¡batching ¡techniques ¡incur ¡long ¡delay ¡for ¡RNNs ¡

  • Our ¡approach: ¡cellular ¡batching ¡
  • Batchmaker ¡RNN ¡inference ¡system ¡
  • EvaluaGon ¡
slide-14
SLIDE 14

Our ¡approach: ¡cellular ¡batching ¡

  • The ¡insight: ¡RNN ¡is ¡made ¡up ¡of ¡(a ¡few ¡types ¡of) ¡

cells ¡that ¡are ¡repeated ¡many ¡Gmes ¡ ü Cellular ¡batching: ¡make ¡batching ¡decisions ¡ before ¡execuGng ¡each ¡cell. ¡ X Graph ¡batching ¡or ¡padding: ¡make ¡batching ¡ decisions ¡before ¡execuGng ¡requests. ¡

slide-15
SLIDE 15

Graph ¡batching ¡wastes ¡batching ¡

  • pportunity ¡

Not ¡yet ¡executed ¡ execuGng ¡ finished ¡

slide-16
SLIDE 16

Graph ¡batching ¡wastes ¡batching ¡

  • pportunity ¡

Not ¡yet ¡executed ¡ execuGng ¡ finished ¡

slide-17
SLIDE 17

Graph ¡batching ¡wastes ¡batching ¡

  • pportunity ¡

Not ¡yet ¡executed ¡ execuGng ¡ finished ¡

slide-18
SLIDE 18

Graph ¡batching ¡wastes ¡batching ¡

  • pportunity ¡

Not ¡yet ¡executed ¡ execuGng ¡ finished ¡

slide-19
SLIDE 19

Graph ¡batching ¡wastes ¡batching ¡

  • pportunity ¡

Not ¡yet ¡executed ¡ execuGng ¡ finished ¡

slide-20
SLIDE 20

Cellular ¡batching ¡reduces ¡waiGng ¡

Not ¡yet ¡executed ¡ execuGng ¡ finished ¡

slide-21
SLIDE 21

Cellular ¡batching ¡reduces ¡waiGng ¡

Not ¡yet ¡executed ¡ execuGng ¡ finished ¡

slide-22
SLIDE 22

Cellular ¡batching ¡reduces ¡waiGng ¡

Not ¡yet ¡executed ¡ execuGng ¡ finished ¡

slide-23
SLIDE 23

Cellular ¡batching ¡reduces ¡waiGng ¡

Not ¡yet ¡executed ¡ execuGng ¡ finished ¡

slide-24
SLIDE 24

Cellular ¡batching ¡reduces ¡waiGng ¡

Not ¡yet ¡executed ¡ execuGng ¡ finished ¡

slide-25
SLIDE 25

Performance ¡challenges ¡in ¡realizing ¡ cellular ¡batching ¡

  • Must ¡support ¡mulGple ¡types ¡of ¡cells ¡and ¡>1 ¡GPUs ¡

– Only ¡cells ¡of ¡the ¡same ¡type ¡can ¡be ¡batched ¡ ¡together ¡ – Different ¡cell ¡types ¡have ¡different ¡priority ¡

  • Balance ¡batching ¡opportunity ¡and ¡overhead ¡

– Cost ¡of ¡scheduling ¡is ¡non-­‑trivial ¡ – Adding ¡new ¡requests ¡to ¡a ¡batch ¡incurs ¡memory ¡copy ¡

  • Decisions ¡must ¡be ¡made ¡asynchronously ¡with ¡

execuGon ¡

slide-26
SLIDE 26

Talk ¡outline ¡

  • MoGvaGon: ¡ ¡

– ExisGng ¡batching ¡techniques ¡incur ¡long ¡delay ¡for ¡RNNs ¡

  • Our ¡approach: ¡cellular ¡batching ¡
  • Batchmaker ¡RNN ¡inference ¡system ¡
  • EvaluaGon ¡
slide-27
SLIDE 27

Batchmaker: ¡system ¡architecture ¡

requests ¡ User-­‑defined ¡ unfolding ¡logic ¡ initalizaGon ¡ cell ¡definiGon ¡ (saved ¡by ¡MXNet/TensorFlow) ¡ predicGons ¡

slide-28
SLIDE 28

How ¡the ¡scheduler ¡makes ¡decisions ¡

  • Preserve ¡Locality ¡

– prefer ¡batching ¡cells ¡of ¡the ¡same ¡set ¡of ¡request ¡ – prefer ¡sGcking ¡to ¡the ¡same ¡GPU ¡for ¡the ¡same ¡ request ¡

  • Allow ¡Priority ¡

– decoder ¡cells ¡> ¡encoder ¡cells ¡ – TreeLSTM ¡internal ¡cells ¡> ¡leaf ¡cell ¡

  • Schedule ¡several ¡dependent ¡batches ¡at ¡a ¡Gme ¡
slide-29
SLIDE 29

Priority ¡and ¡locality ¡in ¡scheduling ¡

slide-30
SLIDE 30

Priority ¡and ¡locality ¡in ¡scheduling ¡

slide-31
SLIDE 31

Priority ¡and ¡locality ¡in ¡scheduling ¡

slide-32
SLIDE 32

Priority ¡and ¡locality ¡in ¡scheduling ¡

slide-33
SLIDE 33

Priority ¡and ¡locality ¡in ¡scheduling ¡

slide-34
SLIDE 34

Priority ¡and ¡locality ¡in ¡scheduling ¡

slide-35
SLIDE 35

Priority ¡and ¡locality ¡in ¡scheduling ¡

slide-36
SLIDE 36

ImplementaGon ¡opGmizaGons ¡

  • Dynamically ¡adjust ¡the ¡batch ¡size ¡(up ¡to ¡the ¡

configured ¡maximum) ¡

– Form ¡and ¡execute ¡a ¡batch ¡whenever ¡GPU ¡is ¡idle ¡

  • Asynchronously ¡wait ¡for ¡GPU ¡kernel ¡compleGon ¡

– GPU ¡driver’s ¡asynchronous ¡callback ¡is ¡too ¡slow ¡ – Add ¡a ¡signaling ¡kernel ¡at ¡the ¡end ¡of ¡all ¡cell ¡kernels ¡

  • update ¡a ¡variable ¡in ¡host ¡memory ¡
slide-37
SLIDE 37

Talk ¡outline ¡

  • MoGvaGon: ¡ ¡

– ExisGng ¡batching ¡techniques ¡incur ¡long ¡delay ¡for ¡RNNs ¡

  • Our ¡approach: ¡cellular ¡batching ¡
  • Batchmaker ¡RNN ¡inference ¡system ¡
  • EvaluaGon ¡
slide-38
SLIDE 38

EvaluaGon ¡quesGons ¡

  • How ¡does ¡Batchmaker ¡compare ¡against ¡

baseline ¡systems? ¡

  • Where ¡does ¡Batchmaker’s ¡performance ¡

advantage ¡come ¡from? ¡

slide-39
SLIDE 39

EvaluaGon ¡Setup ¡

  • Batchmaker ¡prototype: ¡

– Implemented ¡using ¡MXNet ¡

  • Baseline ¡systems: ¡

– Padding: ¡MXNet, ¡TensorFlow ¡ – Graph ¡batching: ¡TensorFlow-­‑Fold, ¡DyNet ¡

  • Workload ¡

– LSTM, ¡Seq2seq, ¡TreeLSTM ¡

  • Hardware ¡

– NVIDIA ¡Tesla ¡V100 ¡

slide-40
SLIDE 40

Baseline ¡system ¡tuning ¡

  • How ¡to ¡get ¡the ¡best ¡performance ¡from ¡padding? ¡

– BuckeGng: ¡batch ¡(and ¡pad) ¡requests ¡of ¡similar ¡length ¡

Throughput ¡(reqs/sec) ¡ 90-­‑percenGle ¡Latency ¡(ms) ¡

We ¡chose ¡ bucket ¡ width=10 ¡

slide-41
SLIDE 41

LSTM ¡on ¡English ¡sentences ¡

Throughput ¡(reqs/sec) ¡ ¡90-­‑percenGle ¡latency ¡(ms) ¡

35% ¡more ¡ throughput ¡ ¡ 93% ¡latency ¡ reducGon ¡from ¡ 165ms ¡to ¡12ms ¡

slide-42
SLIDE 42

Batchmaker ¡wins ¡by ¡curng ¡down ¡queueing ¡

reduce ¡90p ¡wait ¡Gme ¡ from ¡80ms ¡to ¡1.3ms ¡

cumulaGve ¡distribuGon ¡ Latency ¡(ms) ¡

slide-43
SLIDE 43

Throughput ¡(reqs/sec) ¡

Batchmaker ¡wins ¡due ¡to ¡variable ¡req ¡length ¡

99p-­‑latency ¡(ms) ¡ 99p-­‑latency ¡(ms) ¡ Fixed ¡sequence ¡length ¡ Clipped ¡sequences ¡(max=100) ¡

slide-44
SLIDE 44

Seq2seq ¡on ¡English-­‑German ¡on ¡4 ¡GPUs ¡

¡90-­‑percenGle ¡latency ¡(ms) ¡ Throughput ¡(reqs/sec) ¡

slide-45
SLIDE 45

TreeLSTM ¡on ¡TreeBank ¡dataset ¡

Throughput ¡(reqs/sec) ¡ ¡90-­‑percenGle ¡latency ¡(ms) ¡

slide-46
SLIDE 46

Related ¡Work ¡

  • Persistent ¡RNNs ¡ ¡[Diamos ¡et ¡al. ¡ICML’16] ¡
  • TensorFlow-­‑Serving ¡ ¡[Olston ¡et ¡al. ¡arXiv ¡1712.06139] ¡
  • MulG-­‑query ¡batching ¡in ¡database ¡[Giannikis ¡et ¡al. ¡

VLDB ¡2012, ¡ ¡Harizopoulos ¡et ¡al. ¡SIGMOD ¡2005] ¡

  • Pipelined ¡execuGon ¡[Welsh ¡et ¡al. ¡SOSP ¡2001] ¡
slide-47
SLIDE 47

Conclusion ¡

  • Cellular ¡batching ¡batches ¡together ¡new ¡

requests ¡with ¡ongoing ¡ones ¡

– unique ¡to ¡inference ¡

  • Realizing ¡cellular ¡batching ¡efficiently ¡must ¡

consider ¡locality ¡and ¡priority ¡

  • Batchmaker ¡significantly ¡outperforms ¡baseline ¡

systems ¡