Inkling-2-Mini-DFly2 / HANDOFF.md
shisuiki's picture
Update repository contents and docs for Honeycomb v0.2.0 (DFly2-KV + TurboQuant K6V4 / TS-QJL2)
234bad5 verified
|
Raw History Blame Contribute Delete
14.5 kB

Inkling-2-Mini DFly2-KV Drafter — Serving & Kernel Integration Handoff

1. Verified Artifacts

  • On endmin: /data/models/Inkling-2-Mini-DFly2-Pilot/
    • model.safetensors — 71 tensors, all bfloat16, 320,368,336 params (640,747,008 B = 640.7 MB), zero NaN/Inf, bit-for-bit verified
    • SHA256: 48a60f271a7eb7cad3458b7d84bc9332c2b7e7ccb74fc67bea7ba9cc9eec0dbc
    • config.json — complete architecture & export metadata
    • tensor_inventory.json — full list of all 71 tensor names, shapes, and dtypes
    • eval_i2m_onpolicy_step956.json — exact side-by-side held-out eval vs. native DSpark7 (step 956, 2 ep on-policy)
    • eval_i2m_onpolicy_step720.json — 1-epoch on-policy ablation (step 720)
    • eval_i2m_pilot_report.json — pre-on-policy off-policy baseline (step 478) for reference
    • reference_model.py & reference_kernels.py — exact PyTorch/Triton forward contract (I2MDFly2DraftModel.draft_one_block)
  • Nebius S3 Archive:
    • Exported safetensor (step 956): s3://q27-dfly2-us-north1/i2m/runs/i2m_dfly2_pilot_onpolicy/export_step_00956/model.safetensors
    • Resumable un-decayed WSD checkpoints (step 956 & step 720, constant lr = 5e-4):
      • s3://q27-dfly2-us-north1/i2m/runs/i2m_dfly2_pilot_onpolicy/final_step_00956/ckpt.pt
      • s3://q27-dfly2-us-north1/i2m/runs/i2m_dfly2_pilot_onpolicy/step_00720/ckpt.pt
    • On-policy training corpus (50 shards = 501.35M tokens, 51,854 unique I2M trajectories): s3://q27-dfly2-us-north1/i2m/data_onpolicy/shards/

Checkpoint status: Un-decayed WSD On-Policy Pilot (step 956, 2.005B cumulative tokens = 1.002B off-policy warmup + 1.002B pure Inkling-2-Mini on-policy rollouts, pre-cooldown at constant peak lr = 5e-4, matching Q27 Pilot's un-decayed state). Any future WSD cooldown or extended on-policy run exports the exact same 71 tensor names and shapes as a drop-in swap.

Reference Held-Out Acceptance (γ = 7, max τ = 8.0, 48-Visit BF16 Teacher, 15 Balanced Prompts)

Drafter Draft KV Cache T = 0.0 Overall T = 0.6 Overall short_1_4k (T=0.0 / 0.6) mid_4_12k (T=0.0 / 0.6) long_12_30k (T=0.0 / 0.6) Verify Steps (T=0.0 / 0.6)
Native DSpark7 (mtp.safetensors) Own 3-layer KV 3.050 3.228 2.368 / 2.672 3.286 / 3.495 3.871 / 3.729 319 / 302
I2M DFly2-KV Off-Policy (step 478) 0 bytes 2.150 2.245 1.747 / 1.801 2.331 / 2.492 2.528 / 2.639 448 / 433
I2M DFly2-KV On-Policy 1-Ep (step 720) 0 bytes 3.686 3.670 3.309 / 3.137 3.505 / 3.721 4.411 / 4.356 261 / 261
I2M DFly2-KV On-Policy 2-Ep (step 956) 0 bytes 3.645 3.722 3.473 / 3.505 3.200 / 3.320 4.486 / 4.549 265 / 259

2. Exact Architecture & Forward Contract

Core Dimensions (1 Global + 2 Local SWA-1024, DSpark-Matched Size)

  • hidden_size = 2304, intermediate_size = 8192, num_hidden_layers = 3 (320.37M params vs. native DSpark7's 317.9M)
  • num_attention_heads = 24, num_key_value_heads = 8, head_dim = 128 (GQA 3:1; TP4: 6 Q heads / 2 KV heads per GPU)
  • Native Inkling-2-Mini attention space (NO RoPE, NO draft short-conv state):
    • Sheared relative position bias: d_rel = 16, rel_extent = 1024, sliding_window_size = 1024
    • L2-clipped Q/K (qk_l2_clip_threshold = 22.627416997969522 = 16√2) & R (rel_l2_clip_threshold = 8.0)
    • Unit RMSNorm V (no learnable gamma), rms_norm_eps = 1e-6
    • Log-length scaling on global layer 1 only: tau(pos) = 1.0 + 0.1 * log(max(pos, 8192) / 8192)
    • Output gating + sink: ao_gated = ao * sigmoid(gate) * sigmoid(lse - sink) (note: lse is natural log!)
  • block_size = 8 (1 anchor slot 0 + γ = 7 draft slots 1..7)
  • target_kv_layers = [20, 23, 22] (all in the unlooped epilogue, visits 44, 47, 46 — 0 bytes of draft context KV cache and 0 bytes of draft conv state!):
    • Draft layers.0 (local, SWA-1024) → reads target L20 cached (K_ctx, V_ctx)
    • Draft layers.1 (global, FULL ctx) → reads target L23 cached (K_ctx, V_ctx)
    • Draft layers.2 (local, SWA-1024) → reads target L22 cached (K_ctx, V_ctx)
    • AttentiveCorrection (local, SWA-1024) → reads target L22 cached (K_ctx, V_ctx) (O(1) bandwidth per slot!)
  • Shared target weights (NOT stored in model.safetensors):
    • embed_tokens — CRITICAL: Inkling-2-Mini applies unit RMSNorm + scaling to embeddings (embed_normalized(ids) = rms_norm_no_gamma(embed_tokens(ids)), see reference_kernels.py / target embed_tokens path; exact match to teacher.embed_normalized!).
    • lm_head ([200058, 2304] unpadded) with logit soft-capping 30.0 * tanh(logits / 30.0).

Step-by-Step Serving Forward Pass (draft_one_block)

Inputs after target prefill/verify emits the accepted anchor token:

  • anchor_tok ([B]): newly accepted/sampled token at 0-indexed position anchor_pos = ctx_len. (Has NOT yet been processed by the target model.)
  • prev_hidden_normed ([B, 2304]): target's post-final-RMSNorm hidden state (target.model.norm(...)) at position ctx_len - 1 (the exact state whose logits produced anchor_tok).
  • target_kvs: paired target post-clip/post-norm (K_ctx, V_ctx) for positions 0 .. ctx_len - 1 from target unlooped epilogue layers [20, 23, 22].

Stage A — Block Input Construction (1× per step, S = 8 tokens at positions anchor_pos .. anchor_pos + 7):

  1. e0 = target.embed_normalized(anchor_tok) ([B, 2304]).
  2. Slot 0: h[:, 0] = e0 + mtp_fusion.eh_proj(cat([enorm(e0), hnorm(prev_hidden_normed)], dim=-1)) * mtp_fusion.gate.
  3. Slots 1..7: initialized to mask_embedding ([2304]).
  4. Compute tau_draft[slot] = 1.0 + 0.1 * log(max(anchor_pos + slot, 8192) / 8192) for slot in 0..7 (used ONLY on global layers.1).

Stage B — 3 KV-Sharing Backbone Layers (1 parallel pass over S = 8 tokens): For i in {0, 1, 2} reading target layer [20, 23, 22]'s cached (K_ctx, V_ctx) (is_local = (i in {0, 2})):

  1. x = input_layernorm(h). (Standard Inkling-2-Mini RMSNorm: weight * rsqrt(mean(x^2) + 1e-6) * x, NOT +1 centered!)
  2. Project q_raw = wq_du(x) ([B,8,24,128]), r_raw = wr_du(x) ([B,8,24,16]), gate = gate_attn(x) ([B,8,24,128]), sink = attn_sink_proj(x) ([B,8,24]), k_d = wk_dv(x) ([B,8,8,128]), v_d = wv_dv(x) ([B,8,8,128]).
  3. Normalize & clip (identical to Inkling-2-Mini target attention, tau_v = tau_draft if i == 1 else None):
    • q = i2m_l2_clip(q_raw, q_scale, clip=22.627417, eps=1e-6, tau=tau_v)
    • r = i2m_l2_clip(r_raw, r_scale, clip=8.0, eps=1e-6, tau=tau_v)
    • k_d = i2m_l2_clip(k_d, None, clip=22.627417, eps=1e-6, tau=None)
    • v_d = unit_rms_norm(v_d, eps=1e-6)
    • rel_all = r @ rel_logits_proj ([B, 24, 8, 1024]).
  4. Non-causal (bidirectional) block attention over [K_ctx | k_d(0..7)] and [V_ctx | v_d(0..7)], scale 128^-0.5, GQA 24:8:
    • Context positions j < anchor_pos (if is_local, only (anchor_pos + q_slot - j) < 1024): add rel_all[h, q_slot, dist] where 0 <= dist < 1024, dist = (anchor_pos + q_slot) - j.
    • Intra-block positions kv_slot in 0..7: add rel_all[h, q_slot, q_slot - kv_slot] (when q_slot >= kv_slot) PLUS intra_rel_bias[h, (q_slot - kv_slot) + 15].
    • Compute (ao, lse) via exact online-softmax merge of (ao_ctx, lse_ctx) and the 8×8 intra-block (ao_blk, lse_blk) — ephemeral (k_d, v_d) are discarded, never written to KV cache!
  5. Output gate & sink: ao_gated = ao * sigmoid(gate) * sigmoid(lse - sink) → h = h + wo_ud(ao_gated).
  6. MLP: h = h + mlp.down_proj(silu(mlp.gate_proj(post_ln(h))) * mlp.up_proj(post_ln(h))).
  7. After layers.2: h = norm(h).

Stage C — Sequential TreeFlash + SWA-1024 AttentiveCorrection (slot = 0..7, reading target L22 SWA-1024 KV):

  • Critical: Slot 0 MUST run first with h_k = h[:, 0:1], e_prev = e0, slot_idx = 0 so that blk_k_cache[:, :, 0:1] and blk_v_cache[:, :, 0:1] are populated before drafting slot = 1..7. (Its corrected hidden output is unused.)
  • For slot = 1..7 (producing drafted tokens d_1 .. d_7, with prev_tok = anchor_tok at slot = 1, then d_{slot-1}):
    1. h_n = hidden_norm(h[:, slot:slot+1]), e_n = embed_norm(embed_normalized(prev_tok)), inp = cat([h_n, e_n], dim=-1) ([B, 1, 4608]).
    2. SwiGLU delta: delta = down_proj(silu(gate_proj(inp)) * up_proj(inp)).
    3. AttentiveCorrection delta (L22 SWA-1024, no output sigmoid gate, no sink on ctx read):
      • q = i2m_l2_clip(q_in(inp), q_scale, 22.627417) ; r = i2m_l2_clip(r_in(inp), r_scale, 8.0) ; rel_row = r @ rel_logits_proj.
      • Context read over L22 KV slice c_start = max(0, ctx_len + slot - 1023) .. ctx_len - 1 (<= 1024 tokens, O(1) bandwidth regardless of context length!) with sheared bias rel_row[dist] (dist = ctx_len + slot - j).
      • Causal intra-block read: append kb = i2m_l2_clip(k_blk_proj(inp), None, 22.627417), vb = unit_rms_norm(v_blk_proj(inp)) to blk_{k,v}_cache (len = slot + 1), compute logits q @ k_blk^T * 128^-0.5 + block_rel_bias[:, slot - t], apply block_sink via p_blk = exp(logits - logaddexp(lse(logits), block_sink)), multiply read = p_blk @ v_blk by tanh(block_gate(inp) + block_gate_bias[:, slot]).
      • attn_delta = o_proj(ctx_out + read * gate).
    4. h_corr = h[:, slot] + delta + attn_delta.
    5. logits = 30.0 * tanh((h_corr @ lm_head.T) / 30.0) → argmax / sample d_slot.

3. Critical Subtle Gotchas (Check Before Kernel Bring-Up!)

  1. Standard RMSNorm (NOT +1 Qwen-style!): I2MRMSNorm computes weight * rsqrt(mean(x^2) + 1e-6) * x (standard Inkling-2-Mini RMSNorm; weights initialized around 1.0).
  2. Normalized Embeddings (embed_normalized): Every embedding lookup (anchor_tok in Stage A, prev_tok in Stage C) MUST apply Inkling-2-Mini's embedding normalization (identical to target embed_tokens scaling/norm — verify against reference_model.py / teacher.py!).
  3. Log-Length Scaling tau ONLY on Global layers.1: layers.0, layers.2, and AttentiveCorrection are all local SWA-1024 (tau = None). Only layers.1 (paired with global target L23) scales q and r by tau(anchor_pos + slot) when anchor_pos + slot > 8192.
  4. No Output Gate or Sink in AttentiveCorrection Context Read: Backbone layers.{0..2} use sigmoid(gate) * sigmoid(lse - sink). AttentiveCorrection uses a plain softmax context read over L22 (<= 1024 tokens) plus a block_sink-normalized, tanh-gated causal intra-block read (block_gate + block_gate_bias[:, slot]).
  5. 16-Slot / 31-Offset Bias Buffers: intra_rel_bias has shape [24, 31] (center = 15, q_slot - kv_slot in [-7, +7] → indices 8..22); block_rel_bias and block_gate_bias have shape [24, 16] (indices 0..7 exercised during block_size = 8 training).
  6. Target Verify Window (Q = 8): Verifying γ = 7 drafted tokens feeds [anchor_tok, d1..d7] (Q = 8 tokens) into the 48-visit Inkling-2-Mini target model and checks target logits at [ctx_len .. ctx_len + 7].

4. Tensor Inventory Summary (71 Tensors, All bfloat16)

Group Tensor Pattern Shape Params Notes
Mask embed mask_embedding [2304] 2.3K Shared across slots 1..7
MTP fusion (slot 0) mtp_fusion.{enorm,hnorm}.weight, gate, eh_proj.weight [2304], [2304, 4608] 10.6M Zero-init per-channel gate
Backbone Attn ×3 (i=0,1,2) wq_du, gate_attn, wo_ud, wk_dv, wv_dv, wr_du, attn_sink_proj [3072,2304], [1024,2304], [384,2304], [24,2304] 3 × 26.9M Paired 1-to-1 with target L20 (SWA), L23 (Global), L22 (SWA)
Backbone Attn Scales/Bias ×3 q_scale, r_scale, rel_logits_proj, intra_rel_bias [24,128], [24,16], [16,1024], [24,31] 3 × 20.6K Keep FP16/FP32 on sm_70
Backbone MLP ×3 gate_proj, up_proj, down_proj, {input,post}_layernorm [8192,2304], [2304,8192], [2304] 3 × 56.6M SwiGLU, TP4 I_local = 2048
Final norm norm.weight [2304] 2.3K Standard RMSNorm
Correction SwiGLU {hidden,embed}_norm, {gate,up}_proj, down_proj [2304,4608], [2304,2304] 26.5M TP4 I_local = 576
Correction Attn (L22 SWA) q_in, r_in, k_blk_proj, v_blk_proj, o_proj, block_gate [3072,4608], [1024,4608], [2304,3072], [24,4608] 32.6M O(1) SWA-1024 context read
Correction Scales/Bias q_scale, r_scale, rel_logits_proj, block_{sink,rel_bias,gate_bias} [24,128], [16,1024], [24,16] 20.6K Keep FP16/FP32 on sm_70
Total 71 tensors — 320.37M 640.7 MB BF16 (160.2 MB/GPU TP4 unquantized)

5. Volta sm_70 (4× V100-SXM2-16GB, TP4) Serving Notes

  1. Tiny Footprint & Huge Hybrid KV Gain:
    • Even unquantized in FP16, the entire drafter is only 160 MB/GPU at TP4 (~80 MB/GPU if linears are FP8 QPN8 — comparable to DSpark7's weights) while reclaiming 100% of native DSpark7's separate 3-layer KV cache (+16.9% FP16 → +34% FP8 total hybrid KV token capacity on endmin, and composes zero-retrain with TurboQuant K6V4, TS-QJL2(K6V4), K8V4, and ELR).
  2. Exact TP4 Sharding (6 Q heads / 2 KV heads per GPU):
    • Every backbone layer (L20, L23, L22) and AttentiveCorrection (L22) maps 1-to-1 onto each GPU's local 2 KV heads — zero cross-GPU KV communication.
    • Stage B reads only 1 global layer (L23) + 2 SWA-1024 layers (L20, L22), and Stage C's 7 sequential correction slots read only SWA-1024 (L22, <= 1024 tokens) — so at long contexts (16K–128K), DFly2-KV has the same 1G + 2L global KV read bandwidth as DSpark7 while achieving +0.62 to +0.82 τ higher long-context acceptance (4.49–4.55 vs 3.73–3.87).
  3. Zero Rollback State on Rejection:
    • Because neither Stage B nor Stage C writes anything to any persistent KV cache or short-conv buffer, speculative rejection requires zero drafter cache rollback.