Repository navigation
feat(inkling2): GPU batched prefill, quantized KV, chat/serve parity, inkling2v vision, and DSpark/N-gram speculative decoding - #65
Conversation
Aletheore Flash reviewNo issues found in this diff. Note: 11 of 40 changed file(s) were not included in this review (the review reads at most 30 files, and skips any file over 100KB). Issues in them would not be found, and citations pointing into them could not be checked against the real file: |
🔍 Aletheore evidence diffgraph LR
n0["src/backend.rs"]
n1["src/cuda/mod.rs"]
n2["mat.rs"]
n3["src/inkling2/mod.rs"]
n4["src/serve.rs"]
n5["image.rs"]
n6["mmproj.rs"]
n7["projector.rs"]
n8["src/vulkan/mod.rs"]
n9["src/chat.rs"]
n10["cpu_worker.rs"]
n11["src/deepseek/chat.rs"]
n12["src/deepseek/forward.rs"]
n13["src/deepseek/mod.rs"]
n14["expert_cache.rs"]
n15["src/gemma4/forward.rs"]
n16["src/gemma4/mod.rs"]
n17["src/glm/forward.rs"]
n18["src/glm/mod.rs"]
n19["src/gpu_model.rs"]
n20["prefill.rs"]
n21["hf.rs"]
n22["src/hy4/chat.rs"]
n23["src/hy4/forward.rs"]
n24["lib.rs"]
n25["model.rs"]
n26["src/vision/mod.rs"]
n27["preflight.rs"]
n28["tests/backend.rs"]
n29["tests/common/mod.rs"]
n30["tests/gpu_model.rs"]
n31["kv_q8.rs"]
n32["llama_numerics.rs"]
n33["tests/serve.rs"]
n0 --> n10
n0 --> n14
n0 --> n19
n0 --> n20
n0 --> n24
n0 --> n25
n0 --> n28
n0 --> n29
n0 --> n30
n0 --> n31
n0 --> n32
n1 --> n24
n1 --> n27
n1 --> n29
n1 --> n30
n1 --> n31
n1 --> n32
n2 --> n12
n2 --> n13
n2 --> n15
n2 --> n17
n2 --> n23
n3 --> n24
n4 --> n9
n4 --> n11
n4 --> n16
n4 --> n18
n4 --> n21
n4 --> n22
n4 --> n24
n4 --> n33
n5 --> n16
n5 --> n26
n6 --> n26
n6 --> n29
n7 --> n16
n7 --> n26
n8 --> n24
n8 --> n27
n8 --> n28
n8 --> n29
n8 --> n30
n8 --> n31
n8 --> n32
classDef changed fill:#d9772c,color:#fff,stroke:#b85f1c;
classDef changedFinding fill:#c0392b,color:#fff,stroke:#922b21;
classDef dependent fill:#f2f0ec,color:#18140f,stroke:#d6d0c5;
class n0 changed
class n1 changed
class n2 changed
class n3 changed
class n4 changed
class n5 changed
class n6 changed
class n7 changed
class n8 changed
class n9 dependent
class n10 dependent
class n11 dependent
class n12 dependent
class n13 dependent
class n14 dependent
class n15 dependent
class n16 dependent
class n17 dependent
class n18 dependent
class n19 dependent
class n20 dependent
class n21 dependent
class n22 dependent
class n23 dependent
class n24 dependent
class n25 dependent
class n26 dependent
class n27 dependent
class n28 dependent
class n29 dependent
class n30 dependent
class n31 dependent
class n32 dependent
class n33 dependent
What changed
Aggregate deltas
|
edaf155 to
b4b1a69
Compare
…kling2v vision, and DSpark/ngram speculative decoding
b4b1a69 to
4246396
Compare
|
@ybenyedder Merged, ty, this is a lot of work. It is also the answer to #66. I ran it on an RTX 3060 12 GB (CUDA and Vulkan) and fixed these on top, in the merge commit:
Measured after the fixes, same card,
|
Closes #62
Summary
Completes and optimizes
inkling2_loop(Inkling 2 Mini 21B-A1.5B MoE) across decode, batched GPU prefill, quantized KV cache, CLI/chat/serveparity, multimodalinkling2vvision, and speculative decoding (--draft-modelDSpark +--spec-typecontext-lookup drafters).1. Decode & Zero-Round-Trip GPU MoE Optimizations
situ_q(src/vulkan/shaders/situ_q.comp,src/cuda/kernels.cu): Fuses Inkling 2's bounded SITU activation directly withQ8_1(int8+ per-32 scale) quantization so the down-projectionmoe_gemvskips a separatequant_xqpass.softcap(src/vulkan/shaders/softcap.comp,src/cuda/kernels.cu) &Device::step_argmax: Keeps the200,064-vocab final logit softcap (y * tanh(x / y)) and greedy argmax on the GPU, transferring 4 bytes instead of 800 KB per greedy step.ink_route.comp/ink_routeCUDA) + PriorityFullExpsSlab Preload: Top-8 sigmoid +e_score_correction_bias+ normalizedexp_scalerouting on the GPU; prioritizes the 12 core layers (each visited 3× per token acrossloop_count = 3, i.e. 36/48 = 75% of all slot runs) before prelude/coda layers when preloadingFullExpsslabs, and fixes non-FullExpscoda layers to deterministic GPU execution whenDeviceis active.Dev::uploadDeduplication (src/deepseek/mat.rs): Deduplicates dense GPU tensor uploads by(data.as_ptr(), data.len()).2. Batched GPU Prefill, Dynamic
--ctx, and Quantized KV (--kv f16|q8|q4|q2)Device::prefill_chunk_seq/prefill_layer): Runs prompt chunks on the GPU (ink_mix_n,ink_ctrl_n,ink_conv_batch,ink_clip_n,ink_attn_prefillwith staging of new SWA K/V rows intokc_tmp/vc_tmpso ring wrap never overwrites live history< pos0, and batched GPU MoE).--ctxup tocfg.ctx = 262,144): Replaces the hardcoded 4,096-token limit with dynamic KV capacity growth up to--ctx(capped atcfg.ctx).--kv f16|q8|q4|q2): Updatesink_clip.comp,ink_attn.comp,ink_attn_prefill.comp, and CUDAink_clip/ink_attn/ink_attn_prefillto usekv_put/ldkvwithbe.kv_words(kw)row sizing across all 4 KV modes.3. Full
chat/serve/ CLI Parity &CheckpointPrefix ReuseInkling2Opts(src/inkling2/chat.rs,src/main.rs): WiresSampler(--temp,--top-k,--top-p,--seed,--repeat-penalty,--penalty-last-n,--presence-penalty,--frequency-penalty,--dry-*),--ctx,--think,--thinking-budget, and--allowed-hostsintoinkling2::chat::{generate_image_opts, chat_image_opts, serve_opts}.reasoning_effort(none|minimal|low|medium|high|xhigh|maxor0..=0.99) andthinkboolean toThinking effort level: <val>, and enforcesthinking_budgetby closing<|content_thinking|>with<|end_message|><|message_model|><|content_text|>on the GPU before sampling the final answer.include_usage,/v1/messages, and Multi-TurnCheckpointPrefix Reuse: Holds back partial stop strings viaHold, emitsusage(prompt_tokens_details.cached_tokens) on final SSE chunks whenstream_options.include_usageis set, supports Anthropic/v1/messages, and snapshots(Checkpoint, logits)right after prefill so subsequent turns where the client omits priorreasoning_contentrestore the exact KV + conv + SWA prefix state in O(1) without re-prefilling history.4. Multimodal Vision (
inkling2vinsrc/vision/&src/inkling2/)ProjectorKind::Inkling2V(src/vision/mmproj.rs,src/vision/image.rs,src/vision/projector.rs): Implementsinkling2vViT + 3×3 PatchMerger (post_norm-> 3×3 grouped patch gather ->input_norm-> gated SwiGLUgate_proj/up_proj/down_proj), 2D learned position embeddings, and aspect-preserving bilinear resize + bottom/right zero-padding without upscaling small images (matchingllama.cppmtmd_graph_inkling2v&mtmd_image_preprocessor_inkling2v).Inkling2Model::prefill_embds): Expands<|content_image|><|unused_200054|><|end_message|>placeholders into(nx / 3) * (ny / 3)vision embeddings and skipstok_normon vision tokens (matchinginkling2.cpp::build_inputs()).5. Speculative Decoding (
Device::verify_forward+commit_verify+--spec-type+ DSpark--draft-model)Device::verify_forward,Device::commit_verify): Verifies[anchor, drafts..](1 <= nt <= 16) in one batched pass on the GPU with exactDevice::stepnumerics (rms_norm_q+gemvq,ink_attn, and router-rank-ordered FFN) and rolls back rejected draft tokens' SWA ring rows and 4 causal conv histories in place on the GPU.src/inkling2/dspark.rs,--draft-model): Implements the 3-layer DSpark speculative draft model (dspark-Inkling-2-Mini-Q8_0.gguf, matchingllama.cppPR #32218): target feature extraction at visits[5, 23, 41, 48], softmaxdspark_fuse.weightmixing,dflare_norm,attn_k_ctx/attn_v_ctxKV cache injection withattn_k_ctx_normand NEOX RoPE (theta = 1e6), 8-token non-causal block attention (anchor+ 7mask_embd), and chained Markov RNN head (markov_w1+joint_proj+dspark_hidden_out) with target GPUlm_head_argmax.--spec-type): IntegratesNgramDrafter(ngram-simple,ngram-map-k,ngram-map-k4v,ngram-mod,ngram-cache,suffix) intoInkling2Model.Benchmarks & Verification (AMD Radeon 890M
gfx1150, Vulkan RADV,Inkling-2-Mini-IQ4_NL.gguf)--gpu --backend vulkan)10db14c)pp 64(prefill tok/s)36.9 tok/s53.5 tok/spp 512(prefill tok/s)95.8 tok/s135.3 tok/spp 2048(prefill tok/s)108.0 tok/s124.7 tok/stg 64@pp 64(decode tok/s)7.4 tok/s9.0 tok/stg 64@pp 512(decode tok/s)7.6 tok/s8.9 tok/stg 64@pp 2048(decode tok/s)7.5 tok/s8.6 tok/s--draft-model dspark-Inkling-2-Mini-Q8_0.gguf)40/70 (57.1%)Test Suite
cargo test --release --lib --locked: 96/96 passed (0 warnings)cargo test --release --test backend --locked: 10/10 passed (spirv_is_freshok)cargo test --release --test kernels --locked: 35/35 passed (situ_q_matches_situ_and_quant_xq,softcap_matches_cpu,ink_route_matches_cpu,ink_conv_batch_matches_sequential,ink_attn_prefill_matches_single_step,ink_attn_quantized_kv_modes_match_f16ok)cargo test --release --test vision --locked: 14/14 passed (inkling2v_encode_and_pad,inkling2v_red_image_predicts_redok)STRATA_INKLING2_MODEL=.../Inkling-2-Mini-IQ4_NL.gguf STRATA_DS_GPU=1 cargo test --release --test inkling2_forward --locked: 4/4 passed (short_prompt_follows_llama_cpp,long_prompt_follows_llama_cpp,chunked_prefill_matches_token_by_token,speculative_ngram_and_dspark_match_greedyok)src/cuda/kernels.cuandsrc/cuda/mod.rsare updated in lockstep with Vulkan/CPU and not compiled on this AMD host.