vaultpls commited on
Commit
8e9e87f
·
verified ·
1 Parent(s): 5b618e6

Card: add DSpark drafter section (restore frontmatter)

Browse files
Files changed (1) hide show
  1. README.md +121 -130
README.md CHANGED
@@ -1,155 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  # LFM3-1.7B-Looped (layers 8-11, run twice)
2
 
3
- A **training-free depth loop** for [LiquidAI/LFM3-1.7B-Base](https://huggingface.co/LiquidAI/LFM3-1.7B-Base):
4
- layers 8–11 are executed **twice**, each pass contributing **half of a residual step**.
 
5
 
6
- No gradients, no new parameters, no training data. Four layers are duplicated in the graph and the
7
- residual branch of every pass is scaled by 0.5, which makes the result an ordinary 28-layer model
8
- that runs on stock KV cache, bakes to GGUF, and serves in llama.cpp.
9
 
10
- Measured on the same items against the unmodified base:
 
 
 
 
 
 
11
 
12
- | benchmark | base | looped | Δ |
13
- |---|---|---|---|
14
- | ARC-Easy, 5-shot, n=1000 | 60.8 | **69.2** | +8.4 pp (p=2.4e-9) |
15
- | ARC-Challenge, 5-shot, n=1000 | 30.0 | **34.1** | +4.1 pp |
16
- | HellaSwag, 0-shot, n=10042 (lm-eval) | 53.6 | **54.3** | +0.7 pp (p=0.006) |
17
- | WinoGrande, 0-shot, n=1267 | 54.7 | **57.4** | +2.7 pp (p=0.014) |
18
- | ARC-Easy, 0-shot, n=2376 | 38.5 | **41.0** | +2.5 pp (p=0.0001) |
19
- | ARC-Challenge, 0-shot, n=1172 | 26.1 | **27.7** | +1.6 pp (p=0.073) |
20
- | PIQA, 0-shot, n=1838 | 60.3 | 60.6 | +0.3 pp (n.s.) |
21
- | BoolQ, 0-shot, n=3270 | 75.4 | 74.8 | −0.6 pp (n.s.) |
22
- | wikitext perplexity (HF, 1024-ctx windows) | 24.73 | **23.62** | −4.5% |
23
- | wikitext perplexity (llama.cpp Q8) | 18.29 | **17.87** | −2.3% |
24
-
25
- Cost: 1.73B → 1.97B parameters, 1.84 → 2.10 GB Q8 file, and about **11% slower decode**
26
- (llama-bench, RTX 4070, Q8_0, `-ngl 99`: pp512 18184 → 16699 t/s, tg128 160.3 → 142.6 t/s).
27
 
28
- ## Speculative decoding (DSpark)
29
 
30
- A DSpark drafter for this model ships separately:
31
- **[vaultpls/LFM3-1.7B-DSpark-loop-taps](https://huggingface.co/vaultpls/LFM3-1.7B-DSpark-loop-taps)**
32
- (344 MB GGUF, ~316M params, block size 8). It is the Apache-2.0 drafter trained against plain
33
- LFM3-1.7B with the auxiliary hidden-state taps shifted to `[3, 11, 23, 27]` — the loop renumbers
34
- every layer after the duplicated window, so the upstream taps `[3, 11, 19, 23]` would read the
35
- wrong depths.
36
 
37
- ```bash
38
- llama-server -m LFM3-1.7B-loop-8-11-Q8_0.gguf \
39
- -md LFM3-1.7B-DSpark-loop-taps-Q8_0.gguf \
40
- --spec-type draft-dspark --spec-draft-n-max 4 -c 131072 -ngl 99 -fa on -np 1
41
- ```
 
 
 
 
 
 
 
42
 
43
- Measured (RTX 4070, Q8_0, np1, greedy, 16k ctx, 160-token generations; baseline ~183 t/s):
44
- prose **+45%**, structured JSON **+112%** (+172% at n-max 6), arithmetic **+95%**; draft acceptance
45
- ~34% on prose and ~66% on JSON. Two caveats: at `--parallel 8` with a unified KV cache the drafter
46
- costs ~26% aggregate throughput, so it is single-stream only; and greedy text is not bit-identical
47
- to the no-drafter run, so keep it off for reproducible benchmark runs.
48
 
49
- ## Method
50
 
51
- Each LFM3 block is `h' = h + post_op_norm(op(pre_norm(h))) + post_ffn_norm(ffn(ffn_norm(h)))`.
52
- The loop repeats the window as a damped fixed-point iteration with K=2:
53
 
 
 
54
  ```
55
- h0 = x
56
- h1 = h0 + 0.5 * (G(h0) - h0) # G = the four-layer block
57
- h2 = h1 + 0.5 * (G(h1) - h1)
58
- x' = h2
59
- ```
60
-
61
- Because it is built as a *static* graph — the window is physically duplicated and both copies carry
62
- `post_operator_norm.weight * 0.5` and `post_ffn_norm.weight * 0.5` — generation uses a normal KV cache
63
- with no runtime wrapper, and the whole thing converts to GGUF.
64
-
65
- The scaling must go in the **post-norms**, not in `o_proj`/`w2`: those feed an RMSNorm, which divides
66
- the scale back out. Both the HF implementation and `llama.cpp`'s `lfm3.cpp` apply the post-norm to the
67
- branch output *before* the residual add, so the edit is exact in both. Verified: hook-based reference
68
- wrapper vs. static model max|Δlogit| = 0.0 at α ∈ {1.0, 0.5, 0.25}, and every scaled tensor in the
69
- shipped GGUF is exactly 0.5× the base tensor (`scripts/check_loop_gguf.py`).
70
-
71
- ## What does not work (measured, same harness)
72
-
73
- These were tried so you don't have to; numbers are ARC-Easy 5-shot / n=1000 unless noted.
74
-
75
- * More passes: K=3 69.7, K=4 69.0 — flat inside noise.
76
- * Different per-pass gains: RK2 midpoint (0.5 then 1.0) **63.6**, 0.7/0.3 66.5, 0.3/0.7 66.8.
77
- The uniform half-step is a sharp optimum; the "better" integrator is the worst option.
78
- * Multiple loop windows: adding [16-19] or [12-15] to [8-11]×2 changes nothing item-for-item
79
- (0.0 pp, discordant 39/39); looping late layers [20-23] costs **−5.9 pp**.
80
- * Logit ensemble with the unlooped base: monotonically worse (w=0.1 already −0.8 pp).
81
- * Repeating only the shortconv sublayers (cheap depth): +0.3 pp, perplexity worse. The effect lives
82
- in the attention sublayers.
83
- * Attention temperature (q×0.9 / q×1.1): 69.2 / 69.0, dead flat.
84
- * Global residual scaling ×0.8: **71.4 on ARC but wikitext PPL 23.6 → 44.5**. A multiple-choice gain
85
- without a language-model gain, i.e. a scoring artifact. Rejected.
86
- * GSM8K, n=80: 67.5 → 61.3, not significant — the one task where the loop is behind, on a small sample.
87
-
88
- ## Weights
89
-
90
- Published at **https://huggingface.co/vaultpls/LFM3-1.7B-Looped** (`gguf/` + bf16).
91
 
92
- ## Files
93
 
 
 
 
 
 
 
94
  ```
95
- gguf/LFM3-1.7B-loop-8-11-Q8_0.gguf the artefact (Q8_0, 28 layers, 2.10 GB)
96
- hf/ same weights in HF format (trust_remote_code)
97
- scripts/tfl.py build/verify/eval the loop in HF
98
- scripts/save_loop_hf.py write the looped model as an HF checkpoint
99
- scripts/loop_gguf_k.py build the looped GGUF from a base GGUF
100
- scripts/check_loop_gguf.py verify the GGUF surgery (exact 0.5× scaling)
101
- scripts/lmstat.py, ens.py paired McNemar tables, logit-ensemble sweep
102
- scripts/compose-loop.yaml llama.cpp container definition used for serving
103
- results/ raw lm-eval results and sample-level JSON
104
- ```
105
-
106
- ## Quick start
107
 
108
- llama.cpp (builds with LFM3 support, e.g. master ≥ `1014775c8`):
 
109
 
110
- ```bash
111
- llama-server -m LFM3-1.7B-loop-8-11-Q8_0.gguf --alias lfm3-loop \
112
- -ngl 99 -fa on -c 131072 --jinja
113
- ```
114
 
115
- transformers:
 
 
 
 
 
116
 
117
- ```python
118
- from transformers import AutoModelForCausalLM, AutoTokenizer
119
- tok = AutoTokenizer.from_pretrained("LFM3-1.7B-loop-8-11-HF", trust_remote_code=True)
120
- m = AutoModelForCausalLM.from_pretrained("LFM3-1.7B-loop-8-11-HF", trust_remote_code=True, dtype="bfloat16")
121
  ```
122
 
123
- `hf/` needs the custom `modeling_lfm3.py` / `configuration_lfm3.py` / `lfm3_conv.py` that ship with it.
 
 
 
 
124
 
125
  ## Limitations
126
 
127
- * This is the **base** checkpoint, not an instruction-tuned model. With the chat template it will
128
- produce a thinking trace (`reasoning_content`) and needs a token budget large enough to finish it;
129
- a small `max_tokens` returns empty content with `finish_reason=length`. Prefer `/v1/completions`
130
- for plain text.
131
- * Gains depend on the evaluation configuration: +8.4 pp on ARC-Easy with 5-shot prompting, +2.5 pp
132
- with 0-shot. Few-shot results were not run under the canonical 25-shot ARC / 10-shot HellaSwag
133
- settings.
134
- * Tested on one model (LFM3-1.7B, 24 layers, hybrid shortconv/attention) and one window. Transfer to
135
- other sizes and architectures is untested.
136
- * Loop runs late in the stack hurt; the safe zone is the middle of the depth (`8-11` of 24).
137
- * About 11% slower decode and a larger file than the base model.
138
-
139
- ## License and attribution
140
-
141
- Derived from **LiquidAI/LFM3-1.7B-Base**, © Liquid AI, Inc., under the **LFM Open License v1.0**
142
- (see `LICENSE`). This repository contains a Derivative Work under that license:
143
-
144
- * four layers are duplicated and the post-norm tensors of the original and copied layers are scaled
145
- by 0.5 (modified tensors: `*.post_attention_norm.weight`, `*.post_ffw_norm.weight` for layers
146
- 8–11 and their copies at 12–15);
147
- * tensor names and layer indices are renumbered accordingly;
148
- * no other weights were changed, and no training was performed.
149
-
150
- Commercial use is subject to the limitations in Section 5 of the license. This project is not
151
- affiliated with, endorsed by, or supported by Liquid AI. "LFM" is used only to describe the origin
152
- of the weights.
153
-
154
- Method inspired by *training-free depth looping* (arXiv 2605.23872), which explores running a
155
- pretrained block more than once with damped sub-steps.
 
1
+ ---
2
+ library_name: transformers
3
+ license: other
4
+ license_name: lfm1.0
5
+ license_link: https://huggingface.co/LiquidAI/LFM3-1.7B-Base/blob/main/LICENSE
6
+ pipeline_tag: text-generation
7
+ base_model: LiquidAI/LFM3-1.7B-Base
8
+ tags:
9
+ - liquid
10
+ - lfm3
11
+ - depth-loop
12
+ - training-free
13
+ - gguf
14
+ - custom_code
15
+ language:
16
+ - en
17
+ - ar
18
+ - zh
19
+ - fr
20
+ - de
21
+ - it
22
+ - ja
23
+ - ko
24
+ - pt
25
+ - es
26
+ - vi
27
+ - th
28
+ - id
29
+ - hi
30
+ - ru
31
+ - pl
32
+ ---
33
+
34
  # LFM3-1.7B-Looped (layers 8-11, run twice)
35
 
36
+ LFM3-1.7B-Base with **layers 8–11 executed twice**, each pass contributing **half a residual step**.
37
+ Training-free: no gradients, no new parameters, no data. The result is a plain 28-layer model, so it
38
+ generates with a stock KV cache and runs in llama.cpp.
39
 
40
+ ## Model details
 
 
41
 
42
+ * Base: [LiquidAI/LFM3-1.7B-Base](https://huggingface.co/LiquidAI/LFM3-1.7B-Base) — 24 layers, hybrid
43
+ shortconv/attention, 2048 hidden, 7680 FFN, sliding-window attention every 4th layer.
44
+ * Modification: layers 8–11 duplicated once (new layers 12–15), and
45
+ `post_attention_norm.weight` / `post_ffw_norm.weight` multiplied by 0.5 on both the originals and
46
+ the copies. All later layers renumbered. `block_count` 24 → 28.
47
+ * Parameters: 1.73B → 1.97B. Q8_0 file 1.84 → 2.10 GB.
48
+ * Nothing else is changed: no fine-tuning, no merging, no calibration data.
49
 
50
+ The loop is the damped fixed point `h ← h + 0.5 · (G(h) − h)` applied twice, where `G` is the
51
+ four-layer block. Damping lives in the post-norms because those are applied to the branch output
52
+ before the residual add, in both the HF code and llama.cpp's `lfm3.cpp`; scaling `o_proj`/`w2`
53
+ instead would be divided out by the following RMSNorm. Verified exact: max|Δlogit| = 0.0 against a
54
+ runtime reference wrapper, 0.5× on every scaled tensor in the GGUF.
 
 
 
 
 
 
 
 
 
 
55
 
56
+ ## Evaluation
57
 
58
+ Same items, both models, paired. Full details and the negative results are in the repository README.
 
 
 
 
 
59
 
60
+ | benchmark | base | this model | Δ |
61
+ |---|---|---|---|
62
+ | ARC-Easy 5-shot (n=1000) | 60.8 | 69.2 | +8.4 pp, p=2.4e-9 |
63
+ | ARC-Challenge 5-shot (n=1000) | 30.0 | 34.1 | +4.1 pp |
64
+ | HellaSwag 0-shot (n=10042) | 53.6 | 54.3 | +0.7 pp, p=0.006 |
65
+ | WinoGrande 0-shot (n=1267) | 54.7 | 57.4 | +2.7 pp, p=0.014 |
66
+ | ARC-Easy 0-shot (n=2376) | 38.5 | 41.0 | +2.5 pp, p=0.0001 |
67
+ | ARC-Challenge 0-shot (n=1172) | 26.1 | 27.7 | +1.6 pp, p=0.073 |
68
+ | PIQA 0-shot (n=1838) | 60.3 | 60.6 | +0.3 pp (n.s.) |
69
+ | BoolQ 0-shot (n=3270) | 75.4 | 74.8 | −0.6 pp (n.s.) |
70
+ | wikitext PPL (HF) | 24.73 | 23.62 | −4.5% |
71
+ | wikitext PPL (llama.cpp Q8) | 18.29 | 17.87 | −2.3% |
72
 
73
+ Throughput on an RTX 4070, Q8_0, `-ngl 99`, isolated llama-bench: pp512 18184 → 16699 t/s,
74
+ tg128 160.31 → 142.55 t/s.
 
 
 
75
 
76
+ ## Use
77
 
78
+ llama.cpp (needs the LFM3 architecture, master ≥ `1014775c8`):
 
79
 
80
+ ```bash
81
+ llama-server -m LFM3-1.7B-loop-8-11-Q8_0.gguf --alias lfm3-loop -ngl 99 -fa on -c 131072 --jinja
82
  ```
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
83
 
84
+ transformers:
85
 
86
+ ```python
87
+ from transformers import AutoModelForCausalLM, AutoTokenizer
88
+ tok = AutoTokenizer.from_pretrained("vaultpls/LFM3-1.7B-Looped", trust_remote_code=True)
89
+ m = AutoModelForCausalLM.from_pretrained("vaultpls/LFM3-1.7B-Looped", trust_remote_code=True, dtype="bfloat16")
90
+ ids = tok("The capital of France is", return_tensors="pt").input_ids
91
+ print(tok.decode(m.generate(ids, max_new_tokens=32, do_sample=False)[0]))
92
  ```
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
+ The `hf/` folder carries the custom `modeling_lfm3.py`, `configuration_lfm3.py` and `lfm3_conv.py`
95
+ needed by `trust_remote_code`.
96
 
97
+ ## Speculative decoding (DSpark)
 
 
 
98
 
99
+ A DSpark drafter for this model ships separately:
100
+ **[vaultpls/LFM3-1.7B-DSpark-loop-taps](https://huggingface.co/vaultpls/LFM3-1.7B-DSpark-loop-taps)**
101
+ (344 MB GGUF, ~316M params, block size 8). It is the Apache-2.0 drafter trained against plain
102
+ LFM3-1.7B with its auxiliary hidden-state taps moved to `[3, 11, 23, 27]`: the loop inserts four
103
+ layers after layer 11 and renumbers the rest, so the upstream taps `[3, 11, 19, 23]` would read the
104
+ wrong depths.
105
 
106
+ ```bash
107
+ llama-server -m LFM3-1.7B-loop-8-11-Q8_0.gguf \
108
+ -md LFM3-1.7B-DSpark-loop-taps-Q8_0.gguf \
109
+ --spec-type draft-dspark --spec-draft-n-max 4 -c 131072 -ngl 99 -fa on -np 1
110
  ```
111
 
112
+ Measured on the RTX 4070, Q8_0, single stream, greedy, 16k ctx, 160-token generations (baseline
113
+ ~183 t/s): prose **+45%**, structured JSON **+112%** (+172% at n-max 6), arithmetic **+95%**; draft
114
+ acceptance ~34% on prose and ~66% on JSON. Two caveats: at `--parallel 8` with a unified KV cache
115
+ the drafter costs ~26% aggregate throughput, so use it single-stream only; and greedy text is not
116
+ bit-identical to the no-drafter run, so keep it off for reproducible benchmarking.
117
 
118
  ## Limitations
119
 
120
+ * **Base checkpoint**, not instruction-tuned. With the chat template it emits a thinking trace
121
+ (`reasoning_content`) and returns empty `content` if `max_tokens` is too small. Use
122
+ `/v1/completions` for plain text, or set `chat_template_kwargs: {"enable_thinking": false}`.
123
+ * Gains are configuration-dependent: +8.4 pp on ARC-Easy at 5-shot vs +2.5 pp at 0-shot. The
124
+ canonical 25-shot ARC / 10-shot HellaSwag settings were not run.
125
+ * One model, one window, one architecture family. Late-layer loops degrade the model; don't move the
126
+ window into the last quarter without re-measuring.
127
+ * ~11% slower decode, ~14% larger file.
128
+ * No safety tuning was applied beyond whatever the base model carries.
129
+
130
+ ## License
131
+
132
+ LFM Open License v1.0, inherited from the base model — commercial use limited by the revenue
133
+ threshold in Section 5. See `LICENSE`. Modified files are listed in `NOTICE`. Not affiliated with or
134
+ endorsed by Liquid AI; "LFM" is used only to describe the origin of the weights.
135
+
136
+ ## Citation
137
+
138
+ ```bibtex
139
+ @misc{lfm3_loop_8_11,
140
+ title = {LFM3-1.7B-loop-8-11: a training-free depth loop},
141
+ year = {2026},
142
+ note = {Derived from LiquidAI/LFM3-1.7B-Base by executing layers 8--11 twice at half step},
143
+ }
144
+ ```
145
+
146
+ Method inspired by arXiv 2605.23872 (training-free looping / damped sub-steps).