51
Adaptive Learning Rates, Inference, and Algorithms other than SGD CS6787 Lecture 8 — Fall 2019

Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Adaptive Learning Rates, Inference, and Algorithms other

than SGD

CS6787 Lecture 8 — Fall 2019

Page 2: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Adaptive learning rates

• So far, we’ve looked at update steps that look like

• Here, the learning rate/step size is fixed a priori for each iteration.

• What if we use a step size that varies depending on the model?

• This is the idea of an adaptive learning rate.

wt+1 = wt � ↵trft(wt)<latexit sha1_base64="kn2CCBTj11TsMB31ze7r2wsjmFA=">AAACEXicbZA9SwNBEIb34nf8ilraLAZBEcOdCNoIoo1lBJMISTjmNnvJkr29Y3fOEI78BRv/io2FIrZ2dv4bNx+FJr6w8PDODLPzBokUBl3328nNzS8sLi2v5FfX1jc2C1vbVROnmvEKi2Ws7wMwXArFKyhQ8vtEc4gCyWtB93pYrz1wbUSs7rCf8GYEbSVCwQCt5RcOen6GR96AXtCej/SYNkAmHbDYUBBIoKGPtgcP/ULRLbkj0VnwJlAkE5X9wlejFbM04gqZBGPqnptgMwONgkk+yDdSwxNgXWjzukUFETfNbHTRgO5bp0XDWNunkI7c3xMZRMb0o8B2RoAdM10bmv/V6imG581MqCRFrth4UZhKijEdxkNbQnOGsm8BmBb2r5R1QANDG2LehuBNnzwL1ZOSZ/n2tHh5NYljmeySPXJAPHJGLskNKZMKYeSRPJNX8uY8OS/Ou/Mxbs05k5kd8kfO5w+56puw</latexit><latexit sha1_base64="kn2CCBTj11TsMB31ze7r2wsjmFA=">AAACEXicbZA9SwNBEIb34nf8ilraLAZBEcOdCNoIoo1lBJMISTjmNnvJkr29Y3fOEI78BRv/io2FIrZ2dv4bNx+FJr6w8PDODLPzBokUBl3328nNzS8sLi2v5FfX1jc2C1vbVROnmvEKi2Ws7wMwXArFKyhQ8vtEc4gCyWtB93pYrz1wbUSs7rCf8GYEbSVCwQCt5RcOen6GR96AXtCej/SYNkAmHbDYUBBIoKGPtgcP/ULRLbkj0VnwJlAkE5X9wlejFbM04gqZBGPqnptgMwONgkk+yDdSwxNgXWjzukUFETfNbHTRgO5bp0XDWNunkI7c3xMZRMb0o8B2RoAdM10bmv/V6imG581MqCRFrth4UZhKijEdxkNbQnOGsm8BmBb2r5R1QANDG2LehuBNnzwL1ZOSZ/n2tHh5NYljmeySPXJAPHJGLskNKZMKYeSRPJNX8uY8OS/Ou/Mxbs05k5kd8kfO5w+56puw</latexit><latexit sha1_base64="kn2CCBTj11TsMB31ze7r2wsjmFA=">AAACEXicbZA9SwNBEIb34nf8ilraLAZBEcOdCNoIoo1lBJMISTjmNnvJkr29Y3fOEI78BRv/io2FIrZ2dv4bNx+FJr6w8PDODLPzBokUBl3328nNzS8sLi2v5FfX1jc2C1vbVROnmvEKi2Ws7wMwXArFKyhQ8vtEc4gCyWtB93pYrz1wbUSs7rCf8GYEbSVCwQCt5RcOen6GR96AXtCej/SYNkAmHbDYUBBIoKGPtgcP/ULRLbkj0VnwJlAkE5X9wlejFbM04gqZBGPqnptgMwONgkk+yDdSwxNgXWjzukUFETfNbHTRgO5bp0XDWNunkI7c3xMZRMb0o8B2RoAdM10bmv/V6imG581MqCRFrth4UZhKijEdxkNbQnOGsm8BmBb2r5R1QANDG2LehuBNnzwL1ZOSZ/n2tHh5NYljmeySPXJAPHJGLskNKZMKYeSRPJNX8uY8OS/Ou/Mxbs05k5kd8kfO5w+56puw</latexit><latexit sha1_base64="kn2CCBTj11TsMB31ze7r2wsjmFA=">AAACEXicbZA9SwNBEIb34nf8ilraLAZBEcOdCNoIoo1lBJMISTjmNnvJkr29Y3fOEI78BRv/io2FIrZ2dv4bNx+FJr6w8PDODLPzBokUBl3328nNzS8sLi2v5FfX1jc2C1vbVROnmvEKi2Ws7wMwXArFKyhQ8vtEc4gCyWtB93pYrz1wbUSs7rCf8GYEbSVCwQCt5RcOen6GR96AXtCej/SYNkAmHbDYUBBIoKGPtgcP/ULRLbkj0VnwJlAkE5X9wlejFbM04gqZBGPqnptgMwONgkk+yDdSwxNgXWjzukUFETfNbHTRgO5bp0XDWNunkI7c3xMZRMb0o8B2RoAdM10bmv/V6imG581MqCRFrth4UZhKijEdxkNbQnOGsm8BmBb2r5R1QANDG2LehuBNnzwL1ZOSZ/n2tHh5NYljmeySPXJAPHJGLskNKZMKYeSRPJNX8uY8OS/Ou/Mxbs05k5kd8kfO5w+56puw</latexit>

Page 3: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Example: Polyak’s step length

• This is an simple step size scheme for gradient descent that works when the optimal value is known.

• Can also use this with an estimated optimal value.

↵k =f(wk)� f(w⇤)

krf(wk)k2<latexit sha1_base64="eix1RGYidE4ceUYOVzyydhd3mKs=">AAACIXicbZDNSgMxFIUz/tb6V3XpJliEVlBmimA3QtGNSwVbhU473EkzbWgmMyQZpUz7Km58FTcuFHEnvoxpOwttvRD4OOdebu7xY86Utu0va2FxaXllNbeWX9/Y3Nou7Ow2VJRIQusk4pG890FRzgSta6Y5vY8lhdDn9M7vX479uwcqFYvErR7EtBVCV7CAEdBG8gpVF3jcA6+Pz7EbSCBpUHr0+mV8jA20j8qj1B1iV4DPAWeWO2xXRl6haJ/Yk8Lz4GRQRFlde4VPtxORJKRCEw5KNR071q0UpGaE01HeTRSNgfShS5sGBYRUtdLJhSN8aJQODiJpntB4ov6eSCFUahD6pjME3VOz3lj8z2smOqi2UibiRFNBpouChGMd4XFcuMMkJZoPDACRzPwVkx6YnLQJNW9CcGZPnodG5cQxfHNarF1kceTQPjpAJeSgM1RDV+ga1RFBT+gFvaF369l6tT6sz2nrgpXN7KE/ZX3/AOR4oXk=</latexit><latexit sha1_base64="eix1RGYidE4ceUYOVzyydhd3mKs=">AAACIXicbZDNSgMxFIUz/tb6V3XpJliEVlBmimA3QtGNSwVbhU473EkzbWgmMyQZpUz7Km58FTcuFHEnvoxpOwttvRD4OOdebu7xY86Utu0va2FxaXllNbeWX9/Y3Nou7Ow2VJRIQusk4pG890FRzgSta6Y5vY8lhdDn9M7vX479uwcqFYvErR7EtBVCV7CAEdBG8gpVF3jcA6+Pz7EbSCBpUHr0+mV8jA20j8qj1B1iV4DPAWeWO2xXRl6haJ/Yk8Lz4GRQRFlde4VPtxORJKRCEw5KNR071q0UpGaE01HeTRSNgfShS5sGBYRUtdLJhSN8aJQODiJpntB4ov6eSCFUahD6pjME3VOz3lj8z2smOqi2UibiRFNBpouChGMd4XFcuMMkJZoPDACRzPwVkx6YnLQJNW9CcGZPnodG5cQxfHNarF1kceTQPjpAJeSgM1RDV+ga1RFBT+gFvaF369l6tT6sz2nrgpXN7KE/ZX3/AOR4oXk=</latexit><latexit sha1_base64="eix1RGYidE4ceUYOVzyydhd3mKs=">AAACIXicbZDNSgMxFIUz/tb6V3XpJliEVlBmimA3QtGNSwVbhU473EkzbWgmMyQZpUz7Km58FTcuFHEnvoxpOwttvRD4OOdebu7xY86Utu0va2FxaXllNbeWX9/Y3Nou7Ow2VJRIQusk4pG890FRzgSta6Y5vY8lhdDn9M7vX479uwcqFYvErR7EtBVCV7CAEdBG8gpVF3jcA6+Pz7EbSCBpUHr0+mV8jA20j8qj1B1iV4DPAWeWO2xXRl6haJ/Yk8Lz4GRQRFlde4VPtxORJKRCEw5KNR071q0UpGaE01HeTRSNgfShS5sGBYRUtdLJhSN8aJQODiJpntB4ov6eSCFUahD6pjME3VOz3lj8z2smOqi2UibiRFNBpouChGMd4XFcuMMkJZoPDACRzPwVkx6YnLQJNW9CcGZPnodG5cQxfHNarF1kceTQPjpAJeSgM1RDV+ga1RFBT+gFvaF369l6tT6sz2nrgpXN7KE/ZX3/AOR4oXk=</latexit><latexit sha1_base64="eix1RGYidE4ceUYOVzyydhd3mKs=">AAACIXicbZDNSgMxFIUz/tb6V3XpJliEVlBmimA3QtGNSwVbhU473EkzbWgmMyQZpUz7Km58FTcuFHEnvoxpOwttvRD4OOdebu7xY86Utu0va2FxaXllNbeWX9/Y3Nou7Ow2VJRIQusk4pG890FRzgSta6Y5vY8lhdDn9M7vX479uwcqFYvErR7EtBVCV7CAEdBG8gpVF3jcA6+Pz7EbSCBpUHr0+mV8jA20j8qj1B1iV4DPAWeWO2xXRl6haJ/Yk8Lz4GRQRFlde4VPtxORJKRCEw5KNR071q0UpGaE01HeTRSNgfShS5sGBYRUtdLJhSN8aJQODiJpntB4ov6eSCFUahD6pjME3VOz3lj8z2smOqi2UibiRFNBpouChGMd4XFcuMMkJZoPDACRzPwVkx6YnLQJNW9CcGZPnodG5cQxfHNarF1kceTQPjpAJeSgM1RDV+ga1RFBT+gFvaF369l6tT6sz2nrgpXN7KE/ZX3/AOR4oXk=</latexit>

Page 4: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Intuition: Polyak’s step length

• Approximate the objective with a linear approximation at the current iterate.

• Choose the step size that makes the approximation equal to the known optimal value.

Page 5: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Example: Line search

• Idea: just choose the step size that minimizes the objective.

• Only works well for gradient descent, not SGD.

• Why?• SGD moves in random directions that don’t always improve the objective.• Doing line search on full objective is expensive relative to SGD update.

↵k = argmin↵>0

f(wk � ↵rf(wk))<latexit sha1_base64="PR7QSNzEJ7PvDgpuXkXIPZw1M8s=">AAACKHicbZDLSsNAFIYnXmu9VV26GSxCu7AkIuhGLbpxWcFeoCnhZDpph04mYWailNDHceOruBFRpFufxGmbhbYeGPj5/nM4c34/5kxp2x5bS8srq2vruY385tb2zm5hb7+hokQSWicRj2TLB0U5E7Sumea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c9p0x/cTvzmI5WKReJBD2PaCaEnWMAIaIO8wrULPO6DN8CX2AXZw27IhJfOKL7C9ggHpSdjn+CMuQJ8DjNaLnuFol2xp4UXhZOJIsqq5hXe3W5EkpAKTTgo1XbsWHdSkJoRTkd5N1E0BjKAHm0bKSCkqpNODx3hY0O6OIikeULjKf09kUKo1DD0TWcIuq/mvQn8z2snOrjopEzEiaaCzBYFCcc6wpPUcJdJSjQfGgFEMvNXTPoggWiTbd6E4MyfvCgapxXH6PuzYvUmiyOHDtERKiEHnaMqukM1VEcEPaNX9IE+rRfrzfqyxrPWJSubOUB/yvr+Aek5pAA=</latexit><latexit sha1_base64="PR7QSNzEJ7PvDgpuXkXIPZw1M8s=">AAACKHicbZDLSsNAFIYnXmu9VV26GSxCu7AkIuhGLbpxWcFeoCnhZDpph04mYWailNDHceOruBFRpFufxGmbhbYeGPj5/nM4c34/5kxp2x5bS8srq2vruY385tb2zm5hb7+hokQSWicRj2TLB0U5E7Sumea0FUsKoc9p0x/cTvzmI5WKReJBD2PaCaEnWMAIaIO8wrULPO6DN8CX2AXZw27IhJfOKL7C9ggHpSdjn+CMuQJ8DjNaLnuFol2xp4UXhZOJIsqq5hXe3W5EkpAKTTgo1XbsWHdSkJoRTkd5N1E0BjKAHm0bKSCkqpNODx3hY0O6OIikeULjKf09kUKo1DD0TWcIuq/mvQn8z2snOrjopEzEiaaCzBYFCcc6wpPUcJdJSjQfGgFEMvNXTPoggWiTbd6E4MyfvCgapxXH6PuzYvUmiyOHDtERKiEHnaMqukM1VEcEPaNX9IE+rRfrzfqyxrPWJSubOUB/yvr+Aek5pAA=</latexit>

Page 6: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Adaptive methods for SGD

• Several methods exist• AdaGrad• AdaDelta• RMSProp• Adam

• You’ll see Adam in one of this Wednesday’s papers

Page 7: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

AdaGradAdaptive gradient descent

Page 8: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Per-parameter adaptive learning rate schemes

• Main idea: set the learning rate per-parameter dynamically at each iteration based on observed statistics of the past gradients.

• Where the step size now depends on the parameter index j• Corresponds to a multiplication of the gradient by a diagonal scaling matrix.

• There are many different schemes in this class

Page 9: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

AdaGrad: One of the first adaptive methods

• AdaGrad: Adaptive subgradient methods for online learning and stochastic optimization• J Duchi, E Hazan, Y Singer• Journal of Machine Learning Research, 2011

• High level approach: can use history of sampled gradients to choose the step size for the next SGD step to be inversely proportional to the usual magnitude of gradient steps in that direction• On a per-parameter basis.

Page 10: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

AdaGradCan think of this as like

the norm of the gradients in the jth

parameter.

Page 11: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Memory-efficient implementation of AdaGrad

Important thing to notice: step size is

monotonically decreasing!

Page 12: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Demo

Page 13: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

AdaGrad for Non-convex Optimization

• What problems might arise when using AdaGrad for non-convex optimization?• Think about the step size always decreasing. Could this cause a problem?

• If you do think of a problem that might arise, how could you change AdaGrad to fix it?

Page 14: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

RMSProp Just replaces the gradient accumulation

of AdaGrad with an exponential moving

average.

Page 15: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

A systems perspective

• What is the computational cost of AdaGrad and RMSProp?• How much additional memory is required compared to baseline SGD?• How much additional compute is used?

Page 16: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Adaptive methods, summed up

• Generally useful when we can expect there to be different scales for different parameters• But can even work well when that doesn’t happen, as we saw in the demo.

• Very commonly used class of methods for training ML models.

• We’ll see more of this when we study Adam on Wednesday• Adam is basically RMSProp + Momentum.

Page 17: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Algorithms other than SGD

Page 18: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Machine learning is not just SGD

• Once a model is trained, we need to use it to classify new examples• This inference task is not computed with SGD

• There are other algorithms for optimizing objectives besides SGD• Stochastic coordinate descent• Derivative-free optimization

• There are other common tasks, such as sampling from a distribution• Gibbs sampling and other Markov chain Monte Carlo methods• And we sometimes use this together with SGD à called contrastive divergence

Page 19: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Why understand these algorithms?

• They represent a significant fraction of machine learning computations• Inference in particular is huge

• You may want to use them instead of SGD• But you don’t want to suddenly pay a computational penalty for doing so because

you don’t know how to make them fast

• Intuition from SGD can be used to make these algorithms faster too• And vice-versa

Page 20: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Inference Algorithms

Page 21: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Inference

• Suppose that our training loss function looks like

• Inference is the problem of computing the prediction

f(w) =1

N

nX

i=1

l(y(w;xi), yi)

y(w;xi)

Page 22: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

How important is inference?

• Train once, infer many times• Many production machine learning systems just do inference

• Image recognition, voice recognition, translation• All are just applications of inference once they’re trained

• Need to get responses to users quickly• On the web, users won’t wait more than a second

Page 23: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Inference on linear models

• Computational cost: relatively low• Just a matrix-vector multiply

• But still can be more costly in some settings• For example, if we need to compute a random kernel feature map• What is the cost of this?

• Which methods can we use to speed up inference in this setting?

Page 24: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Inference on neural networks

• Just need to run the forward pass of the network.• A bunch of matrix multiplies and non-linear units.

• Unlike backpropagation for learning, here we do not need to keep the activations around for later processing.

• This makes inference a much simpler task than learning.• Although it can still be costly — it’s a lot of linear algebra to do.

Page 25: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Inference on neural networks (continued)

• Computational cost: relatively high• Several matrix-vector multiplies and non-linear elements

• Which methods can we use to speed up inference in this setting?

• Compression• Find an easier-to-compute network with similar accuracy by fine-tuning• We’ll see this in more detail later in the course.

Page 26: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Metrics for Inference

• Important metric: throughput• How many examples can we classify in some amount of time

• Important metric: latency• How long does it take to get a prediction for a single example

• Important metric: model size• How much memory do we need to store/transmit the model for prediction

• Important metric: energy use• How much energy do we use to produce each prediction

• What are examples where we might care about each metric?

Page 27: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Improving the performance of inferenceWe can use many of the methods we’ve already discussed!

Page 28: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Altering the batch size

• Just like with learning, we can make predictions in batches

• Increasing the batch size helps improve parallelism• Provides more work to parallelize and an additional dimension for parallelization• This improves throughput

• But increasing the batch size can make us do more work before we can return an answer for any individual example• Can negatively affect latency

Page 29: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Demo

Page 30: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Compression

• Find an easier-to-compute network with similar accuracy• Or find a network with smaller model size, depending on the goal

• Many techniques for doing this• We’ll talk about this later in the semester when we come back to it

• Usually involve some sort of fine-tuning• Apply a lossy compression operation, then retrain the model to improve accuracy

Page 31: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Efficient architectures

• Some neural network architectures are designed to be efficient at inference time• Examples: MobileNet, ShuffleNet, CirCNN

• These networks are often based on sparsely connected neurons• This limits the number of weights which makes models smaller and easier to run

inference on

• To be efficient, we can just train one of these networks in the first place for our application.

Page 32: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Re-use of computation

• For video and time-series data, there is a lot of redundant information from one frame to the next.

• We can try to re-use some of the computation from previous frames.

• This is less popular than some of the other approaches here, because it is not really general.

Page 33: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

The last resort for speeding up DNN inference

• Train another, faster type of model that is not a deep neural network• For some real-time applications, you can’t always use a DNN

• If you can get away with a linear model, that’s almost always much faster.

• Also, decision trees tend to be quite fast for inference.

Page 34: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Where do we run inference?The hardware that underlies the systems side of inference

Page 35: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Inference in the cloud

•Most inference today is run on cloud platforms

• The cloud supports large amounts of compute• And makes it easy to access it and make it reliable

• This is a good place to put AI that needs to think about data

• For interactive models, latency is critical

Page 36: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Inference on edge devices

• Inference can run on your laptop or smartphone• Here, the size of the model becomes more of an issue• Limited smartphone memory

• This is good for user privacy and security• But not as good for companies that want to keep their models private

• Also can be used to deploy personalized models

Page 37: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Inference on sensors

• Sometimes we want inference right at the source• On the sensor where data is collected

• Example: a surveillance camera taking video• Don’t want to stream the video to the cloud, especially if most of it is

not interesting.

• Energy use is very important here.

Page 38: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Other Techniques for Training, Besides SGD

Page 39: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Coordinate Descent

• Start with objective

• Choose a random index i, and update

• And repeat in a loop

minimize:f(x1, x2, . . . , xn)

xi = argminxi

f(x1, x2, . . . , xi, . . . , xn)<latexit sha1_base64="qPJzMLlt8qIoRvD6H/dNsH8HhpY=">AAACLnicbZBdS8MwFIZTP+f8qnrpTXAICjJaEfRGEEXwcoL7gHWUNEu3sDQtyalslP0ib/wreiGoiLf+DLOtoG4eCHl433NIzhskgmtwnFdrbn5hcWm5sFJcXVvf2LS3tms6ThVlVRqLWDUCopngklWBg2CNRDESBYLVg97VyK/fM6V5LO9gkLBWRDqSh5wSMJJvX/d9js+xR1QHexGXfuZ1CWCjDnF40PfdI8PHR9gT7Ri0uXP3R+n78tC3S07ZGReeBTeHEsqr4tvPXjumacQkUEG0brpOAq2MKOBU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2MKOBUsGHRSzVLCO2RDmsalCRiupWN1x3ifaO0cRgrcyTgsfp7IiOR1oMoMJ0Rga6e9kbif14zhfCslXGZpMAknTwUpgJDjEfZ4TZXjIIYGCBUcfNXTLtEEQom4aIJwZ1eeRZqx2XX8O1J6eIyj6OAdtEeOkAuOkUX6AZVUBVR9ICe0Bt6tx6tF+vD+py0zln5zA76U9bXN49apmY=</latexit><latexit sha1_base64="qPJzMLlt8qIoRvD6H/dNsH8HhpY=">AAACLnicbZBdS8MwFIZTP+f8qnrpTXAICjJaEfRGEEXwcoL7gHWUNEu3sDQtyalslP0ib/wreiGoiLf+DLOtoG4eCHl433NIzhskgmtwnFdrbn5hcWm5sFJcXVvf2LS3tms6ThVlVRqLWDUCopngklWBg2CNRDESBYLVg97VyK/fM6V5LO9gkLBWRDqSh5wSMJJvX/d9js+xR1QHexGXfuZ1CWCjDnF40PfdI8PHR9gT7Ri0uXP3R+n78tC3S07ZGReeBTeHEsqr4tvPXjumacQkUEG0brpOAq2MKOBUsGHRSzVLCO2RDmsalCRiupWN1x3ifaO0cRgrcyTgsfp7IiOR1oMoMJ0Rga6e9kbif14zhfCslXGZpMAknTwUpgJDjEfZ4TZXjIIYGCBUcfNXTLtEEQom4aIJwZ1eeRZqx2XX8O1J6eIyj6OAdtEeOkAuOkUX6AZVUBVR9ICe0Bt6tx6tF+vD+py0zln5zA76U9bXN49apmY=</latexit>

Page 40: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Variants

• Coordinate descent with derivative and step size• Sometimes called “stochastic coordinate descent”

• The same thing, but with a gradient estimate rather than the full gradient.

• How do these compare to SGD?

xt+1,i = xt,i � ↵t ·@f

@xi(xt,1, xt,2, . . . , xt,n)

<latexit sha1_base64="gxSAhKzM433PyMIRqPSR7CwmFtc=">AAACUXicbZFLS+RAFIVvZxwf7Yy243I2hY3gMI4kIuhGEN24VLBV6DThprpiF1YqoepGbEL+4izGlf/D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ning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Derivative Free Optimization (DFO)

• Optimization methods that don’t require differentiation

• Basic coordinate descent is actually an example of this

• Another example: for normally distributed ε

• Applications?

xt+1 = xt � ↵f(xt + �✏)� f(xt � �✏)

2�✏

Page 42: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Another Task: Sampling

Page 43: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Focus problem for this setting:Statistical Inference• Major class of machine learning applications• Goal: draw conclusions from data using a statistical model• Formally: find marginal distribution of unobserved variables given observations

• Example: decide whether a coin is biased from a series of flips

• Applications: LDA, recommender systems, text extraction, data cleaning, data integration etc.

Page 44: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Popular algorithms used forstatistical inference at scale• Markov-chain Monte Carlo methods (MCMC)• Infer by simulating a Markov chain — a random process — that we can prove

will converge to the distribution we want to sample from over time• Asymptotically exact, but approximate for any finite execution time

• Variational inference• Infer by solving an optimization problem that models the target distribution as a

member of a tractable family of distributions.• Can use many of the same techniques for speedup we have discussed in class.• Approximate method, since the class may not contain the real distribution.

Page 45: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Examples of Markov Chain Monte Carlo Methods• Gradient-based methods• Stochastic gradient Langevin dynamics• Hamiltonian Monte Carlo• Stochastic gradient Hamiltonian Monte Carlo

• Non-gradient-based methods• Gibbs sampling• Metropolis-Hastings

Page 46: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Graphical models

• A graphical way to describe a probability distribution

• Common in machine learning applications• Especially for applications that deal with uncertainty

• Useful for doing statistical inference at scale• Because we can leverage techniques for computing on large graphs

Page 47: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

What types of inference exist here?

• Maximum-a-posteriori (MAP) inference• Find the state with the highest probability• Often reduces to an optimization problem• What is the most likely state of the world?

• Marginal inference• Compute the marginal distributions of some variables• What does our model of the world tell us about this object or event?

Page 48: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

x1

x2

x3

x4x5 x7

x6

Algorithm 1 Gibbs sampling

Require: Variables xi for 1 i n, and distribution ⇡.loop

Choose s by sampling uniformly from {1, . . . , n}.Re-sample xs uniformly from P⇡(xs|x{1,...,n}\{s}).output x

end loop

What is Gibbs Sampling?Choose a variable to update at random.

Update the variable by sampling from its

conditional distribution.

Compute its conditional distribution given the

other variables.Output the current state as a sample.

x4

x6

x7

P( ) = 0.7

P( ) = 0.3x5

x5

x5x5

Page 49: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Learning on graphical models

• Contrastive divergence• SGD on top of Gibbs sampling

• The de facto way of training• Restricted boltzmann machines (RBM)• Deep belief networks (DBN)• Knowledge-base construction (KBC) applications

Page 50: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

What do all these algorithms look like?Stochastic Iterative AlgorithmsGiven an immutable input dataset and a model we want to output.

Repeat:

1. Pick a data point at random

2. Update the model

3. Iterate

same structure

same systems properties

same techniques

Page 51: Adaptive Learning Rates, Inference, and Algorithms other ... · Adaptive learning rates •So far, we’ve looked at update steps that look like •Here, the learning rate/step size

Questions?

• Upcoming things• Project proposals due today• Paper Presentation #6a and #6b on Wednesday

• On adaptive learning rate methods