Width vs. Depth: Speculating on the Margin

原始链接: https://blog.doubleword.ai/speculating-on-the-margin

相关文章

原文

Here’s a fun

  1. Run at batch size 22 by batching 22 random user sequences together.
  2. Run at batch size 11, speculating 11 token ahead — so the verify works on 22 positions, the token you just sampled plus one draft — with a per-token acceptance rate α\alpha.

Which is better, assuming you only care about the total number of tokens being output per second?

Here’s a sensible answer:

Assuming that everything is memory bound, batching is always better for α<1\alpha<1

But here’s something that comes out when you do the modelling:

Spending your 2 positions on one speculating sequence produces, globally, more output tokens per second than spending them on a batch of 2, even with α=0.9\alpha=0.9

How come?

To find out, we ought to look at the data

First, the empirical distribution of routed experts

Surprisingly non-uniform! Fitting the rank-vs-share curve, it decays roughly exponentially with rank: the busiest expert pulls several times its fair share

This doesn’t by itself explain anything. But — let’s look at the difference between the two choices on the table when we decide between width and depth: work on two randomly chosen tokens, or on two tokens that follow one from the other:

The distinct experts one verify forward touches as NN grows, three ways: NN separate sequences (width), one sequence running NN consecutive positions (depth), and the uniform coupon-collector.

So there’s the answer. At batch size 1 we’re memory-bound, and verifying a two-position speculative run moves less expert weight than adding a second sequence would. It does so by co-activation — speculated runs are more similar than randomly chosen data, so they activate more of the same experts

This is a toy problem, though it’s interesting to think about how we could make use of the insight

Batches formed over the life of the inference engine are not homogeneous: some decode requests are much easier to speculate from than others. If we can get some sense of how confident the drafter is, we can spend depth only where we need it, saving both drafter

The first question is how much variation there is across sequences in how many tokens get accepted — if there’s none, this isn’t worth doing at all. It turns out there’s a lot. The number of committed tokens isn’t clustered around the mean: on a given round the drafter tends to be right about almost everything it drafts, or wrong almost immediately. Rounds split between ‘mostly misses’ and ‘clean sweeps’

A single fixed depth across the batch has to compromise between those two populations, deep enough to cash in the easy rounds, shallow enough not to waste too much verification time on requests that will be almost all rejections.

In fact, the drafter already has an opinion about which kind of round it is before the verifier runs. Below, we plot the accept length the drafter’s own per-depth confidences imply — the sum of their cumulative products — against the total length that actually committed. The diagonal is ‘perfectly calibrated’: i.e. the empirical accepted tokens are the same as the drafter’s confidences predicted. Below the diagonal, the drafter was overconfident; above, not confident enough.

There’s lots of blue along the diagonal, and that’s free signal we could be using to improve our drafting policy.

How can we do that?

Write round ii‘s expected committed tokens at depth γ\gamma from its own per-depth confidences akia_k^i

mi(γ)=1+d=1γk=1daki.m_i(\gamma) = 1 + \sum_{d=1}^{\gamma} \prod_{k=1}^{d} a_k^i .
联系我们 contact @ memedata.com