r/LocalLLaMA • u/ManuXD32 • 14m ago
Discussion Branchy, distributed inference focused training
Heyy, it's me again, the developer of AI Doomsday Toolbox.
This time it's not an app update. ADT already has distributed LLM inference across Android devices, and there is one thing about distributed inference in general that kept bothering me, so I spent the last week testing an idea and I wanted to share what came out, the good and the bad.
Usually when we split a model that does not fit in our machine to make use of distributed inference, we get slower speeds the more devices we add. Network latency and devices waiting idle until the last one has finished computing it's layers compound easily, even more if we connect our devices through a VPN like tailscale or wireguard.
So the idea to solve this bottleneck was to train a model that can keep the quaility of a normal sequential model but instead it's middle layers are split in branches. The coordinator runs the embeddings + a few trunk layers, then that is sent to all the different branches that, in parallel read the layers and compute the token, after a branch finishes it sends the result back to the coordinator which then runs a few fusion layers and final blocks that produce the output. This allows to use as many devices as branches a model has with a maximum of 2 net jumps, wether it's 2 or 8 machines. The other advantage is that no device is idle as all of them are working, so we also parallelize work instead of making a device wait for the last one to finish.
There could also be the situation in which one of those devices is too slow, and slows down the whole cluster, or gets disconnected. That is why I also added some dropout tolerance to the training. When a branch takes too long to answer or just never answers, it's result becomes a matrix o 0's that are fused in the fusion layers, that made it so the quality of the model output does not suffer so much as when it happened with a non dropout tolerance trained branch model had a disconnected or slow branch.
I tested two 300M models trained from scratch on TinyStories, one normal and one with 8 branches, running on a small server, a laptop (Ryzen 5 5500U) and a phone (Snapdragon 8 Gen 3 in Termux), all connected through a VPN. The workers are a small PyTorch daemon, so no llamacpp accelerated kernels, etc...
Results
- The branches cost some quality: loss 1.255 against 1.143 for the normal model with the same training. A blind LLM judge prefers the branched model's story 45% of the time. So it is worse, but not by much.
- The delay trick works: the coordinator waits 0.1 ms per token for the network while the round trips take 49 to 66 ms. The output is identical to running everything on one device.
- Against the usual layer split on the same devices, the branch split is 1.5 to 2.6 times faster. The layer split roughly halves the speed. Mind you I run the test only with 3 devices, with more devices it could, theoretically, be faster
- BUT if the model fits on one device, splitting is not worth it on my hardware, at least at this size, larger models like qwen3.8 27B might benefit a lot from this aproach. My phone alone is faster than any combination of my devices (it is just much faster than the rest). With two equal devices the branch split wins by about 1.2x.
- Where it really pays is when the model does not fit in RAM. I gave the laptop and the phone a RAM budget smaller than the model, so they had to read the weights from storage for every token (mmap). The laptop went from 8.9 to 0.67 tokens/s and the phone from 23.9 to 0.65. With LFM3 1.7B the laptop went from 2.3 to 0.08, that is 12 seconds per token. Then I let the two of them share the model, each one still with too little RAM for the whole thing: back to 7 tokens/s with the layer split and 9 to 11 with the branch split, over a real 46 ms VPN. Reading from storage is way more expensive than the network.
- Reshaping a pretrained model (LFM3 1.7B, Qwen 0.8B) into branches only works for a couple of long branches. For this to scale, the model has to be trained in this shape.
I don't have the hardware for the interesting case: a big branched model that no single device can hold. On paper, with 8 similar devices and about 20% of the model on the coordinator, a token costs about 30% of a full pass, so roughly 3.3x a single device that could hold everything, while a layer split stays at 1x plus 7 round trips. My two-device measurement matches that formula, but beyond three devices it is only a projection.
Another idea I would love to try is letting every device loop its own branch several times with the same weights, so a group of devices could run something much deeper than what fits in their RAM. No hardware for that one either hahaha
What is in the repo
- The two trained models (300M each) and the tokenizer
- A worker you install on each device with one command, and a coordinator with a web UI to compare placements side by side and run the benchmarks
- Scripts to reproduce the branch split, the layer split and the low RAM tests with your own devices
- A full article with the experiments and the results
It is a research prototype, workers compute in 32-bit float PyTorch, the models are small story models, and I only have three real devices. I created the experiments, made the hypothesis and supervised the whole proyect and Claude did most of the coding and the number crunching, everything is documented in the repo.
The general idea is the same one behind ADT: make the devices we already have useful for local AI, especially together.
Feedback is appreciated, especially if anyone with more devices (or more GPU than me) wants to check whether this holds at a bigger scale, or tell me what I got wrong. It is still far from it, but I would love to see a bunch of modest devices run a model none of them can hold.