In the current architecture, a significant limitation arises due to the requirement that either every GPU involved in training must hold the entire model state, or they must communicate with ms latency, virtually functionning as 1 big GPU to ensure that gradient propagation is efficiently done.
The same problem arise during inference step, where the GPU must hold the whole stuff in memory in RAM at the same time.
This blog post aim to develop 2 approaches to reduce :
- the dependency to a centralized system during training, by providing practical compute algorithms examples.
- overall RAM dependency during inference through efficient nodes pre-loading in RAM.
Those 2 things seems very important stepping stones to make LLM@home-like projects emerging, and popularized decentralizedly-trained, lightweight, efficient LLMs.
This document aims to give a bit of context to the suggested algorithm, and to explain why and how we obtained it.
- First, we try to give some elements to explain why neural networks with several layers are solving previously unsolvable problems, albeit at high computational training costs.
- Second, we will try to guess where those training costs are coming from, and what practical constraints it causes.
- Third, we are going to establish why the "gradient descent", despite its disadvantages, still works
- Fourth, we are going to establish the properties of a "perfect neural network layer", and see that because of forward thinking fitting the n-th layer does not require to know the n+i-th layers.
- Fifth, we will establish why fitting a "perfect neural network layer" is a hard problem.
- Sixth, we will finally suggest an empirical way of fitting them, that could have a better "learning density" (how much compute it takes to converge), and that would be more parallelizable than gradient descent.
When you are making a computer program, you are trying to find a compromise between several metrics :
- Computation speed
$s$ during program execution. - Computation speed
$t$ during program construction. - Size of the program
$q$ - Accuracy of the program
$a$ Given a price cost$p(s, a, q, t)$ ; your budget$B$ and an objective cost$o(s,a,q,t)$ you are trying to find$$\max_{s,a,q,t \text{ u.c. } p(s,a,q,t) < B} o(s,a,q,t)$$ How does it looks like in practice ? Let's look at a simple example Conway's game of life). Suppose you want to plot, given a state$u_0$ , the state after$n$ iterations,$u_n$ , on a$k \times k$ grid.
Two extreme ways to do this with perfect accuracy
- Method 1: if
$f$ transforms a state$u_n$ into$u_{n+1}$ through some rules, and$u_n = f(...f(u_0))$ , you could pre-compute$g = f \circ \dots \circ f$ and store it. In this solution, you have the lowest speed$s$ but a high$t$ and$q$ . Method 1 is probably out of budget because of$q$ and$t$ - Method 2: you can simply store
$f$ and apply it$n$ times.$t$ and$q$ are very low, but$s$ is high. Method 2 is probably out of budget because of$s$ .
Neither ways to do this is very efficient. You would probably like
What are possible practical tradeoffs ?
- Compared to method 1, you can avoid explicitely computing the entirety of
$g$ , leaving some part "compressed" to diminish$t$ and$q$ , but augmenting$s$ . - Compared to method 1, if you do not care about having a perfect model, you could throw away part of
$g$ that "in practice" never called (i.e. given your "usual inputs"). You diminish$t$ and$q$ , leave$s$ constant, but diminish$a$ .
Deep neural network architecture :
- encapsulates a hierarchical features representation (which is the native design of a lot of practical things like text or image), therefore maintains
$a$ high while reducing$q$ and$s$ - only stores features that are seen in real data (random noise is much more dense than real data, but the model does not learn on random data), reducing
$q$ while maintaining a high$a$ in practice. - Express thoses deduced rules in a fast-to-compute framework, therefore reducing
$s$
But, and that the topic of this article, the
The problem is not deep learning itself, but the gradient descent training method. It has 2 main drawbacks.
- First, you need to fit the whole network at once : it means having all the weight in RAM simultaneously, or have a very low latency between connected machines if you want to split training on several machines.
- Second, you can't really parallelize the training. Given a data
$X$ , you need to compute your predicted label$\hat Y$ , and then modify your weights, before doing another prediction. One may still use batches, but with a need to limit their size in order to maximize generalisation. - Third, gradient descent probably does not maximises the use it makes from data at each step. The problem of finding the best neural networks, as we will see further, is non-convex, and thus data probably can't be exploited as optimally as in a linear regression modeling, but one can probably find algorithms that more reliably improves the "density of usage of data".
To illustrate the third point, let's compare two ways of fitting a simple linear regression model with one predictor (X) and an intercept:
- The least-squares method (closed-form solution) finds the optimal parameters in one step by solving the normal equation:
$\theta = (X^T X)^{-1} X^T Y$
This method is extremely efficient because it directly computes the best-fitting parameters without iteration. It fully leverages the entire dataset in a single matrix operation, making it optimal in terms of data usage and convergence speed.
- Gradient descent, in contrast, updates the parameters iteratively:
$\theta_{t+1} = \theta_t - \alpha \nabla L(\theta_t)$
where
Suppose another simple problem. You have a 2x2 pixel grid and want to train a neural network to recognize diagonals. Here are the pixel numbering and shapes we are trying to recognize for reference.
![[Pasted image 20250121104735.png]]
A neural network that would return 1 if the pattern is a diagonal and 0 else could be achieved with a 2-neurons hidden layer and a 1-neuron output layer, as demonstrated here : (the activation function of every neurons is : $\mathbb{1}(aX + b \ge 0)$). Here is an example of possible learned weights :
![[Pasted image 20250121102611.png]] You can see that the "Hidden 1" neuron has learnt to recognize the second diagonal and "Hidden 2" the first diagonal.
If you were training the hidden neurons independently, initialized with random weight, they could converged to fitting the same diagonal.
Gradient descent backpropagation empirically works as an "learning manager", organizing the learning process of a layer.
When you train using backpropagation on the diagonals problem, you can expect to converge to the solution. This is because backpropagation empirically detects that, if a neuron is already fitted on the first diagonal, exploring with the other neuron weights does not degrade the whole network accuracy. Thus, gradient descent "manages knowledge": it (in average) allows neurons that do not have learn something useful to explore.
Let :
-
$X$ be a random variable representing your feature, -
$Y$ be a random variable representing your label.
Usually, the goal of your model is presented as such : Finding
The main problem of this approach is that in order to measure the performance
Let :
-
$f_1, \dots f_l$ being the$l$ neurons of my first network layer. -
$\bar f$ being the next layers of my network.
We can thus express
Fortunately, the answer is yes ! There is an indicator, called mutual information, that can be practically approximated, and that verifies :
$$ \max_{f_1, \dots, f_l}{I(Y; f_1(X), ... f_n(X))} = \max_{f_1, \dots, f_l, \bar f}{I(Y; \bar f(f_1(X), ..., f_n(X))} \ge I(Y, \hat Y), \forall{\hat Y}$$ with equality case for the best possible estimator.
Note that the estimator
since
Thus, if you can somehow solve this
The problem is non-convex, and thus not analytically solvable. but the following algorithm build iteratively
This algorithm is easy to parallelize, without much communication between machines (at least, much less often than using backpropagation). and could be used to decentralizedly train large neural networks models.
The backpropagation method is trying to solve the same problem :
$$ \max_{f_1, \dots, f_l}{I(Y; f_1(X), ... f_l(X))}$$
but it takes
Given those data, let us find the hyperplan that best separate the data, i.e. that maximizes mutual information.
![[Pasted image 20250115164214.png]]
Given our data, let us define
-
$S$ the random variable associated to the the shape (circle or triangle), -
$X$ the random variable associated to the shape position. -
$X_{\alpha} = \mathbb{1}(X \ge alpha)$ defines on which side of$\alpha$ the random variable is. -
$f : \alpha \longrightarrow I(S ; X_{alpha})$ representing the mutual information gained by knowing$X_{\alpha}$ value.
Finding our best hyperplan is equivalent to finding
![[Pasted image 20250116085336.png]]
2. Even if you solve this non-convex problem, the greedy algorithm does not converge to the optimal solution.
Let us take this example
![[Pasted image 20250115114128.png]]
The best hyperplans to separate data are clearly the following
![[Pasted image 20250115114744.png]]
The main problem is that a greedy algorithm that would find the best possible hyperplan, would not converge to this solution, since both
![[Pasted image 20250116151124.png]]
Of course, after convergence, you would probably have something like this :
![[Pasted image 20250116151435.png]]
That would contain
The algorithm would look like : while the weighted entropy potential is above a certain threshold, add a new Hyperplan to separate the data. Once the layer is created, repeat with next layer.
But how to efficiently find the "next best hyperplan" I will propose one highly parallelizable algorithm that converges, but this is probably not the best one. Some further research should probably be made to find empirical improvements. I will precisely detail where I am doing approximations.
The idea is :
- Take the subzone defined by the already created hyperplans with the biggest potential for mutual information improvement, or the whole space if it is the first iteration.
- Compute the weighted center of mass of the
$n$ classes. Then do a hierarchical clustering to separate them in 2 groups, and compute 2 new center of mass. Finally, split the space orthogonally to the segment defined by the 2 obtained centers of mass (the centers should be on different sides of the hyperplan). This will always increase the mutual information if the 2 centers are distinct points. You can either split in the middle or look for a better split point manually, or even use techniques similar to Maximum margin separation algorithm - Repeat until the mutual information potential gain (weighted entropy) is too limited.
- Prune the network to find redundant hyperplans (by computing the mutual information of the layer minus this hyperplan for all defined hyperplans)
Note that :
- Choose the next hyperplan based only on a subzone is suboptimal
- Choose the next hyperplan with the center of mass technique guarantees a mutual information gain, but not that the gain will be the biggest (see 1D example).
But also, note that :
- Several subzones can be studied in parallel.
- Center of mass can be computed in parallel.
- Mutual information potential gain can be computed in parallel (actually, this is weighted entropy of the remaining zones)
If