SleepyInkling-Qwen3-4B (bmswheart/SleepyInkling-Qwen3-4B)
By Brian Wasielewski (brianmswheart) and Jeff Bander, MD (jeffbander)
SleepyInkling-Qwen3-4B is a Frozen-Wake Value-Only Sleep KV Consolidation + Bounded MessageGate Recurrence retrofit of Qwen/Qwen3-4B, combining the Wake–Sleep KV-Cache Refinement method of Sangyun Lee et al. ("Sample-Efficient In-Context Adaptation via Sleep", arXiv:2611.32802) with a Layer-0 rank-64 tanh forget/gain recurrence bridge inspired by Thinking Machines Lab's thinkingmachines/Inkling-2-Mini (Inkling2LoopMessageGate, Apache-2.0).
Unlike full-backbone fine-tunes, SleepyInkling-Qwen3-4B keeps all 4.02B base Qwen/Qwen3-4B weights frozen and untouched during Wake (N=1) and ships with Value-Only Sleep (sleep_v_only: true) enabled by default—keeping all attention Keys (K) 100% bit-exact Frozen-Wake while consolidating Values (V) in place during periodic Sleep passes (l = 2..N). On NVIDIA CUDA GB10 (BF16, n = 344 greedy items against untouched stock Qwen/Qwen3-4B), default N=2 Value-Only Sleep delivers 261/344 (75.9%) vs stock Base 241/344 (70.1%) (+5.81 pp, 33W / 298T / 13L, exact two-sided McNemar p = 0.0045, 95% bootstrap CI [+2.03, +9.59] pp), led by Multi-Window Cross-Document Synthesis QA (56/72 = 77.8% vs 42/72 = 58.3%, +19.44 pp, p = 0.0066) with zero regression on GSM8K 8-Shot (100/120 = 83.3% vs 99/120 = 82.5%) and 24/24 (100.0%) ~21K RULER long-context needle retrieval, while independently replicating on Apple Silicon M3 Ultra MLX (101/136 = 74.3%, +8.09 pp vs Wake, p = 0.0266; 12/12 ~21K RULER).
It is also distributed as a compact 163.46 MiB plug-in Sleep adapter (bmswheart/SleepyInkling-Qwen3-4B-adapter, 651 FP16 tensors, 85.66M params = 2.13% of base) that activates exclusively during periodic Sleep consolidation passes while leaving the KV cache sequence length unchanged.
Credit & Contributions
- From Lee et al. (arXiv:2611.32802): Sangyun Lee, Enyan Zhang, Michael Xu, Hao Tang, Zinan Lin, Weijia Xu, Chris Quirk, Jianfeng Gao, Giulia Fanti, and Xiaodong Liu invented and formulated Wake–Sleep KV refinement, periodic window-bidirectional consolidation passes, and GRU-style KV write gates.
- Inspired by Thinking Machines Lab (
thinkingmachines/Inkling-2-Mini, Apache-2.0): Rank-64tanhforget/gain message gating (Inkling2LoopMessageGate) and loop-contrastive hidden decoding (LoopCD), adapted here into Layer 0'sMessageGateSleepBridgeand--loopcd-omega.- Base Model: Qwen/Qwen3-4B by the Qwen Team (Alibaba Cloud, Apache-2.0, arXiv:2505.09388).
- Added in this release: Frozen-Wake isolation (all base weights untouched at
N=1), Value-Only Sleep (sleep_v_only: truedefault), Sleep-only LoRA (r=32), Layer-0MessageGateSleepBridge(rank=64), Wake-KL consolidation anchor (λ = 0.50), plug-in adapter extraction/application, and multi-runtime inference wrappers across PyTorch/CUDA, Apple Silicon MLX, native Apple Silicon Metal (ASOR), and OpenAI-compatible serving.- Release Contributors: Brian Wasielewski (
brianmswheart) and Jeff Bander, MD (jeffbander) (personal release).- Apache-2.0 §4(b) Notice: Adds Frozen-Wake Value-Only Sleep KV write gates, Sleep-only LoRA, Layer-0
MessageGateSleepBridge, and multi-runtime inference wrappers; baseQwen/Qwen3-4Bweights unmodified.
Architecture & Plug-In Adapter Summary
Building on Lee et al. (arXiv:2611.32802) with Frozen-Wake isolation, Value-Only KV consolidation, and bounded recurrence gating:
- Frozen Wake (
l = 1): Runs unmodifiedQwen/Qwen3-4Bweights in Wake-only mode (overall|Δ NLL| ≤ 0.00111nats across all 4 NLL suites, and336/344 = 97.7%exact item agreement with untouched stockQwen/Qwen3-4Bacross then = 344greedy generation/RULER benchmark,p = 0.727; rare tie-breaks stem from windowed explicit-mask SDPA vs stock causal kernel). Standardmodel()andmodel.generate()executeN=1Wake-only; callforward_sleep()orgenerate_sleep()forN ≥ 2Sleep. - Value-Only Sleep (
sleep_v_only: truedefault): During Sleep passes (l = 2..N), attention Keys (K) remain 100% bit-exact Frozen-Wake—preserving exact RoPE positional addressing up to long context and eliminating early-needle routing drift—while Sleep consolidates Values (V) in place via the per-KV-head GRU write gates (sleep_gate_v). Allsleep_gate_kweights remain included in thev3d651-tensor adapter for full backwards compatibility (v_only=Falseopt-in). - Periodic Bidirectional Sleep (
l = 2..N, windowW = 256): At every256-token window boundary (or opportunistically viasleep_now()in MLX), the engine runsN − 1full-stack passes over the uncommitted window with bidirectional intra-window attention and causal visibility over all prior consolidated windows. - Layer-0
MessageGateSleepBridge(rank = 64): Bounded RMSNorm +tanhgated recurrence bridge anchoring Sleep passes onto Layer 0's token-embedding manifold using the post-final-norm hidden stateh_prev:z = W_down @ [RMSNorm(h_embed), RMSNorm(h_prev)],forget = tanh(W_forget @ z),gain = tanh(W_gain @ z),h_in = (1 - forget) * h_embed + gain * h_prev, where(1 - forget) ∈ (0, 2)andgain ∈ (-1, 1). Zero-init ofW_forgetandW_gainguarantees exact identity (h_in == h_embed) at initialization; trainedv3dweights are verified non-zero (downabs-mean0.00709,forget0.00110,gain0.00110). - Sleep-Only LoRA (
r = 32, α = 64):504FP16 tensors across all36layers (q/k/v/o+gate/up/downMLP) that fire strictly inside Sleep passes (l ≥ 2) and are completely bypassed during Wake (l = 1). - In-Place Per-KV-Head GRU KV Write Gates (constant KV sequence length):
144FP16 tensors (sleep_gate_{k,v}.{weight,bias},init_bias = 3.0) blending refined values (V_newby default undersleep_v_only: true, or(K_new, V_new)whenv_only=False) into the active window's existing KV slots in FP32 before casting back to the cache dtype. - Training Recipe & Data Mix (
v3d): Frozen-Wake retrofit onQwen/Qwen3-4Bwith randomized loop curriculumN ∈ {2, 2, 3, 4}, Wake-KL anchorλ = 0.50(constrains post-Sleep Wake logit distributions from drifting too far from frozen Wake logits while consolidating KV states),120optimizer steps (32,768tok/step,seq_len = 2048) on NVIDIA GB10 (BF16). Training data combined synthetic/curated coding, tool-use, technical prose, and a15%math CoT mix; the in-domain holdout split is drawn from the same curated pipeline (no overlap with OOD WikiText-103 test or Python 3.12 stdlib).
Plug-In Adapter Artifact (bmswheart/SleepyInkling-Qwen3-4B-adapter)
| Field | Verified Value |
|---|---|
| Adapter File | sleep_adapter.safetensors |
| Exact Size | 163.46 MiB (171,403,008 bytes) |
| Tensor Count / Dtype | 651 FP16 tensors (85,663,744 params = 2.13% of Qwen3-4B) |
| Tensor Breakdown | 144 KV write gates (sleep_gate_v active by default; sleep_gate_k included for v_only=False) + 504 Sleep-Only LoRA + 3 MessageGateSleepBridge (down, forget, gain) |
| Default Sleep Mode | sleep_v_only: true (num_loops = 2, window_size = 256; Keys 100% Frozen-Wake) |
| Base Overlap | 0 overlapping keys with the 398 base Qwen/Qwen3-4B tensors (1,049 total unique tensors with tied embeddings) |
| SHA-256 | 22bb77fd9a8a9eb0743bf9096a7c3d311bd0c7d35e684fca43520cfdefaea5b6 |
Verified Benchmarks (SleepyInkling-Qwen3-4B)
1. NVIDIA CUDA GB10 BF16 — Multi-Window NLL (2,048-Token Contexts = 8 × W=256, Default sleep_v_only: true & K+V Comparison)
All 4 evaluation suites improve on 7/7 post-Sleep windows under both default sleep_v_only: true (k_update_scale = 0.0, v_update_scale = 1.0) and legacy K+V (v_only=False), while N=1 stays within |Δ NLL| ≤ 0.00111 nats (-0.00111 to +0.00039) of stock Qwen/Qwen3-4B. Default Value-Only Sleep matches or surpasses K+V on OOD Python (N=4: -0.1883 vs -0.1776) and OOD ICL (N=2: -0.0127 vs -0.0118; N=4: -0.0123 vs -0.0086) while keeping Keys 100% bit-exact Frozen-Wake. On CUDA GB10 (PyTorch 2.11.0+cu130, transformers 5.14.1), N=2 takes ~1.86×–1.93× wall-time vs N=1 (~3.1× vs stock causal SDPA) and N=4 takes ~3.63×–3.77× vs N=1 (~6.0× vs stock causal SDPA).
Evaluation Suite (n_chunks × 2048) | Base Qwen3-4B (overall) | N=1 (Wake-Only) | N=1 − Base | N=2 V-Only Default (d2) | N=4 V-Only Default (d4) | Legacy K+V (d2 / d4) | Post-Sleep Windows Won (N=2) |
|---|---|---|---|---|---|---|---|
In-Domain Holdout* (24 × 2048) | 1.5771 | 1.5760 | -0.00111 | -0.4218 (1.5310 → 1.1092) | -0.4817 (1.5310 → 1.0493) | -0.4392 / -0.4856 | 7/7 |
OOD WikiText-103 Test (24 × 2048) | 2.5673 | 2.5673 | +0.00001 | -0.2674 (2.5111 → 2.2437) | -0.2822 (2.5111 → 2.2289) | -0.2708 / -0.2830 | 7/7 |
OOD Python 3.12 Stdlib (24 × 2048) | 1.4065 | 1.4066 | +0.00007 | -0.1717 (1.3187 → 1.1470) | -0.1883 (1.3187 → 1.1304) | -0.1718 / -0.1776 | 7/7 |
OOD ICL Novel Schema (16 × 2048) | 0.6209 | 0.6213 | +0.00039 | -0.0127 (0.4446 → 0.4319) | -0.0123 (0.4446 → 0.4323) | -0.0118 / -0.0086 | 7/7 |
*Caveats: In-Domain Holdout shares the training distribution's formatting/domain mix, so its larger NLL drop (-0.4218 vs WikiText -0.2674) reflects in-domain adaptation rather than pure OOD gain. OOD WikiText-103 and Python 3.12 stdlib have zero overlap with training. Window win counts (7/7) are averaged across chunks at each window position (n = 24 / 24 / 24 / 16 chunks).
2. NVIDIA CUDA GB10 BF16 — Large-n Downstream & Long-Context Head-to-Head vs Untouched Qwen/Qwen3-4B (n = 344)
Measured head-to-head on NVIDIA GB10 (BF16, temperature = 0, identical prompts across all 3 arms) comparing untouched upstream Qwen/Qwen3-4B Base, SleepyInkling-Qwen3-4B N=1 (Wake-Only), and SleepyInkling-Qwen3-4B N=2 Value-Only (sleep_v_only: true, default):
Benchmark Suite (temperature = 0) | Context / Format | Stock Base Qwen/Qwen3-4B | N=1 (Wake-Only) | N=2 Value-Only (Default) | N=2 vs Stock Base (W/T/L, McNemar p, 95% CI) | N=2 vs N=1 (W/T/L, McNemar p) |
|---|---|---|---|---|---|---|
Multi-Window Cross-Doc Synthesis QA (n=72)* | avg 1,541 tok | 42/72 (58.3%) | 43/72 (59.7%) | 56/72 (77.8%) | +19.44 pp (19W/48T/5L, p = 0.0066, [+6.94, +31.94]) | +18.06 pp (18W/49T/5L, p = 0.0106) |
ICL Novel Schema 16-Shot (n=64) | avg 847 tok | 36/64 (56.2%) | 35/64 (54.7%) | 42/64 (65.6%) | +9.38 pp (7W/56T/1L, p = 0.0703, [+1.56, +17.19]) | +10.94 pp (8W/55T/1L, p = 0.0391) |
ICL Novel Schema 8-Shot (n=64) | avg 474 tok | 40/64 (62.5%) | 38/64 (59.4%) | 39/64 (60.9%) | -1.56 pp (2W/59T/3L, p = 1.000, [-7.81, +4.69]) | +1.56 pp (3W/59T/2L, p = 1.000) |
ICL Novel Schema Pooled (8+16-Shot) (n=128) | 474–847 tok | 76/128 (59.4%) | 73/128 (57.0%) | 81/128 (63.3%) | +3.91 pp (9W/115T/4L, p = 0.2668, [-0.78, +9.38]) | +6.25 pp (11W/114T/3L, p = 0.0574) |
GSM8K 8-Shot (n=120) | avg 1,366 tok | 99/120 (82.5%) | 99/120 (82.5%) | 100/120 (83.3%) | +0.83 pp (5W/111T/4L, p = 1.000, [-3.33, +5.83]) | +0.83 pp (6W/109T/5L, p = 1.000) |
~21K RULER NIAH (n=24, 8E/8M/8L)† | avg 21,328 tok (3,000 MiB KV) | 24/24 (100.0%) | 24/24 (100.0%) | 24/24 (100.0%) | 0.00 pp (0W/24T/0L, p = 1.000, E=8/8 M=8/8 L=8/8) | 0.00 pp (0W/24T/0L, p = 1.000) |
POOLED GENERATION (n=320) | MW-QA + ICL + GSM8K | 217/320 (67.8%) | 215/320 (67.2%) | 237/320 (74.1%) | +6.25 pp (33W/274T/13L, p = 0.0045, [+2.19, +10.62]) | +6.88 pp (35W/272T/13L, p = 0.0021) |
POOLED ALL 4 SUITES (n=344) | Gen + ~21K RULER | 241/344 (70.1%) | 239/344 (69.5%) | 261/344 (75.9%) | +5.81 pp (33W/298T/13L, p = 0.0045, [+2.03, +9.59]) | +6.40 pp (35W/296T/13L, p = 0.0021, [+2.33, +10.17]) |
- Frozen-Wake Equivalence (
N=1vs Untouched StockQwen/Qwen3-4B,n=344):239/344(69.5%) vs241/344(70.1%),336/344(97.7%) exact item agreement (3W / 5L, exact two-sided McNemarp = 0.727, 95% CI[-2.33, +1.16] pp). - *MW-QA
n=72Sub-Family Breakdown (24each):config_overridejumped1/24 (4.2%) → 18/24 (75.0%)(both Base &N=1were1/24),multihop_chainmoved17/24 → 18/24(N=1was18/24), whilepython_tracetraded off24/24 → 20/24(including2responses missing the####answer delimiter)—yielding the net+19.44 pp(p = 0.0066) gain across the full 72-item suite. - †KV size is analytic MiB (
tokens × 36 layers × 2 × 8 KV heads × 128 head_dim × 2 B / 2²⁰). Sleep leaves KV sequence length unchanged by construction; on CUDA GB10 withlogits_to_keep=1,~21KRULER held a flat13.66 GiBpeak VRAM (12.06 GiBfor stock Base). Note that the PyTorch reference implementation (modeling_qwen3_sleep.py) usestorch.catto update per-window KV slices, creating transient copies during decode/Sleep (whereas ASOR Metal uses preallocated in-place buffers).
Legacy K+V Opt-In Ablation (v_only=False on CUDA GB10 — Why sleep_v_only: true Is Default)
Prior to enabling sleep_v_only: true by default, legacy K+V (v_only=False) was evaluated across context lengths and N=4 on CUDA GB10 (n=12 needles per RULER/KV length, n=48 GSM8K 4+8-shot):
Legacy K+V Ablation (v_only=False) | N=1 Wake | N=2 K+V | N=4 K+V | Takeaway |
|---|---|---|---|---|
RULER ~5K / ~11K (n=12 each, 5.3K / 10.6K tok) | 12/12 / 12/12 | 12/12 / 12/12 | 12/12 / 12/12 | Ceiling across all N up to ~11K |
RULER ~21K (n=12, 21,057 tok) | 12/12 (100%) | 11/12 (91.7%, E=3/4) | 9/12 (75.0%) | K-gate early-needle drift; eliminated (24/24 = 100%) by default sleep_v_only: true |
KV Retrieval ~5.7K (n=12, 5,669 tok) | 11/12 (91.7%) | 11/12 (91.7%) | 11/12 (91.7%) | Identical to Stock Base (11/12) across all N |
GSM8K Pooled 4+8-Shot (n=48) | 38/48 (79.2%) | 37/48 (77.1%) | 32/48 (66.7%) | N=4 K+V regresses on multi-step math; use default N=2 V-Only (100/120 = 83.3%) |
3. Value-Only Sleep Breakthrough — Apple Silicon M3 Ultra MLX BF16 (Zero Retraining)
Measured on Apple M3 Ultra (256 GiB, MLX bf16 base + fp16 plug-in adapter, 0.25 s warm load, 1,049 / 1,049 strict tensor load, 61.8 tok/s Wake decode). Freezing K to 100% bit-exact Wake (k_update_scale = 0.0, v_update_scale = 1.0, shipped as sleep_v_only: true default) requires zero retraining of the v3d checkpoint yet simultaneously beats K+V N2_stock on 2K OOD NLL, restores 12/12 (100%) ~21K RULER recall, and turns the pooled n=136 downstream suite into a statistically significant win (p = 0.0266):
A. OOD NLL, ~21K RULER Long-Context Retrieval, & Downstream Generation Suite (temperature = 0)
| Benchmark / Metric | N=1 (Wake-Only) | N=2 K+V (N2_stock) | N=2 Value-Only (sleep_v_only: true, Default) | Notes / N=4 Scaling |
|---|---|---|---|---|
2K OOD NLL (8 × 2048 WikiText + Python, W1..W7) | 2.03486 | 1.82269 (-0.21218) | 1.82254 (-0.21233, 100.1% retained) | N4_Vonly 1.80519 (108.2%) beats N4_stock 1.80740 |
~21K RULER (12 needles, avg 21,057 tok) | 12/12 (100.0%) | 11/12 (91.7%, E=3/4) | 12/12 (100.0%, E=4/4 M=4/4 L=4/4) | N4_stock 8/12 (66.7%) → N4_Vonly 10/12 (83.3%) (11/12 w/ start_layer=8, γ=0.5) |
GSM8K 8-Shot (n=48, greedy) | 39/48 (81.2%) | 39/48 (81.2%) | 40/48 (83.3%, +2.1 pp) | 2W / 45T / 1L vs Wake (p = 1.0) |
Multi-Window Cross-Document Synthesis QA (n=24, untruncated) | 14/24 (58.3%) | 17/24 (70.8%) | 19/24 (79.2%, +20.8 pp) | config_override sub-family: 1/8 → 7/8; 0 truncated responses |
ICL Novel Schema (n=64, 8-shot + 16-shot) | 37/64 (57.8%) | 38/64 (59.4%) | 42/64 (65.6%, +7.8 pp) | 8s 23/32, 16s 19/32; reaches 44/64 (68.8%) w/ --loopcd-omega 0.25 |
Pooled Downstream Suite (n=136) | 90/136 (66.2%) | 94/136 (69.1%, p=0.50) | 101/136 (74.3%, +8.09 pp, p = 0.0266) | 16W / 115T / 5L vs Wake; exact two-sided McNemar p = 0.0266, 95% bootstrap CI [+1.47, +14.71] pp |
B. MLX LoopCD-Hidden NLL & Throughput Trade-Off (n=8 × 2,048 Unseen Code + Prose)
LoopCD-Hidden (ω): Optional dual-stream hidden-state contrastive decoding (h_cd = h_sleep + ω · (h_sleep − h_wake) = (1 + ω) · h_sleep − ω · h_wake, with RMS norm preserved to rms(h_sleep)) combining paired causal N=1 Wake (h_wake) and causal post-Sleep N=2 (h_sleep) hidden streams via --loopcd-omega in mlx_sleep_runner.py (ω = 0.0 reduces to exact N=2). Because it runs a paired Wake stream alongside N=2 Sleep (3 full stack passes total vs 4 for N=4), throughput is ~587 tok/s vs N=4's 425.7 tok/s.
| Mode | Post-Sleep NLL (tok ≥ 256, n=8) | Δ vs N=1 | Post-Sleep PPL | Post-Sleep Top-1 | Prefill Throughput |
|---|---|---|---|---|---|
N=1 (Wake-Only) | 1.5333 | 0.0000 | 4.634 | 68.73% | 1,729.6 tok/s |
N=2 (ω = 0.0, 1 Sleep pass) | 1.3668 | -0.1665 | 3.923 | 69.19% | 888.8 tok/s |
N=4 (3 Sleep passes) | 1.3579 | -0.1755 | 3.888 | 68.92% | 425.7 tok/s |
N=2 + LoopCD-Hidden (ω = 0.15) | 1.3585 | -0.1749 | 3.890 | 69.22% | ~587 tok/s (3 stack passes) |
N=2 + LoopCD-Hidden (ω = 0.35) | 1.3525 | -0.1808 | 3.867 | 69.18% | ~587 tok/s (3 stack passes) |
Honest
LoopCD-HiddenTrade-Off: Keep--loopcd-omega 0.0(off) for general generation.LoopCD-Hiddenis opt-in for offline NLL scoring (PPL 3.867atω = 0.35) and short-answer ICL (N2_Vonly + ω = 0.25reaches44/64 = 68.8%), but is NOT recommended for long chain-of-thought math: onGSM8K 8-shot (n=48),LoopCD-Hiddenregressed relative toN2_stock(39/48 = 81.2%) at bothω = 0.25(36/48 = 75.0%) andω = 0.35(31/48 = 64.6%,2W/10L, exact McNemarp = 0.0386).
4. Native ASOR Metal (C++20 / Metal, --precision native, 4.7 GB) — N=1/2/4 K+V & Value-Only Verification
Verified using the separate native Apple Silicon Metal engine (MSWlabAI/asor) with fused MessageGateSleepBridge and single-slice V-Only KV gate Metal kernels (Window-0 max diff N=2/4 vs N=1 = 0.000e+00, +0.0 MB KV cache growth in preallocated Metal buffers):
Corpus / Mode (--precision native) | Post-Sleep NLL | Δ vs N=1 | Full / Post PPL | Top-1 / Windows Won | Notes |
|---|---|---|---|---|---|
2K Multi-Window Corpus — N=1 Wake | 1.17875 | 0.00000 | 3.250 (post) | — | 579 tok/s prefill / 50.9 tok/s decode; Window-0 max logit diff 0.000000e+00 |
2K Multi-Window Corpus — N=2 K+V (v_only: false) | 1.05555 | -0.12320 | 2.874 (-11.59%) | 7/7 windows | Paired bootstrap 95% CI [-0.150, -0.097] |
2K Multi-Window Corpus — N=4 K+V (v_only: false) | 1.06510 | -0.11365 | 2.901 (post) | 7/7 windows | Slightly trails N=2 on this 2K corpus |
2K Unseen Prose+Code (Pure Metal) — N=1 Wake | 1.2816 | 0.0000 | 4.916 (full) | 69.61% Top-1 | Window-0 diff vs Wake: 0.000e+00 (660.3 tok/s) |
2K Unseen Prose+Code (Pure Metal) — N=2 K+V (v_only: false) | 1.1688 | -0.1128 | 4.454 (full) | 69.57% Top-1 | Window-0 diff vs Wake: 0.000e+00 (390.5 tok/s) |
2K Unseen Prose+Code (Pure Metal) — N=2 V-Only (v_only: true, Default) | 1.1730 | -0.1086 | 4.470 (full) | 69.71% Top-1 (best) | 0.000e+00 Window-0 diff; retains 96.3% of K+V ΔNLL w/ bit-exact Wake Keys |
2K Unseen Prose+Code (Pure Metal) — N=4 K+V (v_only: false) | 1.1801 | -0.1015 | 4.498 (full) | 69.52% Top-1 | Window-0 diff vs Wake: 0.000e+00 (216.9 tok/s) |
2K Unseen Prose+Code (Pure Metal) — N=4 V-Only (v_only: true) | 1.1784 | -0.1033 | 4.491 (full) | 69.37% Top-1 | N4_Vonly beats N4_stock (-0.1033 vs -0.1015 ΔNLL, 218.9 vs 216.9 tok/s) |
Recommended Operating Points:
- Default Chat, Coding, Reasoning & Long-Context Adaptation (verified up to
~21Kcontext): UseN=2withsleep_v_only: true(now the default inconfig.jsonandsleep_adapter_config.json) — wins7/7post-Sleep windows on all 4 CUDA NLL suites, achieves24/24(100.0%)~21KRULER retrieval, beats untouched stockQwen/Qwen3-4Bon261/344(75.9%vs70.1%,+5.81 pp, exact McNemarp = 0.0045) on CUDA GB10 (and101/136 = 74.3%,+8.09 pp,p = 0.0266on Apple Silicon MLX), and runs at~889 tok/sprefill (61.8 tok/sWake decode) on Apple Silicon MLX or native Metal via ASOR (v_only: true,69.71%Top-1).- Exact Stock Wake Parity or
>21KUntested Context Lengths: UseN=1(num_loops=1, Wake-only;336/344 = 97.7%exact agreement with untouched stockQwen/Qwen3-4B,p = 0.727) for exact base behavior or contexts beyond the~21Kverified RULER horizon.- Offline Log-Likelihood / Short-Answer ICL: Optionally pass
--loopcd-omega 0.15–0.35(3stack passes in MLX) for offline NLL scoring (PPL 3.867) or short-answer ICL (68.8%withN2_Vonly + ω=0.25). Do NOT enableLoopCD-Hiddenfor long-CoT math (GSM8Kregressed atω=0.25/0.35,p=0.0386), and avoidN=4for multi-step math or long-context retrieval.- Backwards-Compatible K+V Mode (Opt-In): Pass
v_only=False(PyTorch/MLX) orv_only: false(ASOR) to re-enablesleep_gate_kkey updates when comparing against the legacy K+V baseline tables above.
Known Limitations
- Standard
model()/model.generate()runN=1Wake-only: Calling HFmodel(...)ormodel.generate(...)bypasses Sleep LoRA and KV write gates. Usemodel.forward_sleep(..., num_loops=2)ormodel.generate_sleep(..., num_loops=2)for Sleep consolidation (which honorssleep_v_only: trueautomatically fromconfig.json). - Context lengths beyond
~21Kand K+V opt-in (v_only=False): Thev3dadapter was trained atseq_len = 2048. Defaultsleep_v_only: truekeeps post-RoPE keys bit-exact Frozen-Wake and holds24/24(100%) RULER retrieval at~21K(N=2, CUDA GB10) and12/12(100%, MLX), though lengths>21Khave not been evaluated (useN=1when exact verbatim recall is required beyond21K). Opting into legacy K+V gating (v_only=False) modifies post-RoPE keys and degrades early-needle recall at~21K(11/12atN=2,8–9/12atN=4). - Sub-task variance inside Multi-Window Synthesis QA: While
N=2V-Only delivers a strong+19.44 ppnet gain on MW-QA (56/72vs42/72,p = 0.0066, driven byconfig_overridejumping1/24 → 18/24), thepython_tracesub-family traded off24/24 → 20/24(2missing-####outputs). For strict step-by-step code tracing where stock Base is already at ceiling,N=1Wake-only remains immediately available at zero reload cost. LoopCD-Hiddenscope: Contrastive hidden-state decoding (--loopcd-omega > 0) improves offline NLL and short-answer ICL, but hurts long chain-of-thought math (GSM8Kregressed significantly atω=0.35,p=0.0386). Keepω = 0.0(default) for general generation and reasoning.- Attention backend requirement: Bidirectional Sleep passes use 4D additive intra-window masks and require
sdpaoreagerattention. FlashAttention-2 and FlexAttention are explicitly disabled and rejected whenN > 1. - Quantization & Tensor Parallelism:
SleepOnlyLoRALinearwraps everynn.Linearprojection, so bitsandbytes 4/8-bit auto-quantization leaves wrapped projections unquantized and custom TP plans may require adaptation. - PyTorch reference memory traffic:
modeling_qwen3_sleep.pyconcatenates per-window KV slices withtorch.cat, creating transient KV copies (unlike ASOR Metal's fixed-buffer in-place KV cache).
Runtime Compatibility Matrix
| Runtime | Full Sleep (N=2/4, sleep_v_only: true default) + MessageGateSleepBridge | N=1 Frozen-Wake | How to Run |
|---|---|---|---|
Hugging Face transformers | Yes (CUDA tested; MPS/CPU best-effort; single-device recommended) | Yes | AutoModelForCausalLM.from_pretrained("bmswheart/SleepyInkling-Qwen3-4B", trust_remote_code=True) |
| Apple Silicon MLX | Yes (0.25 s load, 61.8 tok/s, sleep_v_only: true, --loopcd-omega) | Yes | python mlx_sleep_runner.py --model bmswheart/SleepyInkling-Qwen3-4B --num-loops 2 |
| ASOR Metal (Native C++20) | Yes (native sleep_bridge_msggate_* + single-slice V-Only KV gates; separate repo) | Yes | MSWlabAI/asor: convert_model.py --precision native -> asor serve / asor score |
| OpenAI-Compatible Server | Yes (bundled Torch & MLX backends) | Yes | python openai_sleep_server.py --model ./SleepyInkling-Qwen3-4B --model-id SleepyInkling-Qwen3-4B --backend torch|mlx |
vLLM (vllm_plugin/, Out-of-Tree) | Yes (zero-fork vllm.general_plugins, Value-Only prefill + stock PagedAttention decode) | Yes (SLEEPY_INKLING_NUM_LOOPS=1) | pip install ./vllm_plugin && vllm serve bmswheart/SleepyInkling-Qwen3-4B |
| SGLang | via openai_sleep_server.py | Yes (serve-sglang via stripped shadow dir) | python vllm_sglang_wrapper.py serve-sglang --model ./SleepyInkling-Qwen3-4B |
| llama.cpp / Ollama | — | Yes (strip-gates) | python vllm_sglang_wrapper.py strip-gates --src ./SleepyInkling-Qwen3-4B --dst ./SleepyInkling-Qwen3-4B-n1 |
Quick Start
Install dependencies (recommended transformers>=5.0,<6; Qwen3SleepConfig also includes a rope_theta compatibility guard for transformers v4):
pip install "transformers>=5.0,<6" accelerate safetensors huggingface_hub
1. Apply the Compact 163.46 MiB Plug-In Adapter onto Qwen/Qwen3-4B
hf download bmswheart/SleepyInkling-Qwen3-4B-adapter --local-dir ./sleepy_inkling_adapter
python ./sleepy_inkling_adapter/apply_sleep_adapter.py apply \
--base Qwen/Qwen3-4B \
--adapter ./sleepy_inkling_adapter \
--out ./SleepyInkling-Qwen3-4B \
--verify-sha256 22bb77fd9a8a9eb0743bf9096a7c3d311bd0c7d35e684fca43520cfdefaea5b6
(You can also pass --adapter bmswheart/SleepyInkling-Qwen3-4B-adapter directly or alias --base-model Qwen/Qwen3-4B.)
2. Hugging Face transformers (PyTorch — Full N=2/4 Value-Only Sleep Default)
Note: Sleep consolidates every
W = 256tokens, so prompts must be≥ 256tokens for Sleep to fire during prefill (≥ 512tokens to observe post-Sleep NLL differences across multiple windows). Standardmodel()/model.generate()runN=1Wake-only; useforward_sleep()/generate_sleep(). Value-Only Sleep (sleep_v_only: true) is active by default fromconfig.json; passv_only=Falseto opt back into legacy K+V gating.
import torch
from transformers import AutoModelForCausalLM, PreTrainedTokenizerFast
model_id = "bmswheart/SleepyInkling-Qwen3-4B" # or local "./SleepyInkling-Qwen3-4B"
tokenizer = PreTrainedTokenizerFast.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
trust_remote_code=True,
dtype=torch.bfloat16,
device_map="auto",
).eval()
# Multi-window (>= 512 tokens) technical context so Sleep triggers across W=256 boundaries
doc = (
"Service Runbook — HeliosCache uses three tiers: Tier-0 is a 256 MiB per-worker in-process LRU slab "
"with a 15s soft TTL; Tier-1 is a regional NVMe ring with W=2 of R=3 synchronous quorum writes and "
"CRC32C checksums; Tier-2 archives cold keys older than 4 hours to object storage. During single-zone "
"power loss, ephemeral=true keys degrade to W=1 while durable auth keys stay W=2. "
) * 10
prompt = doc + "\nQuestion: How do ephemeral=true and durable auth keys differ during single-zone power loss?\nAnswer:"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
assert inputs["input_ids"].shape[1] >= 512
with torch.inference_mode():
# Full Wake-Sleep generation (N=2 Value-Only bidirectional KV consolidation every 256 tokens)
out = model.generate_sleep(inputs["input_ids"], max_new_tokens=128, num_loops=2)
print(tokenizer.decode(out[0, inputs["input_ids"].shape[1]:], skip_special_tokens=True))
# Compare Wake-only (N=1) vs Wake+Sleep (N=2, sleep_v_only=True default) NLL over the prompt
out_n1 = model.forward_sleep(inputs["input_ids"], labels=inputs["input_ids"], num_loops=1)
out_n2 = model.forward_sleep(inputs["input_ids"], labels=inputs["input_ids"], num_loops=2)
print(f"N=1 loss: {out_n1.loss.item():.4f} | N=2 V-Only loss: {out_n2.loss.item():.4f}")
3. Apple Silicon MLX (Standalone — 0.25 s Load, No PyTorch Required)
# Works with a Hugging Face Hub repo ID or local model directory (uses sleep_v_only: true from config.json):
python mlx_sleep_runner.py --model bmswheart/SleepyInkling-Qwen3-4B \
--prompt "Write a concise Python LRU cache with O(1) get and put." \
--num-loops 2 --max-tokens 256
# Compare N=1 vs N=2 V-Only NLL (and optional LoopCD-Hidden omega for offline scoring) on any local text file:
python mlx_sleep_runner.py --model bmswheart/SleepyInkling-Qwen3-4B \
--compare-n1-n2 --text-file ./README.md --loopcd-omega 0.35
4. Native ASOR Metal (Separate C++20/Metal Engine Repository)
Native Metal conversion and serving require the separate ASOR repository (https://github.com/MSWlabAI/asor), which provides scripts/convert_model.py (automatically propagating sleep_v_only: true into recipe.yaml) and the asor binary with fused MessageGateSleepBridge and single-slice V-Only Sleep KV kernels:
# Inside a checkout of https://github.com/MSWlabAI/asor:
python scripts/convert_model.py \
--src ./SleepyInkling-Qwen3-4B \
--dst ./SleepyInkling-Qwen3-4B-native.asor \
--precision native
asor serve --model ./SleepyInkling-Qwen3-4B-native.asor --port 8080
5. vLLM Out-of-Tree Plugin (vllm_plugin/), OpenAI Server, SGLang & llama.cpp
# Native vLLM Value-Only Sleep (zero fork — uses bundled vllm.general_plugins package):
pip install ./vllm_plugin
vllm serve bmswheart/SleepyInkling-Qwen3-4B --dtype bfloat16 --port 8000
# Or attach the 163.46 MiB adapter dynamically onto stock Qwen/Qwen3-4B in vLLM:
SLEEPY_INKLING_ADAPTER=bmswheart/SleepyInkling-Qwen3-4B-adapter \
vllm serve Qwen/Qwen3-4B --dtype bfloat16 --port 8000
# Standalone OpenAI-compatible API (Torch / MLX):
python openai_sleep_server.py --model ./SleepyInkling-Qwen3-4B --model-id SleepyInkling-Qwen3-4B --backend torch --port 8000
python openai_sleep_server.py --model ./SleepyInkling-Qwen3-4B --model-id SleepyInkling-Qwen3-4B --backend mlx --port 8000
# SGLang / llama.cpp (exact N=1 Frozen-Wake compatibility):
python vllm_sglang_wrapper.py serve-sglang --model ./SleepyInkling-Qwen3-4B --port 30000
python vllm_sglang_wrapper.py strip-gates --src ./SleepyInkling-Qwen3-4B --dst ./SleepyInkling-Qwen3-4B-n1
Citations
Please cite the original authors of Sample-Efficient In-Context Adaptation via Sleep, Inkling-2-Mini (Thinking Machines Lab), and Qwen3:
@article{lee2026sleep,
title = {Sample-Efficient In-Context Adaptation via Sleep},
author = {Lee, Sangyun and Zhang, Enyan and Xu, Michael and Tang, Hao and Lin, Zinan and Xu, Weijia and Quirk, Chris and Gao, Jianfeng and Fanti, Giulia and Liu, Xiaodong},
journal = {arXiv preprint arXiv:2611.32802},
year = {2026},
url = {https://arxiv.org/abs/2611.32802}
}
@misc{thinkingmachines2026inkling2mini,
title = {Inkling-2-Mini},
author = {{Thinking Machines Lab}},
year = {2026},
howpublished = {\url{https://huggingface.co/thinkingmachines/Inkling-2-Mini}}
}
@article{yang2025qwen3,
title = {Qwen3 Technical Report},
author = {Yang, An and Li, Anfeng and Yang, Baosong and Zhang, Beichen and Hui, Binyuan and Zheng, Bo and Yu, Bowen and Gao, Chang and Huang, Chengen and Lv, Chenxu and others},
journal = {arXiv preprint arXiv:2505.09388},
year = {2025},
url = {https://arxiv.org/abs/2505.09388}
}