Declara've ¡Systems ¡for ¡ ¡ Large ¡Scale ¡Machine ¡Learning ¡
Markus ¡Weimer, ¡Tyson ¡Condie, ¡Raghu ¡Ramakrishnan ¡ ¡ Cloud ¡and ¡Informa'on ¡Services ¡Laboratory ¡ MicrosoA ¡
Declara've Systems for Large Scale Machine Learning - - PowerPoint PPT Presentation
Declara've Systems for Large Scale Machine Learning Markus Weimer, Tyson Condie, Raghu Ramakrishnan Cloud and Informa'on Services Laboratory MicrosoA
Markus ¡Weimer, ¡Tyson ¡Condie, ¡Raghu ¡Ramakrishnan ¡ ¡ Cloud ¡and ¡Informa'on ¡Services ¡Laboratory ¡ MicrosoA ¡
6/5/12 2
Yingyi ¡Bu, ¡Vinayak ¡Borkar, ¡Michael ¡J. ¡Carey ¡ University ¡of ¡California, ¡Irvine ¡ Joshua ¡Rosen, ¡Neoklis ¡Polyzo's ¡ University ¡of ¡California, ¡Santa ¡Cruz ¡
6/5/12 3
Inbox ¡ Spam ¡ Spam ¡ Filter ¡ User ¡ Interface ¡ Logged ¡ Event ¡
6/5/12 4
Example ¡ Forma'on ¡ Modeling ¡ Evalua'on ¡
6/5/12 5
EMail ¡ Click ¡Log ¡ Bag ¡of ¡ Words ¡ ID ¡ Label ¡ ID ¡ Bag ¡of ¡ Words ¡ Label ¡ ID ¡ Feature Extraction Label Extraction Data ¡Parallel ¡ Func'ons ¡ Large ¡Scale ¡Join ¡ Large ¡Scale ¡Join ¡
6/5/12 6
6/5/12 7
6/5/12 8
6/5/12 9
Regularization Data Parallel Sum
6/5/12 10
(x,y)
wt: Current Model x: Data y: Label l: loss function (e.g. squared error) ∂: Gradient operator
6/5/12 11
Par''on ¡I ¡ Par''on ¡II ¡ Par''on ¡III ¡ Gradient ¡I ¡ Gradient ¡II ¡ Gradient ¡III ¡ Gradient ¡ Sum ¡
6/5/12 12
– Beyond ¡the ¡fixed ¡map-‑ groupby-‑reduce ¡ – Arbitrary ¡length ¡and ¡ complexity ¡
– Join, ¡Filter, ¡Project, ¡… ¡
– Dryad ¡(MicrosoA ¡Research) ¡ – Hyracks ¡(UC ¡Irvine) ¡ – Stratosphere ¡(TU ¡Berlin) ¡
6/5/12 13
– Beyond ¡the ¡fixed ¡map-‑ groupby-‑reduce ¡ – Arbitrary ¡length ¡and ¡ complexity ¡
– Join, ¡Filter, ¡Project, ¡… ¡
– Dryad ¡(MicrosoA ¡Research) ¡ – Hyracks ¡(UC ¡Irvine) ¡ – Stratosphere ¡(TU ¡Berlin) ¡
6/5/12 14
6/5/12 15
Spark Giraph (Pregel) One- Offs
6/5/12 16
6/5/12 17
User ¡ Program ¡ Logical ¡ Plan ¡ Physical ¡ Plan ¡ Execu'on ¡ Engine ¡
6/5/12 18
User ¡ Program ¡ Logical ¡ Plan ¡ Physical ¡ Plan ¡ Execu'on ¡ Engine ¡ ScalOps ¡ Algebricks ¡ Physical ¡ Plan ¡ Hyracks ¡
6/5/12 19
Loop ¡ Aware ¡on ¡ all ¡Levels ¡
ScalOps ¡ Algebricks ¡ Physical ¡ Plan ¡ Hyracks ¡
6/5/12 20
6/5/12 21
Regularization Data Parallel Sum
6/5/12 22
(x,y)
wt: Current Model x: Data y: Label l: loss function (e.g. squared error) ∂: Gradient operator
def ¡train(xy:Table[Example], ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_grad:(Example, ¡Vector) ¡=> ¡Vector, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_loss:(Example, ¡Vector) ¡=> ¡Double) ¡= ¡{ ¡ ¡ ¡ ¡ ¡class ¡Env(w:VectorType, ¡lastError:DoubleType, ¡delta:DoubleType) ¡extends ¡Environment ¡ ¡ ¡ ¡ ¡val ¡initialValue ¡= ¡new ¡Env(VectorType.zeros(1000), ¡Double.MaxValue, ¡Double.MaxValue) ¡ ¡ ¡ ¡ ¡loop(initialValue, ¡(env: ¡Env) ¡=> ¡env.delta ¡< ¡eps) ¡{ ¡env ¡=> ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡gradient ¡= ¡xy.map(x=>compute_grad(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡loss ¡ ¡ ¡ ¡ ¡= ¡xy.map(x=>compute_loss(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡env.w ¡ ¡ ¡ ¡ ¡ ¡ ¡-‑= ¡gradient ¡ ¡ ¡ ¡ ¡ ¡ ¡env.delta ¡ ¡ ¡ ¡= ¡env.lastLoss ¡-‑ ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env.lastLoss ¡= ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡} ¡ } ¡ ¡ ¡ ¡
6/5/12 23
Training ¡data; ¡Table ¡is ¡
Computes ¡a ¡gradient ¡ Computes ¡the ¡loss ¡ Ini'alizer ¡ Loop ¡Condi'on ¡ Loop ¡Body ¡ Na've ¡UDFs ¡
¡
6/5/12 24
val points = spark.textFile(...). map(parsePoint). partitionBy(HashPartitioner(NODES)). cache() var w = Vector.random(D) // current separating plane for (i <- 1 to ITERATIONS) { val gradient = points.map(p => (1 / (1 + exp(-p.y*(w dot p.x))) - 1) * p.y * p.x ). reduce(_ + _) w -= gradient }
val points = spark.textFile(...). map(parsePoint). partitionBy(HashPartitioner(NODES)). cache() Physical ¡Layer ¡
6/5/12 25
6/5/12 26
def ¡train(xy:Table[Example], ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_grad:(Example, ¡Vector) ¡=> ¡Vector, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_loss:(Example, ¡Vector) ¡=> ¡Double) ¡= ¡{ ¡ ¡ ¡ ¡ ¡class ¡Env(w:VectorType, ¡lastError:DoubleType, ¡delta:DoubleType) ¡extends ¡Environment ¡ ¡ ¡ ¡ ¡val ¡initialValue ¡= ¡new ¡Env(VectorType.zeros(1000), ¡Double.MaxValue, ¡Double.MaxValue) ¡ ¡ ¡ ¡ ¡loop(initialValue, ¡(env: ¡Env) ¡=> ¡env.delta ¡< ¡eps) ¡{ ¡env ¡=> ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡gradient ¡= ¡xy.map(x=>compute_grad(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡loss ¡ ¡ ¡ ¡ ¡= ¡xy.map(x=>compute_loss(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡env.w ¡ ¡ ¡ ¡ ¡ ¡ ¡-‑= ¡gradient ¡ ¡ ¡ ¡ ¡ ¡ ¡env.delta ¡ ¡ ¡ ¡= ¡env.lastLoss ¡-‑ ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env.lastLoss ¡= ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡} ¡ } ¡ ¡ ¡ ¡
def ¡train(xy:Table[Example], ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_grad:(Example, ¡Vector) ¡=> ¡Vector, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_loss:(Example, ¡Vector) ¡=> ¡Double) ¡= ¡{ ¡ ¡ ¡ ¡ ¡class ¡Env(w:VectorType, ¡lastError:DoubleType, ¡delta:DoubleType) ¡extends ¡Environment ¡ ¡ ¡ ¡ ¡val ¡initialValue ¡= ¡new ¡Env(VectorType.zeros(1000), ¡Double.MaxValue, ¡Double.MaxValue) ¡ ¡ ¡ ¡ ¡loop(initialValue, ¡(env: ¡Env) ¡=> ¡env.delta ¡< ¡eps) ¡{ ¡env ¡=> ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡gradient ¡= ¡xy.map(x=>compute_grad(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡loss ¡ ¡ ¡ ¡ ¡= ¡xy.map(x=>compute_loss(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡env.w ¡ ¡ ¡ ¡ ¡ ¡ ¡-‑= ¡gradient ¡ ¡ ¡ ¡ ¡ ¡ ¡env.delta ¡ ¡ ¡ ¡= ¡env.lastLoss ¡-‑ ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env.lastLoss ¡= ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡} ¡ } ¡ ¡ ¡ ¡
6/5/12 27
Merge ¡into ¡one ¡ MapReduce ¡ Step ¡
6/5/12 28
def ¡train(xy:Table[Example], ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_grad:(Example, ¡Vector) ¡=> ¡Vector, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_loss:(Example, ¡Vector) ¡=> ¡Double) ¡= ¡{ ¡ ¡ ¡ ¡ ¡class ¡Env(w:VectorType, ¡lastError:DoubleType, ¡delta:DoubleType) ¡extends ¡Environment ¡ ¡ ¡ ¡ ¡val ¡initialValue ¡= ¡new ¡Env(VectorType.zeros(1000), ¡Double.MaxValue, ¡Double.MaxValue) ¡ ¡ ¡ ¡ ¡loop(initialValue, ¡(env: ¡Env) ¡=> ¡env.delta ¡< ¡eps) ¡{ ¡env ¡=> ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡gradient ¡= ¡xy.map(x=>compute_grad(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡loss ¡ ¡ ¡ ¡ ¡= ¡xy.map(x=>compute_loss(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡env.w ¡ ¡ ¡ ¡ ¡ ¡ ¡-‑= ¡gradient ¡ ¡ ¡ ¡ ¡ ¡ ¡env.delta ¡ ¡ ¡ ¡= ¡env.lastLoss ¡-‑ ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env.lastLoss ¡= ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡} ¡ } ¡ ¡ ¡ ¡
def ¡train(xy:Table[Example], ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_grad:(Example, ¡Vector) ¡=> ¡Vector, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_loss:(Example, ¡Vector) ¡=> ¡Double) ¡= ¡{ ¡ ¡ ¡ ¡ ¡class ¡Env(w:VectorType, ¡lastError:DoubleType, ¡delta:DoubleType) ¡extends ¡Environment ¡ ¡ ¡ ¡ ¡val ¡initialValue ¡= ¡new ¡Env(VectorType.zeros(1000), ¡Double.MaxValue, ¡Double.MaxValue) ¡ ¡ ¡ ¡ ¡loop(initialValue, ¡(env: ¡Env) ¡=> ¡env.delta ¡< ¡eps) ¡{ ¡env ¡=> ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡gradient ¡= ¡xy.map(x=>compute_grad(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡loss ¡ ¡ ¡ ¡ ¡= ¡xy.map(x=>compute_loss(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡env.w ¡ ¡ ¡ ¡ ¡ ¡ ¡-‑= ¡gradient ¡ ¡ ¡ ¡ ¡ ¡ ¡env.delta ¡ ¡ ¡ ¡= ¡env.lastLoss ¡-‑ ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env.lastLoss ¡= ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡} ¡ } ¡ ¡ ¡ ¡
6/5/12 29
Merge ¡into ¡one ¡ Operator ¡
6/5/12 30
def ¡train(xy:Table[Example], ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_grad:(Example, ¡Vector) ¡=> ¡Vector, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_loss:(Example, ¡Vector) ¡=> ¡Double) ¡= ¡{ ¡ ¡ ¡ ¡ ¡class ¡Env(w:VectorType, ¡lastError:DoubleType, ¡delta:DoubleType) ¡extends ¡Environment ¡ ¡ ¡ ¡ ¡val ¡initialValue ¡= ¡new ¡Env(VectorType.zeros(1000), ¡Double.MaxValue, ¡Double.MaxValue) ¡ ¡ ¡ ¡ ¡loop(initialValue, ¡(env: ¡Env) ¡=> ¡env.delta ¡< ¡eps) ¡{ ¡env ¡=> ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡gradient ¡= ¡xy.map(x=>compute_grad(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡loss ¡ ¡ ¡ ¡ ¡= ¡xy.map(x=>compute_loss(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡env.w ¡ ¡ ¡ ¡ ¡ ¡ ¡-‑= ¡gradient ¡ ¡ ¡ ¡ ¡ ¡ ¡env.delta ¡ ¡ ¡ ¡= ¡env.lastLoss ¡-‑ ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env.lastLoss ¡= ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡} ¡ } ¡ ¡ ¡ ¡
6/5/12 31
def ¡train(xy:Table[Example], ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_grad:(Example, ¡Vector) ¡=> ¡Vector, ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡compute_loss:(Example, ¡Vector) ¡=> ¡Double) ¡= ¡{ ¡ ¡ ¡ ¡ ¡class ¡Env(w:VectorType, ¡lastError:DoubleType, ¡delta:DoubleType) ¡extends ¡Environment ¡ ¡ ¡ ¡ ¡val ¡initialValue ¡= ¡new ¡Env(VectorType.zeros(1000), ¡Double.MaxValue, ¡Double.MaxValue) ¡ ¡ ¡ ¡ ¡loop(initialValue, ¡(env: ¡Env) ¡=> ¡env.delta ¡< ¡eps) ¡{ ¡env ¡=> ¡{ ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡gradient ¡= ¡xy.map(x=>compute_grad(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡val ¡loss ¡ ¡ ¡ ¡ ¡= ¡xy.map(x=>compute_loss(x,env.w)).reduce(_+_) ¡ ¡ ¡ ¡ ¡ ¡ ¡env.w ¡ ¡ ¡ ¡ ¡ ¡ ¡-‑= ¡gradient ¡ ¡ ¡ ¡ ¡ ¡ ¡env.delta ¡ ¡ ¡ ¡= ¡env.lastLoss ¡-‑ ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env.lastLoss ¡= ¡loss ¡ ¡ ¡ ¡ ¡ ¡ ¡env ¡ ¡ ¡ ¡ ¡} ¡ ¡ ¡} ¡ } ¡ ¡ ¡ ¡
Cache ¡xy ¡in ¡main ¡ memory, ¡if ¡possible ¡
6/5/12 32
MapReduce
Map() Reduce()
Sequential
Update() Aggregate Statistics (Model, Performance) Model
Loop
Continue()
Training Data
ScalOps ¡ Algebricks ¡ Physical ¡ Plan ¡ Hyracks ¡
6/5/12 33
6/5/12 34
Data Loading
HDFS
Iterative Computation
Sequential (update) HDFS
HDFS
Iteration Barrier Driver (loop)
model model
Cached Records
CR CR (map) CR CR CR (map) (map) (map) Aggregation tree (reduce)
How many? Fan-In?
6/5/12 35
6/5/12 36
6/5/12 37
6/5/12 38
6/5/12 39
6/5/12 40
6/5/12 41
Aggregation time Map time Time for not loading from Disk Processing Time
Symbol ¡ Meaning ¡ R ¡ # ¡Records ¡ M ¡ Cache ¡capacity ¡per ¡CPU ¡ P ¡ Map ¡'me ¡per ¡record ¡ D ¡ Load ¡'me ¡per ¡record ¡ A ¡ Aggrega'on ¡'me ¡per ¡record ¡
Load Time
6/5/12 42
6/5/12 43
Symbol ¡ Meaning ¡ R ¡ # ¡Records ¡ M ¡ Cache ¡capacity ¡per ¡CPU ¡ P ¡ Map ¡'me ¡per ¡record ¡ D ¡ Load ¡'me ¡per ¡record ¡ A ¡ Aggrega'on ¡'me ¡per ¡record ¡ Let R ≤ MN. The time-minimal number of machines for an Iterative Map- Reduce-Update operator is ˆ N1 = RP Ae Let R > MN. The time-minimal number of machines for an Iterative Map- Reduce-Update operator is ˆ N1 = RD + RP Ae Most ¡oAen: ¡Use ¡as ¡ many ¡machines ¡as ¡ you ¡have ¡
6/5/12 44
Symbol ¡ Meaning ¡ R ¡ # ¡Records ¡ M ¡ Cache ¡capacity ¡per ¡CPU ¡ P ¡ Map ¡'me ¡per ¡record ¡ D ¡ Load ¡'me ¡per ¡record ¡ A ¡ Aggrega'on ¡'me ¡per ¡record ¡ Let R ≤ MN. The cost-minimal number of machines for an Iterative Map- Reduce-Update operator is ˆ N1 = R M Let R > MN. The cost-minimal number of machines for an Iterative Map- Reduce-Update operator is ˆ N1 = e
MD Ae
The ¡solu'on ¡ heavily ¡depends ¡on ¡ your ¡job ¡
ScalOps ¡ Algebricks ¡ Physical ¡ Plan ¡ Hyracks ¡
6/5/12 45
6/5/12 46
6/5/12 47
6/5/12 48
6/5/12 49
50 100 150 200 Iteration time (seconds) 5 10 15 20 25 30 40 50 60 Number of machines Spark 200 400 600 800 1,000 1,200 Cost (machine-seconds) 50 100 150 200 Iteration time (seconds) 5 10 15 20 25 30 40 50 60 Number of machines Hyracks 200 400 600 800 1,000 1,200 Cost (machine-seconds) Iteration time (seconds); Cost (machine-seconds)
6/5/12 50 80 160 240 320 400 480 20 40 60 80 Dataset Size (GB) Iteration time (seconds) 80 160 240 320 400 480 2,000 4,000 6,000 8,000 10,000 12,000 14,000 16,000 Dataset Size (GB) Cost (machine-seconds) Spark C30; Hyracks C30; Hyracks C10
6/5/12 51
6/5/12 52
124.41 ¡ 127.42 ¡ 114.54 ¡ 60 ¡ 70 ¡ 80 ¡ 90 ¡ 100 ¡ 110 ¡ 120 ¡ 130 ¡ 140 ¡ Itera;on ¡;me ¡(s) ¡ VW ¡ Hyracks ¡(VW) ¡ Hyracks ¡(Op'mized) ¡
6/5/12 53
6/5/12 54
Optimizer: Cheapest Optimizer: Fastest
6/5/12 55
6/5/12 56
6/5/12 57 31 60 88 117 146 500 1,000 1,500 2,000 Number of machines Iteration time (seconds) Hadoop 20,000 40,000 60,000 Cost (machine-seconds) 31 60 88 117 146 50 100 150 200 Number of machines Iteration time (seconds) Hyracks 2,000 4,000 6,000 Cost (machine-seconds) Iteration time (seconds); Cost (machine-seconds)
User ¡ Program ¡ Logical ¡ Plan ¡ Physical ¡ Plan ¡ Execu'on ¡ Engine ¡ ScalOps ¡ Algebricks ¡ Physical ¡ Plan ¡ Hyracks ¡
6/5/12 58
Loop ¡ Aware ¡on ¡ all ¡Levels ¡
6/5/12 59
6/5/12 60
6/5/12 61