|
Download README.md from rwb-ai/BerryLM-OS-DFlash2: direct link, hf CLI and curl.
- Browser
- Download file 11.3 kB
-
https://huggingface.co/rwb-ai/BerryLM-OS-DFlash2/resolve/main/README.md
- Command line
-
hf download hf://rwb-ai/BerryLM-OS-DFlash2/README.md
-
curl -L -o README.md https://huggingface.co/rwb-ai/BerryLM-OS-DFlash2/resolve/main/README.md
11.3 kB
| license: apache-2.0 | |
| language: [ru, en] | |
| base_model: | |
| - rwb-ai/BerryLM-OS | |
| inference: false | |
| tags: [berrylm, speculative-decoding, dflash, dflash2, block-diffusion, draft-model, vllm, sglang, llama.cpp] | |
| # BerryLM-OS-DFlash2 | |
| Draft model for speculative decoding with [BerryLM-OS](https://huggingface.co/rwb-ai/BerryLM-OS), built on | |
| [DFlash 2](https://inco.ai/blog/dflash2/) (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](https://huggingface.co/rwb-ai/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](https://github.com/vllm-project/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](https://github.com/vllm-project/vllm/pull/57384) | |
| ```bash | |
| 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](https://github.com/sgl-project/sglang/pull/55435) | |
| ```bash | |
| 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](https://huggingface.co/rwb-ai/BerryLM-OS-GGUF). llama.cpp supports DFlash2 drafting; BerryLM itself | |
| needs the pull request [ggml-org/llama.cpp#30234](https://github.com/ggml-org/llama.cpp/pull/30234). Build llama.cpp | |
| from it as described in BerryLM-OS-GGUF, then: | |
| ```bash | |
| 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](https://huggingface.co/rwb-ai/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](https://huggingface.co/rwb-ai/BerryLM-OS-GGUF)). | |
| - Measured with thinking on. Direct answers (`enable_thinking=False`) are not measured. | |
| ## License | |
| Released under the Apache License 2.0. | |