Skip to content

[Engine] inkling2: native CUDA decoding for IQ2/IQ3/NVFP4 MoE experts (100% VRAM residence on 16GB cards) - #6832

Closed
cobra91 wants to merge 0 commit into
Niko1221:mainfrom
cobra91:perf/inkling2-iq2-moe
Closed

cobra91 wants to merge 0 commit into
Niko1221:mainfrom
cobra91:perf/inkling2-iq2-moe

Conversation

@cobra91

@cobra91 cobra91 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Problem and result

When running Inkling 2 MoE models with low-bit quantizations (such as Unsloth UD quants: IQ2_XXS, IQ2_XS, IQ2_S, IQ3_S, and mixed NVFP4 down-projections like Inkling-2-Mini-UD-IQ3_XXS.gguf), Strata's CUDA engine fell back to treating them as unsupported raw GGUF formats or inflated CPU repackings. Specifically:

  1. ink_gguf_has_gpu_kernel did not recognize IQ2_XXS (type 16), IQ2_XS (type 17), IQ3_S (type 21), IQ2_S (type 22), or NVFP4 (type 40) in MoE expert weights.
  2. In the absence of native CUDA dequantization routines, ink_gguf_row_bytes lacked exact row byte strides for these formats, causing VRAM residency calculations to overestimate expert memory footprint (estimating ~4.5 MB per expert instead of the true ~2.8 MB).
  3. On single 16 GB cards (such as the RTX 5080), this overestimation and missing kernel support forced 481 out of 3072 MoE experts to spill onto host system RAM (hyb=1). Host-PCIe transfers during expert gathering degraded decode speed and caused a 48.16s startup repack delay.

This PR adds native CUDA decoding for IQ2_XXS, IQ2_XS, IQ2_S, IQ3_S, and NVFP4 MoE expert weights in engine/src/inkling2/cuda/ink_moe_cuda.cuh using precomputed constant grid/LUT tables in engine/src/inkling2/cuda/ink_iq_tables.cuh.

With native GPU kernels and exact footprint calculation, Inkling-2-Mini-UD-IQ3_XXS.gguf achieves 100% VRAM residence (hyb=0, 0 host experts) on 16 GB cards, yielding:

  • 100% VRAM residence: 3072 / 3072 experts on GPU 0 (0 spilled to host RAM, down from 481 host experts).
  • Startup delay reduced by -89.6%: Load time drops from 48.16s to 5.00s.
  • Stable decode speed: 59.3 tok/s on single RTX 5080 (and 86.5 tok/s on dual GPU with Q4_K_XL).

Related discussion


Approach

  1. Constant Grid & LUT Tables (engine/src/inkling2/cuda/ink_iq_tables.cuh):
    • kInkIq2XxsGrid[256]: 2 KB constant lookup table for 8-element codebook vectors.
    • kInkIq2XsGrid[512]: 4 KB constant lookup table for 8-element codebook vectors.
    • kInkIq2SGrid[1024]: 8 KB constant lookup table for 8-element codebook vectors.
    • kInkIq3SGrid[512]: 2 KB constant grid for 8-element codebook vectors.
    • kInkE2m1Lut[16]: 16-entry LUT for NVFP4 dequantization.
    • kInkUe4m3Lut[256]: Branchless scale factor lookup table for NVFP4 block scales.
  2. Kernel Dispatch & Exact Strides (engine/src/inkling2/cuda/ink_moe_cuda.cuh):
    • Registered types 16 (IQ2_XXS), 17 (IQ2_XS), 21 (IQ3_S), 22 (IQ2_S), and 40 (NVFP4) in ink_gguf_has_gpu_kernel.
    • Added exact row byte calculation in ink_gguf_row_bytes:
      • Type 16: (K / 256) * 66u
      • Type 17: (K / 256) * 74u
      • Type 21: (K / 256) * 110u
      • Type 22: (K / 256) * 82u
      • Type 40: (K / 64) * 36u
    • Added vectorized dequantization and dot-product loops in ink_gguf_row_dot_multi using DP4A / half2 accumulation.

Validation

Empirical hardware benchmarks conducted on physical GPUs:

  • GPU 0: NVIDIA GeForce RTX 5080 (16 GB VRAM, sm_120)
  • GPU 1: NVIDIA GeForce RTX 4060 Ti (16 GB VRAM, sm_89)

1. Single GPU (RTX 5080 16 GB) - Inkling-2-Mini-UD-IQ3_XXS.gguf

  • Before (Baseline):
    • Experts placement: 2591 GPU0 / 481 host (hyb=1)
    • Load time: 48.16s (CPU repack + host allocation)
    • Prefill: 184.2 ppts
    • Decode: 41.8 tok/s (host PCIe bottleneck on spilled experts)
  • After (This PR):
    • Experts placement: 3072 GPU0 / 0 host (hyb=0) (100% resident)
    • Load time: 5.00s (-89.6% startup delay)
    • Prefill: 232.7 ppts
    • Decode: 59.3 tok/s (+41.8% throughput)

2. Dual GPU (RTX 5080 + RTX 4060 Ti) - Inkling-2-Mini-UD-IQ3_XXS.gguf

  • Experts placement: 1536 GPU0 + 1536 GPU1 / 0 host (hyb=0)
  • Decode: 42.0 tok/s

3. Dual GPU (RTX 5080 + RTX 4060 Ti) - Inkling-2-Mini-UD-Q4_K_XL.gguf

  • Experts placement: 1536 GPU0 + 1536 GPU1 / 0 host (hyb=0)
  • Decode: 86.5 tok/s

Limits

  • Focuses on GGUF format MoE expert tensors evaluated via ink_moe_cuda.cuh.
  • Quantization grid tables reside in constant cache / read-only device memory (~17 KB total footprint).

Test Checklist

  • Passed: Clean compilation with Ninja and CUDA 13.4 on sm_120 and sm_89.
  • Passed: Single GPU 100% VRAM residence verification (hyb=0, 3072/3072 experts on RTX 5080).
  • Passed: Dual GPU partitioned execution (1536 + 1536, hyb=0).
  • Passed: Decode generation and output coherence across IQ2_XXS, IQ2_XS, IQ2_S, IQ3_S, and NVFP4 down-projection layers.

@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 closed this Nov 24, 2026
@cobra91
cobra91 deleted the perf/inkling2-iq2-moe branch November 24, 2026 22:49
@cobra91
cobra91 restored the perf/inkling2-iq2-moe 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-iq2-moe branch from 81caabf to c234774 Compare November 26, 2026 14:00
@cobra91
cobra91 deleted the perf/inkling2-iq2-moe 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