Taming the Wild: A Unified Analysis of Hogwild!-Style Algorithms
Christopher De Sa, Ce Zhang, Kunle Olukotun, Christopher Ré
Introduction
Many problems in machine learning can be written as a stochastic optimization problem
where is the step size. For most problems, this update step is easy to compute, and perhaps because of this SGD is a ubiquitous algorithm with a wide range of applications in machine learning , including neural network backpropagation , recommendation systems , and optimization . For non-convex problems, SGD is popular—in particular, it is widely used in deep learning—but its success is poorly understood theoretically.
Given SGD’s success in industry, practitioners have developed methods to speed up its computation. One popular method to speed up SGD and related algorithms is using asynchronous execution. In an asynchronous algorithm, such as Hogwild! , multiple threads run an update rule such as Equation 1 in parallel without locks. Hogwild! and other lock-free algorithms have been applied to a variety of uses, including PageRank approximations (FrogWild! ), deep learning (Dogwild! ) and recommender systems . Many asynchronous versions of other stochastic algorithms have been individually analyzed, such as stochastic coordinate descent (SGD) and accelerated parallel proximal coordinate descent (APPROX) , producing rate results that are similar to those of Hogwild! Recently, Gupta et al. gave an empirical analysis of the effects of a low-precision variant of SGD on neural network training. Other variants of stochastic algorithms have been proposed ; only a fraction of these algorithms have been analyzed in the asynchronous case. Unfortunately, a new variant of SGD (or a related algorithm) may violate the assumptions of existing analysis, and hence there are gaps in our understanding of these techniques.
One approach to filling this gap is to analyze each purpose-built extension from scratch: an entirely new model for each type of asynchrony, each type of precision, etc. In a practical sense, this may be unavoidable, but ideally there would be a single technique that could analyze many models. In this vein, we prove a martingale-based result that enables us to treat many different extensions as different forms of noise within a unified model. We demonstrate our technique with three results:
For the convex case, Hogwild! requires strict sparsity assumptions. Using our techniques, we are able to relax these assumptions and still derive convergence rates. Moreover, under Hogwild!’s stricter assumptions, we recover the previous convergence rates.
We derive convergence results for an asynchronous SGD algorithm for a non-convex matrix completion problem. We derive the first rates for asynchronous SGD following the recent (synchronous) non-convex SGD work of De Sa et al. .
We derive convergence rates in the presence of quantization errors such as those introduced by fixed-point arithmetic. We validate our results experimentally, and show that Buckwild! can achieve speedups of up to over Hogwild!-based algorithms for logistic regression.
One can combine these different methods both theoretically and empirically. We begin with our main result, which describes our martingale-based approach and our model.
Main Result
Analyzing asynchronous algorithms is challenging because, unlike in the sequential case where there is a single copy of the iterate , in the asynchronous case each core has a separate copy of in its own cache. Writes from one core may take some time to be propagated to another core’s copy of , which results in race conditions where stale data is used to compute the gradient updates. This difficulty is compounded in the non-convex case, where a series of unlucky random events—bad initialization, inauspicious steps, and race conditions—can cause the algorithm to get stuck near a saddle point or in a local minimum.
Broadly, we analyze algorithms that repeatedly update by running an update step
Our main result is a technique that allows us to bound the convergence rates of asynchronous SGD and related algorithms, even for some non-convex problems. We use martingale methods, which have produced elegant convergence rate results for both convex and some non-convex algorithms. Martingales enable us to model multiple forms of error—for example, from stochastic sampling, random initialization, and asynchronous delays—within a single statistical model. Compared to standard techniques, they also allow us to analyze algorithms that sometimes get stuck, which is useful for non-convex problems. Our core contribution is that a martingale-based proof for the convergence of a sequential stochastic algorithm can be easily modified to give a convergence rate for an asynchronous version.
A supermartingale is a stochastic process such that . That is, the expected value is non-increasing over time. A martingale-based proof of convergence for the sequential version of this algorithm must construct a supermartingale that is a function of both the time and the current and past iterates; this function informally represents how unhappy we are with the current state of the algorithm. Typically, it will have the following properties.
Second, for all times and for any sequence , if the algorithm has not succeeded by time (that is, for all ), it must hold that
This represents the fact that we are unhappy with running for many iterations without success.
Using this, we can easily bound the convergence rate of the sequential version of the algorithm.
Assume that we run a sequential stochastic algorithm, for which is a rate supermartingale. For any , the probability that the algorithm has not succeeded by time is
In what follows, we let denote the actual value taken on by the function in a process defined by (2). That is, . By applying (3) recursively, for any ,
By the law of total expectation applied to the failure event ,
Applying (4), i.e. , and recalling that is nonnegative results in
rearranging terms produces the result in Statement 1. ∎
This technique is very general; in subsequent sections we show that rate supermartingales can be constructed for SGD on all convex problems and for some algorithms for non-convex problems.
The behavior of an asynchronous SGD algorithm depends both on the problem it is trying to solve and on the hardware it is running on. For ease of analysis, we assume that the hardware has the following characteristics. These are basically the same assumptions used to prove the original Hogwild! result .
There are multiple threads running iterations of (2), each with their own cache. At any point in time, these caches may hold different values for the variable , and they communicate via some cache coherency protocol.
There exists a central store (typically RAM) at which all writes are serialized. This provides a consistent value for the state of the system at any point in real time.
If a thread performs a read of a previously written value , and then writes another value (dependent on ), then the write that produced will be committed to before the write that produced .
Each write from an iteration of (2) is to only a single entry of and is done using an atomic read-add-write instruction. That is, there are no write-after-write races (handling these is possible, but complicates the analysis).
2 Convergence Rates for Asynchronous SGD
Now that we are equipped with a stochastic model for the asynchronous SGD algorithm, we show how we can use a rate supermartingale to give a convergence rate for asynchronous algorithms. To do this, we need some continuity and boundedness assumptions; we collect these into a definition, and then state the theorem.
An algorithm with rate supermartingale is -bounded if the following conditions hold. First, must be Lipschitz continuous in the current iterate with parameter ; that is, for any , , , and sequence ,
Third, the expected magnitude of the update must be bounded by . That is, for any ,
Assume that we run an asynchronous stochastic algorithm with the above hardware model, for which is a -bounded rate supermartingale with horizon . Further assume that . For any , the probability that the algorithm has not succeeded by time is
Note that this rate depends only on the worst-case expected delay and not on any other properties of the hardware model. Compared to the result of Statement 1, the probability of failure has only increased by a factor of . In most practical cases, , so this increase in probability is negligible.
Since the proof of this theorem is simple, but uses non-standard techniques, we outline it here. First, notice that the process , which was a supermartingale in the sequential case, is not in the asynchronous case because of the delayed updates. Our strategy is to use to produce a new process that is a supermartingale in this case. For any and , if for all , we define
Compared with , there are two additional terms here. The first term is negative, and cancels out some of the unhappiness from (4) that we ascribed to running for many iterations. We can interpret this as us accepting that we may need to run for more iterations than in the sequential case. The second term measures the distance between recent iterates; we would be unhappy if this becomes large because then the noise from the delayed updates would also be large. On the other hand, if for some , then we define
We call a stopped process because its value doesn’t change after success occurs. It is straightforward to show that is a supermartingale for the asynchronous algorithm. Once we know this, the same logic used in the proof of Statement 1 can be used to prove Theorem 1.
Theorem 1 gives us a straightforward way of bounding the convergence time of any asynchronous stochastic algorithm. First, we find a rate supermartingale for the problem; this is typically no harder than proving sequential convergence. Second, we find parameters such that the problem is -bounded, typically ; this is easily done for well-behaved problems by using differentiation to bound the Lipschitz constants. Third, we apply Theorem 1 to get a rate for asynchronous SGD. Using this method, analyzing an asynchronous algorithm is really no more difficult than analyzing its sequential analog.
Applications
Now that we have proved our main result, we turn our attention to applications. We show, for a couple of algorithms, how to construct a rate supermartingale. We demonstrate that doing this allows us to recover known rates for Hogwild! algorithms as well as analyze cases where no known rates exist.
We make the standard assumption that is strongly convex with parameter ; that is, for all and
We require that the second moment of the gradient sample is also bounded for some by
For some , we let the success region be
Under these conditions, we can construct a rate supermartingale for this algorithm.
There exists a where, if the algorithm hasn’t succeeded by timestep ,
such that is a rate submartingale for the above algorithm with horizon . Furthermore, it is -bounded with parameters: , , and .
Using this and Theorem 1 gives us a direct bound on the failure rate of convex Hogwild! SGD.
Assume that we run an asynchronous version of the above SGD algorithm, where for some constant we choose step size
Then for any , the probability that the algorithm has not succeeded by time is
2 Convex Case, Low Precision Arithmetic
Assume that we run asynchronous low-precision convex SGD, and for some , we choose step size
then for any , the probability that the algorithm has not succeeded by time is
Typically, we choose a precision such that ; in this case, the increased error compared to the result of Corollary 1 will be negligible and we will converge in a number of samples that is very similar to the high-precision, sequential case. Since each Buckwild! update runs in less time than an equivalent Hogwild! update, this result means that an execution of Buckwild! will produce same-quality output in less wall-clock time compared with Hogwild!
3 Non-Convex Case, High Precision Arithmetic
Many machine learning problems are non-convex, but are still solved in practice with SGD. In this section, we show that our technique can be adapted to analyze non-convex problems. Unfortunately, there are no general convergence results that provide rates for SGD on non-convex problems, so it would be unreasonable to expect a general proof of convergence for non-convex Hogwild! Instead, we focus on a particular problem, low-rank least-squares matrix completion,
De Sa et al. provide a martingale-based rate of convergence for a particular SGD algorithm, Alecton, running on this problem. For simplicity, we focus on only the rank-1 version of the problem, and we assume that, at each timestep, a single entry of is used as a sample. Under these conditions, Alecton uses the update rule
That is, we are only concerned with the direction of , not its magnitude; this algorithm only recovers the dominant eigenvector of , not its eigenvalue. In order to show convergence for this entrywise sampling scheme, De Sa et al. require that the matrix satisfy a coherence bound .
They also require that the step size be set, for some constants and as
For ease of analysis, we add the additional assumptions that our algorithm runs in some bounded space. That is, for some constant , at all times , and . As in the convex case, by following the martingale-based approach of De Sa et al. , we are able to generate a rate supermartinagle for this algorithm—to save space, we only state its initial value and not the full expression.
For the problem above, choose any horizon such that . Then there exists a function such that is a rate supermartingale for the above non-convex SGD algorithm with parameters , , and , and
Note that the analysis parameter allows us to trade off between , which determines how long we can run the algorithm, and the initial value of the supermartingale . We can now produce a corollary about the convergence rate by applying Theorem 1 and setting and appropriately.
Assume that we run Hogwild! Alecton under these conditions for timesteps, as defined below. Then the probability of failure, , will be bounded as below.
The fact that we are able to use our technique to analyze a non-convex algorithm illustrates its generality. Note that it is possible to combine our results to analyze asynchronous low-precision non-convex SGD, but the resulting formulas are complex, so we do not include them here.
Experiments
We validate our theoretical results for both asynchronous non-convex matrix completion and Buckwild!, a Hogwild! implementation with lower-precision arithmetic. Like Hogwild!, a Buckwild! algorithm has multiple threads running an update rule (2) in parallel without locking. Compared with Hogwild!, which uses 32-bit floating point numbers to represent input data, Buckwild! uses limited-precision arithmetic by rounding the input data to 8-bit or 16-bit integers. This not only decreases the memory usage, but also allows us to take advantage of single-instruction-multiple-data (SIMD) instructions for integers on modern CPUs.
We verified our main claims by running Hogwild! and Buckwild! algorithms on the discussed applications. Table 1 shows how the training loss of SGD for logistic regression, a convex problem, varies as the precision is changed. We ran SGD with step size ; however, results are similar across a range of step sizes. We analyzed all four datasets reported in DimmWitted that favored Hogwild!: Reuters and RCV1, which are text classification datasets; Forest, which arises from remote sensing; and Music, which is a music classification dataset. We implemented all GLM models reported in DimmWitted, including SVM, Linear Regression, and Logistic Regression, and report Logistic Regression because other models have similar performance. The results illustrate that there is almost no increase in training loss as the precision is decreased for these problems. We also investigated 4-bit and 1-bit computation: the former was slower than 8-bit due to a lack of 4-bit SIMD instructions, and the latter discarded too much information to produce good quality results.
Figure 1(a) displays the speedup of Buckwild! running on the dense-version of the RCV1 dataset compared to both full-precision sequential SGD (left axis) and best-case Hogwild! (right axis). Experiments ran on a machine with two Xeon X650 CPUs, each with six hyperthreaded cores, and 24GB of RAM. This plot illustrates that incorporating low-precision arithmetic into our algorithm allows us to achieve significant speedups over both sequential and Hogwild! SGD. (Note that we don’t get full linear speedup because we are bound by the available memory bandwidth; beyond this limit, adding additional threads provides no benefits while increasing conflicts and thrashing the L1 and L2 caches.) This result, combined with the data in Table 1, suggest that by doing low-precision asynchronous updates, we can get speedups of up to on these sorts of datasets without a significant increase in error.
Conclusion
This paper presented a unified theoretical framework for producing results about the convergence rates of asynchronous and low-precision random algorithms such as stochastic gradient descent. We showed how a martingale-based rate of convergence for a sequential, full-precision algorithm can be easily leveraged to give a rate for an asynchronous, low-precision version. We also introduced Buckwild!, a strategy for SGD that is able to take advantage of modern hardware resources for both task and data parallelism, and showed that it achieves near linear parallel speedup over sequential algorithms.
The Buckwild! name arose out of conversations with Benjamin Recht. Thanks also to Madeleine Udell for helpful conversations.
The authors acknowledge the support of: DARPA FA8750-12-2-0335; NSF IIS-1247701; NSF CCF-1111943; DOE 108845; NSF CCF-1337375; DARPA FA8750-13-2-0039; NSF IIS-1353606; ONR N000141210041 and N000141310129; NIH U54EB020405; Oracle; NVIDIA; Huawei; SAP Labs; Sloan Research Fellowship; Moore Foundation; American Family Insurance; Google; and Toshiba.
References
Appendix A Proof of Theorem 1
This proof is a more detailed version of the argument outlined in Section 2.2. First, we restate the definition of the process from the body of the paper. As long as the algorithm hasn’t succeeded yet,
Re-indexing the second sum and applying the definition of produces
Applying the Lipschitz continuity assumption (8) for results in
Taking the expected value of both sides produces
Applying the rate supermartingale property (3) of ,
Finally, applying the update distance bound (10),
where the 1-norm is equal to the 2-norm here because each step only updates a single entry of . Substituting this result in to the above equation allows us to conclude that, if the algorithm hasn’t succeeded by time ,
On the other hand, if it has succeeded, this statement will be vacuously true, since does not change after success occurs. Therefore, (19) will hold for all times.
In what follows, as in the proof of Statement 1, we let denote the actual value taken on by the function during execution of the algorithm. That is, . By applying (19) recursively, for any , we can show that
Since we assumed as part of our hardware model that for ,
Therefore, by the law of total expectation
Since is a rate supermartingale, we can apply (4) to get
and solving for produces
Appendix B Proofs for Convex Case
First, we state the rate supermartingale lemma for the low-precision convex SGD algorithm.
such that is a rate submartingale for the above convex SGD algorithm with horizon . Furthermore, it is -bounded with parameters: , , and
We note that, including this Lemma, the results in Section 3.1 are the same as the results in Section 3.2, except that the quantization factor is set as . It follows that it is sufficient to prove only the Lemma and Corollary in 3.2; this is what we will do here.
In order to prove the results in this section, we will need some definitions and lemmas, which we state now.
For the purposes of this document, we define the piecewise logarithm function to be
The piecewise logarithm function is differentiable and concave. Also, if , then for any ,
The first part of the lemma follows from the fact that is a piecewise function, where the pieces are both increasing and concave, and the fact that the function is differentiable at . The second part of the lemma follows from the fact that a first-order approximation always overestimates a concave function. ∎
Armed with this definition, we prove Lemma 3.
First, we note that, at any timestep , if we evaluate the distance to the optimum at the next timestep using (11), then
Since we assigned ,
Applying the strong convexity assumption (12),
Now, if we haven’t succeeded yet, then . Under these conditions,
Multiplying both sides of the equation by and taking the piecewise logarithm, by Jensen’s inequality
Since , we can apply Lemma 4, which gives us
Now, we define the rate supermartingale such that, if we haven’t succeeded up to time , then
otherwise, if is a time such that , then for all ,
The first rate supermartingale property (3) is true because if success hasn’t occurred,
it is vacuously true if success has occurred because the value of does not change after for . The second rate supermartingale property (4) holds because, if success hasn’t occurred by time ,
this follows from the non-negativity of the function for non-negative arguments.
We have now shown that is a rate supermartingale for this algorithm. Next, we verify that the bound on given in the lemma statement holds. At time , by the definition of the function, since we assume that success has not occurred yet,
this is the bound given in the lemma statement.
Next, we show that this rate supermartingale is -bounded, for the values of , , and given in the lemma statement. First, for any , , and sequence ,
Now, by the definition of , we can conclude that . Therefore,
Clearly, this expression is maximized when . Therefore,
The Lipschitz continuity expression with in the lemma statement now follows from the mean value theorem.
Finally, we bound the update expression with . We have,
Applying the bounds on the rounding error,
Applying the assignment results in
So, we have proved all the statements in the lemma. ∎
Applying Theorem 1 directly to the result of Lemma 1 produces
Substituting the chosen value of ,
Appendix C Proofs for Non-Convex Case
In order to accomplish this proof, we make use of some definitions and lemmas that appear in De Sa et al. . We state them here before proceeding to the proof.
Clearly, . Using this function, De Sa et al. prove the following lemma. While their version of the lemma applies to higher-rank problems and multiple distributions, we state here a version that is specialized for the rank-1, entrywise sampling case we study in this paper. (This is a combination of Lemma 2 and Lemma 12 from De Sa et al. .)
If we run the Alecton update rule using entrywise sampling under the conditions in Section 3.3, including the incoherence and step size assignment, then for any ,
We also use another lemma from De Sa et al. . This is a combination of their Lemmas 1 and 7.
If we initialize with a uniform random angle (as done in Alecton), then
First, if , then . Therefore,
From the result of Lemma 5, for any ,
Therefore, by Jensen’s inequality and Lemma 4, since ,
Now, we define our rate supermartingale. First, define
and let be any constant. Let be defined such that, if for all , then
On the other hand, if for some , then for all , we define
That is, once enters , the process stops changing.
We verify that is a rate supermartingale. First, (3) is true because, in the case that the process has stopped it is true vacuously, and in the case that it hasn’t stopped (i.e. for all ),
Since , it follows that . Therefore,
The second rate supermartingale property (4) holds because, if success hasn’t occurred by time , then there are two possibilities: either the process hasn’t stopped yet, or it stopped at a timestep where . In the former case, by the non-negativity of the function,
We have now shown that is a rate supermartingale for Alecton. Next, we show that our bound on the initial value of the supermartingale holds. At time ,
Now, we show that is -bounded. First, we give the bound. To do so, we first differentiate .
Applying the assumption that ,
Now, differentiating with respect to produces
Applying our assumption that , it is clear that this function will be maximized when . Therefore,
Next, we give the bound. For Alecton, we have
This agrees with our assignment of .
Finally, we give our bound on the magnitude of the updates. By the same argument as above, we will have
Applying the assumption that , produces the bound given in the lemma, .
Next, we prove the corollary that gives a bound on the failure probability of asynchronous Alecton.
By Theorem 1, we know that for the constants defined in Lemma 2,
If we choose for the horizon in Lemma 2, and substitute in the given constants,
Now, for the given value of , we will have
Also, for the given values of and , we will have
Appendix D Simplified Convex Result
In this section, we provide a simplified proof for a result similar to our main result that only works in the convex case. This proof does not use any martingale results, and can therefore be considered more elementary than the proofs given above; however, it does not generalize to the non-convex case.
Under the conditions given in Section 3.1, for any , if for some we choose constant step size
Our goal is to bound the square-distance to the optimum by showing that it generally decreases at each timestep. We can show algebraically that
We can now take the full expected value given the filtration, which produces
and since only at most one entry of changes at each iteration,
Finally, taking the full expected value, and applying Cauchy-Schwarz again,
if we let , we get
For any , as long as ,
If we substitute the value of chosen in the theorem statement, then
Therefore, for any , if for all ,