Skip to content

[Engine] inkling2: compact Q8 dense trunk representation (-2.2 GB VRAM, +43% decode) - #6823

Closed
cobra91 wants to merge 0 commit into
Niko1221:mainfrom
cobra91:perf/inkling2-compact-trunk
Closed

cobra91 wants to merge 0 commit into
Niko1221:mainfrom
cobra91:perf/inkling2-compact-trunk

Conversation

@cobra91

@cobra91 cobra91 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Problem and result

In strata-inkling (v0.2.20), dense trunk tensors (Section 1: token_embd.weight, output.weight, attention projections attn_q, attn_k, attn_v, attn_r, attn_gate, attn_output) are loaded via copy_mat_bf16 in ink_gguf_loader.h. When loading GGUF models where dense weights are stored in quantized formats (such as Q8_0, Q5_K, Q6_K, Q4_K), copy_mat_bf16 inflates dense tensors by 2x into 16-bit BF16.
On Inkling-2-Mini-UD-IQ3_XXS.gguf (11.7 GB), this causes:

  1. Section 1 (dense trunk) consumes 3.93 GB of VRAM on GPU 0.
  2. In mono-GPU setups with 16 GB cards (e.g. RTX 5080 16 GB), this 3.93 GB trunk inflation deprives Section 4 of necessary memory budget, causing 980 experts to spill into host RAM (hyb=1: 2,092 GPU0 / 980 host).
  3. The resulting host RAM expert transfers throttle decode throughput to 48.0 tok/s.
  4. In addition, when --draft off is specified, ink_main.cpp leaves dspark_path unset, triggering phantom auto-discovery of companion drafters (e.g. dspark-*.gguf), wasting 640 MB of VRAM.
  5. In ink_kernels.cuh, k_ink_gemv_multi_q8row_m1 calculated quantized weight offsets using Wp + (size_t)Np * 4. When N_override < ti.rows() (e.g. output.weight with unpadded vocab size 200,058 vs 201,024), 200058 * 4 = 800232 was not 16-byte aligned (800232 % 16 = 8), triggering CUDA error 716 (misaligned address).

With this PR:

  1. Dense trunk tensors in GGUF models are loaded using copy_mat_auto: native BF16 tensors remain untouched, while quantized dense tensors are converted to row-scaled INT8 (FMT_Q8ROW) via a multi-threaded dequant/quant pass at load time.
  2. In ink_kernels.cuh, InkMultiProj precomputes an aligned quantized weights pointer Wq[i] = W[i] + (size_t)ti.rows() * 4, guaranteeing 16-byte alignment and completely eliminating CUDA error 716 on unembed projections.
  3. Implements k_ink_screen_eval_q8row and aliases unembed_screen.q8 directly into d_trunk without allocating a duplicate 461 MB screening buffer.
  4. Corrects --draft off to set dspark_path = "none", preventing phantom drafter allocations.
  5. Section 1 dense trunk memory drops from 3.93 GB to 1.72 GB (-2.21 GB saved, -56% memory). Trunk load time drops from 1.04s to 0.38s (-63%).
  6. On mono-GPU RTX 5080 16 GB, resident experts increase by +499 (hyb=1: 2,591 GPU0 / 481 host), and decode throughput increases from 48.0 tok/s to 68.5 tok/s (+42.7% faster).
  7. On dual-GPU (RTX 5080 + RTX 4060 Ti) with Inkling-2-Mini-UD-Q4_K_XL.gguf, all 3,072 experts remain 100% VRAM resident (1,536 GPU0 + 1,536 GPU1 / 0 host) with decode jumping to 81.8 tok/s (+69% to +82% faster than upstream v0.2.20).

Related discussion

Complements PR #6811 (zero-P2P tail-skip) and PR #6815 (zero-copy mapped staging and CUDA graph capture).

Approach

  • In engine/src/inkling2/ink_gguf_loader.h:
    • Implement copy_mat_q8row with parallel CPU worker threads dequantizing GGUF rows to F32 and quantizing to INT8 with row scale dst_sc.
    • Add copy_mat_auto to select copy_mat_bf16 if source tensor type is already BF16 (type 30) or copy_mat_q8row otherwise.
    • Map token_embd.weight, output.weight, attn_q.weight, attn_k.weight, attn_v.weight, attn_r.weight, attn_gate.weight, and attn_output.weight to copy_mat_auto.
    • Check for none or off in explicit dspark path to bypass auto-discovery.
  • In engine/src/inkling2/ink_main.cpp:
    • When --draft off, explicitly set cfg.bopts.dspark_path = "none".
  • In engine/src/inkling2/ink_safetensors_loader.h:
    • Ignore companion mtp.safetensors when explicit path is "none" or "off".
  • In engine/src/inkling2/cuda/ink_kernels.cuh:
    • Extend struct InkMultiProj with const int8_t* Wq[5] to decouple output row count Np from the scale array row stride ti.rows().
    • Provide an overload for ink_resolve_multi_proj resolving Wqp.
    • Update k_ink_gemv_multi_q8row_m1, k_ink_gemv_multi_q8row_preq, and k_ink_gemv_multi_q8row to use Wqp + (size_t)lrow * K, ensuring 16-byte alignment.
    • Support N_stride in k_ink_q8row_to_bf16.
    • Implement k_ink_screen_eval_q8row and add zero-copy ownership tracking (owns_q8, owns_sc) to UnembedScreenIndex.
  • In engine/src/inkling2/cuda/ink_runner.cuh:
    • In init() and init_dual_gpu(): when ui.fmt == FMT_Q8ROW, alias unembed_screen.q8 and unembed_screen.sc directly into d_trunk + ui.off, bypassing duplicate 461 MB allocation.
    • In linear_multi() and linear(): populate mp.Wq using (size_t)ti.rows() * 4.
    • In head_argmax_exact(): dispatch FMT_Q8ROW to k_ink_screen_eval_q8row.

Validation

Passed:

  • Build: MSVC 19.51, CUDA 13.4, Ninja (cmake --build build --target strata-inkling).
  • Hardware: NVIDIA GeForce RTX 5080 16 GB (Blackwell sm_120) + GeForce RTX 4060 Ti 16 GB (Ada sm_89), Windows 11.
  • Empirical Mono-GPU Test on RTX 5080 16 GB:
    • Command: strata-inkling.exe --bench --native Inkling-2-Mini-UD-IQ3_XXS.gguf --draft off --gpus 1 --prompt-len 64 --gen 128
    • Baseline v0.2.20: trunk = 3.93 GB (1.04s), experts = 2,092 GPU0 / 980 host (hyb=1), prefill = 217.4 ppts, decode = 48.0 tok/s.
    • With this PR: trunk = 1.72 GB (0.38s, -56% memory, -63% load time), experts = 2,591 GPU0 / 481 host (hyb=1), prefill = 238.0 ppts, decode = 68.5 tok/s (+42.7% faster).
  • Empirical Dual-GPU Test on RTX 5080 + RTX 4060 Ti:
    • Command: strata-inkling.exe --bench --native Inkling-2-Mini-UD-Q4_K_XL.gguf --draft off --gpus 2 --prompt-len 64 --gen 128
    • Baseline v0.2.20: Layer-Split decode = 45.0 tok/s; cuda-ep2 decode = 48.4 tok/s.
    • With this PR: trunk = 1.72 GB (0.27s), experts = 1,536 GPU0 + 1,536 GPU1 / 0 host (hyb=0, 100% resident), prefill = 125.3 ppts, decode = 81.8 tok/s (+69% to +82% faster).
  • Correctness and stability verified over full 128-token generation runs with zero misalignment faults or memory leaks.

Failed:

  • none observed

Not run:

  • Non-CUDA backends (Metal / SYCL): this PR addresses CUDA dense kernels and GGUF loader in ink_runner.cuh, ink_kernels.cuh, and ink_gguf_loader.h.

Limits

  • FFN gate/up/down expert weights remain in their native block quantization; this PR quantizes the Section 1 dense trunk tensors.

@cobra91

cobra91 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

For anyone wanting to test the full Inkling 2 dual-GPU stack together (#6811 + #6815 + #6823 + #6832 + #6982) without mixing scopes across individual PRs, a dedicated integration branch is available at cobra91/Strata-DualGPU:lab/inkling2-full (0f302f582, smoke-tested on 2x 16 GB UD-Q4_K_XL --gpus 2 --kv k8v4: 1536 + 1536 / 0 host, 80.1 tok/s decode).

@cobra91

cobra91 commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

Closing as superseded by commit c60259fa6 in v0.2.21 (see discussion in #6811 (comment)).

Saw that the compact Q8 dense trunk architecture submitted here on Nov 23 was integrated into v0.2.21 a few hours later via c60259fa6 ("perf(inkling2/cuda): a GGUF's Q8_0 dense matrices stay Q8_0 and run on the int8 tensor cores, one exact GEMM for every batch size"), reducing dense trunk memory to 2.25 GB across the same attention matrices.

Because it was committed directly by the maintainer, the PR remained open without review, and once again the v0.2.21 release notes omitted contributor credits entirely.

As detailed in #6811, having to reverse-engineer maintainer commits after each release to determine what was cherry-picked without credit or left unmerged makes ongoing upstream contributions unsustainable. We are closing our open superseded PRs here and consolidating all our active engine development, asymmetric multi-GPU optimizations, and low-bit MoE kernels on PolyStrata (https://github.com/simplexai-labs/PolyStrata).

@cobra91 cobra91 closed this Nov 24, 2026
@cobra91
cobra91 deleted the perf/inkling2-compact-trunk branch November 24, 2026 22:49
@cobra91
cobra91 restored the perf/inkling2-compact-trunk branch November 26, 2026 14:00
@cobra91 cobra91 reopened this Nov 26, 2026
@cobra91 cobra91 closed this Nov 26, 2026
@cobra91
cobra91 force-pushed the perf/inkling2-compact-trunk branch from 2255ab3 to c234774 Compare November 26, 2026 14:00
@cobra91
cobra91 deleted the perf/inkling2-compact-trunk branch November 26, 2026 14:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant