Low-latency RNN inference using Cellular Batching Jinyang - - PowerPoint PPT Presentation
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
Lifecycle ¡of ¡DNN ¡deployments ¡
- pGmal ¡weights ¡θopt ¡
[0.1, ¡0.2, ¡...] ¡ predicGons ¡
Training: ¡ Inference ¡
IteraGvely ¡modify ¡ weights ¡θ ¡ Use ¡fixed ¡weights ¡ ¡θopt ¡
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 ¡
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) ¡
Background ¡on ¡Recurrent ¡Neural ¡Network ¡
fθ
input: ¡x ¡ hidden ¡ ¡ state: ¡h ¡
unfold ¡
fθ fθ fθ
x2 ¡ x0 ¡ x1 ¡ h0 ¡ h1 ¡ h2 ¡
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 ¡... ¡
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 ¡... ¡
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 ¡
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” ¡
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” ¡
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” ¡
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. ¡
Talk ¡outline ¡
- MoGvaGon: ¡ ¡
– ExisGng ¡batching ¡techniques ¡incur ¡long ¡delay ¡for ¡RNNs ¡
- Our ¡approach: ¡cellular ¡batching ¡
- Batchmaker ¡RNN ¡inference ¡system ¡
- EvaluaGon ¡
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. ¡
Graph ¡batching ¡wastes ¡batching ¡
- pportunity ¡
Not ¡yet ¡executed ¡ execuGng ¡ finished ¡
Graph ¡batching ¡wastes ¡batching ¡
- pportunity ¡
Not ¡yet ¡executed ¡ execuGng ¡ finished ¡
Graph ¡batching ¡wastes ¡batching ¡
- pportunity ¡
Not ¡yet ¡executed ¡ execuGng ¡ finished ¡
Graph ¡batching ¡wastes ¡batching ¡
- pportunity ¡
Not ¡yet ¡executed ¡ execuGng ¡ finished ¡
Graph ¡batching ¡wastes ¡batching ¡
- pportunity ¡
Not ¡yet ¡executed ¡ execuGng ¡ finished ¡
Cellular ¡batching ¡reduces ¡waiGng ¡
Not ¡yet ¡executed ¡ execuGng ¡ finished ¡
Cellular ¡batching ¡reduces ¡waiGng ¡
Not ¡yet ¡executed ¡ execuGng ¡ finished ¡
Cellular ¡batching ¡reduces ¡waiGng ¡
Not ¡yet ¡executed ¡ execuGng ¡ finished ¡
Cellular ¡batching ¡reduces ¡waiGng ¡
Not ¡yet ¡executed ¡ execuGng ¡ finished ¡
Cellular ¡batching ¡reduces ¡waiGng ¡
Not ¡yet ¡executed ¡ execuGng ¡ finished ¡
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 ¡
Talk ¡outline ¡
- MoGvaGon: ¡ ¡
– ExisGng ¡batching ¡techniques ¡incur ¡long ¡delay ¡for ¡RNNs ¡
- Our ¡approach: ¡cellular ¡batching ¡
- Batchmaker ¡RNN ¡inference ¡system ¡
- EvaluaGon ¡
Batchmaker: ¡system ¡architecture ¡
requests ¡ User-‑defined ¡ unfolding ¡logic ¡ initalizaGon ¡ cell ¡definiGon ¡ (saved ¡by ¡MXNet/TensorFlow) ¡ predicGons ¡
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 ¡
Priority ¡and ¡locality ¡in ¡scheduling ¡
Priority ¡and ¡locality ¡in ¡scheduling ¡
Priority ¡and ¡locality ¡in ¡scheduling ¡
Priority ¡and ¡locality ¡in ¡scheduling ¡
Priority ¡and ¡locality ¡in ¡scheduling ¡
Priority ¡and ¡locality ¡in ¡scheduling ¡
Priority ¡and ¡locality ¡in ¡scheduling ¡
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 ¡
Talk ¡outline ¡
- MoGvaGon: ¡ ¡
– ExisGng ¡batching ¡techniques ¡incur ¡long ¡delay ¡for ¡RNNs ¡
- Our ¡approach: ¡cellular ¡batching ¡
- Batchmaker ¡RNN ¡inference ¡system ¡
- EvaluaGon ¡
EvaluaGon ¡quesGons ¡
- How ¡does ¡Batchmaker ¡compare ¡against ¡
baseline ¡systems? ¡
- Where ¡does ¡Batchmaker’s ¡performance ¡
advantage ¡come ¡from? ¡
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 ¡
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 ¡
LSTM ¡on ¡English ¡sentences ¡
Throughput ¡(reqs/sec) ¡ ¡90-‑percenGle ¡latency ¡(ms) ¡
35% ¡more ¡ throughput ¡ ¡ 93% ¡latency ¡ reducGon ¡from ¡ 165ms ¡to ¡12ms ¡
Batchmaker ¡wins ¡by ¡curng ¡down ¡queueing ¡
reduce ¡90p ¡wait ¡Gme ¡ from ¡80ms ¡to ¡1.3ms ¡
cumulaGve ¡distribuGon ¡ Latency ¡(ms) ¡
Throughput ¡(reqs/sec) ¡
Batchmaker ¡wins ¡due ¡to ¡variable ¡req ¡length ¡
99p-‑latency ¡(ms) ¡ 99p-‑latency ¡(ms) ¡ Fixed ¡sequence ¡length ¡ Clipped ¡sequences ¡(max=100) ¡
Seq2seq ¡on ¡English-‑German ¡on ¡4 ¡GPUs ¡
¡90-‑percenGle ¡latency ¡(ms) ¡ Throughput ¡(reqs/sec) ¡
TreeLSTM ¡on ¡TreeBank ¡dataset ¡
Throughput ¡(reqs/sec) ¡ ¡90-‑percenGle ¡latency ¡(ms) ¡
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] ¡
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 ¡