Mini-Batch Primal and Dual Methods for SVMs
Martin Takáč, Avleen Bijral, Peter Richtárik, Nathan Srebro
Introduction
Stochastic optimization approaches have been shown to have significant theoretical and empirical advantages in training linear Support Vector Machines (SVMs), as well as in many other learning applications, and are often the methods of choice in practice. Such methods use a single, randomly chosen, training example at each iteration. In the context of SVMs, approaches of this form include primal stochastic gradient descent (SGD) methods (e.g., Pegasos, Shalev-Shwartz et al. 2011, NORMA, Zhang 2004) and dual stochastic coordinate ascent (Hsieh et al., 2008).
However, the inherent sequential nature of such approaches becomes a problematic limitation for parallel and distributed computations as the predictor must be updated after each training point is processed, providing very little opportunity for parallelization. A popular remedy is to use mini-batches. That is, to use several training points at each iteration, instead of just one, calculating the update based on each point separately and aggregating the updates. The question is then whether basing each iteration on several points can indeed reduce the number of required iterations, and thus yield parallelization speedups.
In this paper, we consider using mini-batches with Pegasos (SGD on the primal objective) and with Stochastic Dual Coordinate Ascent (SDCA). We show that for both methods, the quantity that controls the speedup obtained using mini-batching/parallelization is the spectral norm of the data.
In Section 3 we provide the first analysis of mini-batched Pegasos (with the original, non-smooth, SVM objective) that provably leads to parallelization speedups (Theorem 1). The idea of using mini-batches with Pegasos is not new, and is discussed already by Shalev-Shwartz et al. (2011), albeit without a theoretical justification. The original Pegasos theoretical analysis does not benefit from using mini-batches—the same number of iterations is required even when large mini-batches are used, there is no speedup, and the serial runtime (overall number of operations, in this case data accesses) increases linearly with the mini-batch size. In fact, no parallelization speedup can be guaranteed based only on a bound on the radius of the data, as in the original Pegasos analysis. Instead, we provide a refined analysis based on the spectral norm of the data.
We then move on to SDCA (Section 4). We show the situation is more involved, and a modification to the method is necessary. SDCA has been consistently shown to outperform Pegasos in practice (Hsieh et al., 2008; Shalev-Shwartz et al., 2011), and is also popular as it does not rely on setting a step-size as in Pegasos. It is thus interesting and useful to obtain mini-batch variants of SDCA as well. We first show that a naive mini-batching approach for SDCA can fail, in particular when the mini-batch size is large relative to the spectral norm (Section 4.1). We then present a “safe” variant of mini-batched SDCA, which depends on the spectral norm, and an analysis for this safe variant that establishes the same spectral-norm-dependent parallelization speedups as for Pegasos (Section 4.2). Similar to a recent analysis of non-mini-batched SDCA by Shalev-Shwartz & Zhang (2012), we establish a guarantee on the duality gap, and thus also on the sub-optimality of the primal SVM objective, when using mini-batched SDCA (Theorem 2). We then go on to describe a more aggressive, adaptive, method for mini-batched SDCA, which is based on the analysis of the “safe” approach, and which we show often outperforms it in practice (Section 4.3, with experiments in Section 5).
For simplicity of presentation we focus on the hinge loss, as in the SVM objective. However, all our results for both Pegasos and SDCA are valid for any Lipschitz continuous loss function.
Several recent papers consider the use of mini-batches in stochastic gradient descent, as well as stochastic dual averaging and stochastic mirror descent, when minimizing a smooth loss function (Dekel et al., 2012; Agarwal & Duchi, 2011; Cotter et al., 2011). These papers establish parallelization speedups for smooth loss minimization with mini-batches, possibly with the aid of some “acceleration” techniques, and without relying on, or considering, the spectral norm of the data. However, these results do not apply to SVM training, where the objective to be minimized is the non-smooth hinge loss. In fact, the only data assumption in these papers is an assumption on the radius of the data, which is not enough for obtaining parallelization guarantees when the loss is non-smooth. Our contribution is thus orthogonal to these papers, showing that it is possible to obtain parallelization speedups even for non-smooth objectives, but only with a dependence on the spectral norm. We also analyze SDCA, which is a substantially different method from the methods analyzed in these papers. It is interesting to note that a bound of the spectral norm could perhaps indicate that it is easier to “smooth” the objective, and thus allow obtaining results similar to ours (i.e. on the suboptimality of the original non-smooth objective) by smoothing the objective and relying on mini-batched smooth SGD, where the spectral norm might control how well the smoothed loss captures the original loss. But we are not aware of any analysis of this nature, nor whether such an analysis is possible.
Support Vector Machines
where is a regularization trade-off parameter. It is also useful to consider the dual of (1):
is the Gram matrix of the (labeled) data. The (primal) optimum of (1) is given by , where is the (dual) optimum of (2). It is thus natural to associate with each dual solution a primal solution (i.e., a linear predictor)
Mini-Batches in Primal Stochastic Gradient Descent Methods
Pegasos is an SGD approach to solving (1), where at each iteration the iterate is updated based on an unbiased estimator of a sub-gradient of the objective . Whereas in a “pure” stochastic setting, the sub-gradient is estimated based on only a single training example, in our mini-batched variation (Algorithm 1) at each iteration we consider the partial objective:
where . We then calculate the subgradient of the partial objective at :
and if and otherwise (indicator for not classifying example correctly with a margin). The next iterate is obtained by setting . We can now write
Analysis of mini-batched Pegasos rests on bounding the norm of the subgradient estimates . An unconditional bound on this norm, used in the standard Pegasos analysis, follows from bounding
From (7) we then get ; the standard Pegasos analysis follows. This bound relies only on the assumption , and is the tightest bound without further assumptions on the data.
The core novel observation here is that the expected (square) norm of can be bounded in terms of (an upper bound on) the spectral norm of the data:
where denotes the spectral norm (largest singular value) of a matrix. In order to bound , we first perform the following calculation, introducing the key quantity , useful also in the analysis of SDCA.
We can now apply Lemma 1 to :
Using the by-now standard analysis of SGD for strongly convex functions, we obtain the main result of this section:
After iterations of Pegasos with mini-batches (Algorithm 1), we have that for the averaged iterate :
Unrolling (9) with yields
where . Using the inequality , we now get
The performance guarantee is now given by the analysis of SGD with tail averaging (Theorem 5 of Rakhlin et al. 2012, with and ). ∎
Parallelization speedup. When we have (see (11)) and Theorem 1 agrees with the standard (serial) Pegasos analysisExcept that we avoid the logarithmic factor by relying on tail averaging and a more modern SGD analysis. (Shalev-Shwartz et al., 2011). For larger mini-batches, the guarantee depends on the quantity , which in turn depends on the spectral norm . Since , we have .
However, when , and so , we see a benefit in using mini-batches in Theorem 1, corresponding to a parallelization speedup of . The best situation is when , and so , which happens when all training points are orthogonal. In this case there is never any interaction between points in the mini-batch, and using a mini-batch of size is just as effective as making single-example steps. When we indeed see that the speedup speedup is equal to the number of mini-batches, and that the behavior in terms of the number of data accesses (equivalently, serial runtime) , does not depend on ; that is, even with larger mini-batches, we require no more data accesses, and we gain linearly from being able to perform the accesses in parallel. The case is rather extreme, but even for intermediate values we get speedup. In particular, as long as , we have , and an essentially linear speedup. Roughly speaking, captures the number of examples in the mini-batch beyond which we start getting significant interactions between points.
Mini-Batches in Dual Stochastic Coordinate Ascent Methods
An alternative stochastic method to Pegasos is Stochastic Dual Coordinate Ascent (SDCA, Hsieh et al. 2008), aimed to solve the dual problem (2). At each iteration we choose a single training example , uniformly at random, corresponding to a single dual variable (coordinate) . Subsequently, is updated so as to maximize the (dual) objective, keeping all other coordinates of unchanged and maintaining the box constraints. At iteration , the update to is computed via
where is projection onto the interval . Variables for are unchanged. Hence, a single iteration has the form . Similar to a Pegasos update, at each iteration a single, random, training point is considered, the “response” is calculated (this operation dominates the computational effort), and based on the response, a multiple of is added to the weight vector (corresponding to changing ). The two methods thus involve fairly similar operations at each iteration, with essentially identical computational costs. They differ in that in Pegasos, is changed according to some pre-determined step-size, while SDCA changes it optimally so as to maximize the dual objective (and maintain dual feasibility); there is no step-size parameter.
A naive approach to parallelizing SDCA using mini-batches is to compute in parallel, according to (14), for all , all based on the current iterate , and then update for , and keep for . However, not only might this approach not reduce the number of required iterations, it might actually increase the number of required iterations. This is because the dual objective need not improve monotonically (as it does for “pure” SDCA), and even not converge.
To see this, consider an extreme situation with only two identical training examples: , and mini-batch size (i.e., in each iteration we use both examples). If we start with with then and following the naive approach we have with objective value . In the next iteration which brings us back to . So the algorithm will alternate between those two solutions with objective value , while at the optimum .
This is of course a simplistic toy example, but the same phenomenon will occur when a large number of training examples are identical or highly correlated. This can also be observed empirically in some of our experiments discussed later, e.g., in Figure 2.
The problem here is that since we update each independently to its optimal value as if all other coordinates were fixed, we are ignoring interactions between the updates. As we see in the extreme example above, two different , might suggest essentially the same change to , but we would then perform this update twice, overshooting and yielding a new iterate which is actually worse then the previous one.
2 Safe Mini-Batching
Instead, we propose a “safe” variant, where the term is approximately bounded by the separable surrogate , for some which we will discuss later. That is, the update is given by:
with for , and for . In essence, serves as a step-size, where we are now careful not to take steps so big that they will accumulate together and overshoot the objective. If handling only a single point at each iteration, such a short-step approach is not necessary, we do not need a step-size, and we can take a “full step”, setting optimally (). But with the potential for interaction between coordinates updated in parallel, we must use a smaller step, depending on the potential for such interactions.
We will first rely on the bound (10), and establish that the choice as in (11) provides for a safe step size. To do so, we consider the dual objective at ,
and the following separable approximation to it:
in which replaces . Our update (15) with can be written as (we then use the coordinates for and ignore the rest). We are essentially performing parallel coordinate ascent on the separable approximation instead of on . To understand this approximation, we note that , and show that provides an approximate expected lower bound on :
Inequalities of this general type are also studied in (Richtárik & Takáč, 2012) (see Sections 3 and 4). Based on the above lemma, we can modify the analysis of Shalev-Shwartz & Zhang (2012) to obtain (see complete proof in the appendix):
Consider the SDCA updates given by (15), with , starting from and with (given in eq. (11)). For any and
The number of iterations of mini-batched SDCA, sufficient to reach primal suboptimality , is by Theorem 2 equal to
We observe the same speedup as in the case of mini-batched Pegasos: factor of , with an essentially linear speedup when . It is interesting to note that the quantity only affects the second, -dependent, term in (22). The “fixed cost” term, which essentially requires a full pass over the data, is not affected by , and is always scaled down by .
3 Aggressive Mini-Batching
Using is safe, but might be too safe/conservative. In particular, we used the spectral norm to bound in Lemma 3 (through Lemma 1), but this is a worst case bound over all possible vectors, and might be loose for the relevant vectors . Relying on a worst-case bound might mean we are taking much smaller steps then we could be. Furthermore, the approach we presented thus far relies on knowing the spectral norm of the data, or at least a bound on the spectral norm (recall (10)), in order to set the step-size. Although it is possible to estimate this quantity by sampling, this can certainly be inconvenient.
Instead, we suggest a more aggressive variant of mini-batched SDCA which gradually adapts based on the actual values of and .
In Section 5 one can observe advantages of this aggressive strategy.
Experiments
In Figure 2 we demonstrate the evolution of solutions using the various methods for two specific data sets. Here we can again see the relative behaviour of the methods, as well as clearly see the failure of the naive approach, which past some point causes the objective to deteriorate and does not converge to the optimal solution.
Conclusion
Contribution. Our contribution in this paper is twofold: (i) we identify the spectral norm of the data, and through it the quantity , as the important quantity controlling guarantees for mini-batched/parallelized Pegasos (primal method) and SDCA (dual method). We provide the first analysis of mini-batched Pagasos, with the non-smooth hinge-loss, that shows speedups, and we analyze for the first time mini-batched SDCA with guarantees expressed in terms of the primal problem (hence, our mini-batched SDCA is a primal-dual method); (ii) based on our analysis, we present novel variants of mini-batched SDCA which are necessary for achieving speedups similar to those of Pegasos, and thus open the door to effective mini-batching using the often-empirically-better SDCA.
Related work. Our safe SDCA mini-batching approach is similar to the parallel coordinate descent methods of Bradley et al. (2011) and Richtárik & Takáč (2012), but we provide an analysis in terms of the primal SVM objective, which is the more relevant object of interest. Furthermore, Bradley et al.’s analysis does not use a step-size and is thus limited only to small enough mini-batches—if the spectral norm is unknown and too large a mini-batch is used, their method might not converge. Richtárik & Takáč’s method does incorporate a fixed step-size, similar to our safe variant, but as we discuss this step-size might be too conservative for achieving the true potential of mini-batching.
Generality. We chose to focus on Pegasos and SDCA with regularized hinge-loss minimization, but all our results remain unchanged for any Lipschitz loss functions. Furthermore, Lemma 2 can also be used to establish identical speedups for mini-batched SGD optimization of , as well as for direct stochastic approximation of the population objective (generalization error) . In considering the population objective, the sample size is essentially infinite, we sample with replacements (from the population), is a bound on the second moment of the data distribution, and .
Experiments. Our experiments confirm the empirical advantages of SDCA over Pegasos, previously observed without mini-batching. However, we also point out that in order to perform mini-batched SDCA effectively, a step-size is needed, detracting from one of the main advantages of SDCA over Pegasos. Furthermore, in the safe variant, this stepsize needs to be set according to the spectral norm (or bound on the spectral norm), with too small a setting for (i.e., too large steps) possibly leading to non-convergence, and too large a setting for yielding reduced speedups. In contrast, the Pegasos stepsize is independent of the spectral norm, and in a sense Pegasos adapts implicitly (see, e.g., its behavior compared to aggressive SDCA in the experiments). We do provide a more aggressive variant of SDCA, which does match Pegasos’s speedups empirically, but this requires an explicit heuristic adaptation of the stepsize.
Parallel Implementation. In this paper we analyzed the iteration complexity, and behavior of the iterates, of mini-batched Pegasos and SDCA. Unlike “pure” (=1) Pegasos and SDCA, which are not amenable to parallelization, using mini-batches does provide opportunities for it. Of course, actually achieving good parallelization speedups on a specific architecture in practice requires an efficient parallel, possibly distributed, implementation of the iterations. In this regard, we point out that the core computation required for both Pegasos and SDCA is that of computing , where is some scalar function. Parallelizing such computations efficiently in a distributed environment has been studied by e.g., Dekel et al. (2012); Hsu et al. (2011); their methods can be used here too. Alternatively, one could also consider asynchronous or delayed updates (Agarwal & Duchi, 2011; Niu et al., 2011).
References
Appendix A Proof of Theorem 2
The proof of Theorem 2 follows mostly along the path of Shalev-Shwartz & Zhang (2012), crucially using Lemma 3, and with a few other required modifications detailed below.
The separable approximation defined in (17) now has the more general form:
and all the properties mentioned in Section 4, including Lemma 3, still hold.
Our goal here is to get a bound on the duality gap, which we will denote by
The analysis now rests on the following lemma, paralleling Lemma 1 of Shalev-Shwartz & Zhang (2012), which bounds the expected improvement in the dual objective after a single iteration in terms of the duality gap:
The situation here is trickier then in the case considered by Shalev-Shwartz & Zhang, and we will first bound the right hand side of (26) by and then use the fact that is a minimizer of :
We will bound the change in the dual sub-optimality :
Following the proof of Shalev-Shwartz & Zhang we will now show by induction that
Clearly, (30) implies that (31) holds for . Now, if it holds for some , we show that it also holds for . Using in (28) we have:
where in the last inequality we used the arithmetic-geometric mean inequality. This establishes (31).
Now, for the average defined in (21) we have:
Now, we can ensure the above is at most if we require:
Combining the requirements (29), (34) and (35) with and , and recalling that for the hinge loss and with we have gives the requirements in Theorem 2. ∎