BerryLM-OS-DFlash2

Draft model for speculative decoding with BerryLM-OS, built on DFlash 2 (block-diffusion drafting). In one forward pass the drafter proposes a block of 7 tokens, conditioned on hidden states of BerryLM-OS. BerryLM-OS then checks the whole block in one pass, keeps the accepted prefix and adds one token of its own. Every emitted token goes through BerryLM-OS's verification (rejection sampling), so the drafter changes the speed of generation, not the output distribution (up to floating-point differences of batched computation). It runs on vLLM, SGLang and llama.cpp; the GGUF file for llama.cpp is in BerryLM-OS-GGUF.

How it works

  • Input. A block of 8 positions: the last accepted token (the anchor) and 7 mask tokens (token id 180215). All 7 draft tokens are predicted at once, not one after another.
  • Target features. The residual stream after BerryLM-OS decoder layers 3, 11, 20, 28 and 37 (0-based, before the final norm), concatenated, projected to 2048 by one linear layer and normalized. The drafter attends to these features over a sliding window of 2048 context positions and to the block itself in both directions.
  • Drafter. 5 decoder layers: hidden size 2048, 16 query and 2 key-value heads of dimension 256, MLP 6144. DFlash2 additions: two-tap dynamic grouped convolutions in every layer and a candidate selector (rank 256) that rescores the top-16 tokens of each position to pick the drafted path.
  • Size. About 0.41B own parameters (bf16, 815 MB). Token embeddings and the LM head are shared with BerryLM-OS and are not stored here.

Training

Trained with the speculators library. The DFlash 2 training objective is not published; we trained with our own implementation. The training set has about 0.94M sequences (2.4B tokens) whose responses BerryLM-OS generated itself (temperature 1.0, top-p 0.95, top-k 20), 60% with thinking and 40% without; 6 epochs, block size 8.

Serving

The vLLM, SGLang and llama.cpp commands below use the BerryLM pull requests. The listed vLLM and SGLang revisions include DFlash2 support.

vLLM

Use the BerryLM branch of vLLM. The commands below check out the revision tested with this drafter. vLLM PR #57384

git clone https://github.com/vllm-project/vllm.git && cd vllm
git fetch origin pull/57384/head
git checkout -b berrylm 7060026c613db283d70efc250f05ab6bbced9317
VLLM_USE_PRECOMPILED=1 VLLM_PRECOMPILED_WHEEL_COMMIT=cb6458c5ce61632524c0447d49790725c1e1d9a2 pip install -e .
VLLM_USE_V2_MODEL_RUNNER=1 vllm serve rwb-ai/BerryLM-OS \
  --spec-model rwb-ai/BerryLM-OS-DFlash2 --spec-method dflash --spec-tokens 7 \
  --speculative-config '{"draft_sample_method": "probabilistic"}' \
  --tensor-parallel-size 1 \
  --reasoning-parser berrylm --tool-call-parser berrylm --enable-auto-tool-choice

BerryLM uses two changes in this vLLM revision for speculative decoding.

  • Hidden-state interface. It adds SupportsEagle3 / EagleModelMixin to the BerryLM model so that vLLM can return the residual streams of the layers listed in this drafter's config. Without it vLLM stops at startup with Model does not support EAGLE3 interface.
  • KDA fix. It passes dense tensors to the linear-attention recurrence that verifies draft tokens. That kernel assumes a dense memory layout; without the fix it reads the draft tokens with the wrong layout, which corrupts outputs during speculative decoding.

Notes:

  • --spec-tokens must be 7: the drafter was trained with blocks of 8 positions.
  • draft_sample_method: probabilistic samples the drafted path from the selector scores instead of taking the top candidate. With the sampling settings of BerryLM-OS it drafts more accepted tokens than the default greedy path. Remove the --speculative-config line to use greedy drafting.
  • Sampling parameters come from BerryLM-OS's generation_config.json, as without the drafter.

SGLang

This SGLang revision captures the residual streams requested by the draft model for --speculative-algorithm DFLASH. SGLang PR #55435

git clone https://github.com/sgl-project/sglang.git && cd sglang
git fetch origin pull/55435/head
git checkout -b berrylm ebedc568181c5290660b3295666382556976ff05
pip install -e "python"
python -m sglang.launch_server --model-path rwb-ai/BerryLM-OS --port 8000 \
  --speculative-algorithm DFLASH --speculative-draft-model-path rwb-ai/BerryLM-OS-DFlash2 \
  --speculative-num-draft-tokens 8 \
  --reasoning-parser berrylm --tool-call-parser berrylm

--speculative-num-draft-tokens counts the whole block of 8 positions (the anchor and 7 draft tokens).

llama.cpp

The drafter is converted to GGUF and stored next to the BerryLM-OS GGUF files: BerryLM-OS-DFlash2-BF16.gguf in BerryLM-OS-GGUF. llama.cpp supports DFlash2 drafting; BerryLM itself needs the pull request ggml-org/llama.cpp#30234. Build llama.cpp from it as described in BerryLM-OS-GGUF, then:

hf download rwb-ai/BerryLM-OS-GGUF BerryLM-OS-Q6_K.gguf BerryLM-OS-DFlash2-BF16.gguf --local-dir .
./build/bin/llama-server -m BerryLM-OS-Q6_K.gguf -md BerryLM-OS-DFlash2-BF16.gguf -ngl 99 -ngld 99 \
  -c 32768 --no-reasoning-preserve --port 8080 \
  --spec-type draft-dflash --spec-draft-n-max 7 --spec-draft-n-min 0 --spec-draft-p-min 0 \
  --spec-draft-sampling probabilistic

--spec-draft-n-max must be 7. The same drafter file works with every BerryLM-OS GGUF quantization.

Speed

Output tokens per second with the drafter divided by the same engine without it, on the same machine, one GPU per server. Protocol at the end of this section.

vLLM

Output tokens per second of BerryLM-OS alone and with the drafter (probabilistic drafting, as in the main command above), the speedup, and the mean acceptance length Ο„: per request, 1 + accepted draft tokens per BerryLM-OS verification step, averaged over requests. Mean of three repetitions, protocol below.

1 request

task BerryLM-OS alone, tok/s with the drafter, tok/s speedup Ο„
GSM8K 221 609 2.75Γ— 5.32
HumanEval 221 660 2.98Γ— 5.56
MATH-500 222 686 3.09Γ— 5.65
MBPP 228 583 2.56Γ— 4.82
MT-Bench 222 521 2.35Γ— 4.38

8 concurrent requests

task BerryLM-OS alone, tok/s with the drafter, tok/s speedup Ο„
GSM8K 955 2,682 2.81Γ— 5.33
HumanEval 949 2,780 2.93Γ— 5.59
MATH-500 967 2,995 3.10Γ— 5.66
MBPP 957 2,409 2.52Γ— 4.83
MT-Bench 940 2,204 2.34Γ— 4.41

32 concurrent requests

task BerryLM-OS alone, tok/s with the drafter, tok/s speedup Ο„
GSM8K 2,191 6,191 2.83Γ— 5.29
HumanEval 2,139 6,275 2.94Γ— 5.60
MATH-500 2,360 7,265 3.08Γ— 5.65
MBPP 2,047 5,636 2.75Γ— 4.84
MT-Bench 2,166 5,082 2.35Γ— 4.38

Greedy drafting (without --speculative-config): 2.25–2.95Γ— (Ο„ 4.24–5.46) over the same conditions. The 95% confidence interval of each speedup (Student t over the three repetitions) is within Β±17% of its value.

SGLang

Speedup of SGLang with the drafter over SGLang alone, and Ο„ at 1 request. Mean of three repetitions, same requests and sampling as for vLLM.

task 1 request 8 concurrent 32 concurrent Ο„
GSM8K 2.99Γ— 2.62Γ— 2.60Γ— 5.32
HumanEval 3.22Γ— 2.74Γ— 2.72Γ— 5.58
MATH-500 3.30Γ— 2.91Γ— 2.93Γ— 5.62
MBPP 2.76Γ— 2.43Γ— 2.25Γ— 4.83
MT-Bench 2.48Γ— 2.20Γ— 2.29Γ— 4.38

With the drafter SGLang outputs 0.86–0.95 of vLLM's tokens per second (vLLM with the drafter, measured in the same run). SGLang alone is slower than vLLM alone at 1 request (0.84–0.87 of its tokens per second), so its speedup there is higher.

llama.cpp

Speedup of llama-server with the drafter GGUF over llama-server alone with the same BerryLM-OS GGUF, 1 request at a time, probabilistic drafting. Mean of three repetitions.

task BF16 Q8_0 Q6_K Q4_K_M
GSM8K 1.96Γ— 1.94Γ— 1.77Γ— 1.86Γ—
HumanEval 2.00Γ— 2.03Γ— 1.83Γ— 1.95Γ—
MATH-500 2.14Γ— 2.12Γ— 1.91Γ— 2.05Γ—
MBPP 1.83Γ— 1.81Γ— 1.65Γ— 1.73Γ—
MT-Bench 1.71Γ— 1.67Γ— 1.51Γ— 1.61Γ—

Ο„ is 4.49–5.71 and within Β±0.1 of vLLM's on the same requests for every file: quantization of BerryLM-OS does not lower the acceptance.

Output quality, scored on the same generations: on vLLM (either drafting mode) and SGLang the share of correct answers on GSM8K, MATH-500, HumanEval and MBPP with the drafter differs from BerryLM-OS alone by 1.3 points at most, and every 95% confidence interval of the difference includes zero and stays within Β±4.0 points. On llama.cpp the check used 32 requests per task, which resolves only large changes: the differences span -7.3 to +7.3 points (mean +1.3) over the four files and both drafting modes. The cap of 4096 new tokens cuts many answers short, so these accuracies are not comparable with the evaluation of BerryLM-OS.

Protocol: one GPU per server, tensor parallel 1. vLLM and SGLang: bf16 BerryLM-OS, --max-model-len 16384 (SGLang --context-length 16384), at most 32 running requests, prefix caching off; 128 requests per task from GSM8K, HumanEval, MATH-500, MBPP and MT-Bench (first turn only), formatted as in the DFlash authors' benchmark code, in a fixed random order; HumanEval (164 items) and MT-Bench (80 items) repeat some prompts; 1, 8 and 32 concurrent requests. llama.cpp: the drafter GGUF in BF16 with each BerryLM-OS GGUF, all layers on the GPU, context 17408, the first 32 of the same requests per task, 1 request at a time, prompts sent as token ids. All engines: thinking on, up to 4096 new tokens, temperature 0.8, top-p 0.95, top-k 20, three repetitions with different sampling seeds.

Limitations

  • Trained for the bf16 weights of BerryLM-OS. llama.cpp was also measured with the Q8_0, Q6_K and Q4_K_M GGUF files; BerryLM-OS-FP8 is not tested.
  • Measured with tensor parallel 1 on one GPU model. The speedup depends on the GPU (the drafter's cost relative to BerryLM-OS's); larger tensor parallel sizes are not tested.
  • llama.cpp was measured with 1 request at a time, on CUDA; on Apple silicon (Metal) only a short check was run (see BerryLM-OS-GGUF).
  • Measured with thinking on. Direct answers (enable_thinking=False) are not measured.

License

Released under the Apache License 2.0.

Downloads last month
23
Safetensors
Model size
0.4B params
Tensor type
BF16
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support

Model tree for rwb-ai/BerryLM-OS-DFlash2

Finetuned
(1)
this model