Skip to content

q4x v0.1.0

Latest

Choose a tag to compare

@lxe lxe released this 04 Dec 19:21

q4x v0.1.0 — Native Rust + CUDA Inference for Qwen4-35B-A3B

First public release of q4x, a native Rust + CUDA (sm_86+) inference engine built for Qwen/Qwen4-35B-A3B on dual asymmetric consumer GPUs (reference target: 2× RTX 3090, PCIe 4.0 x16 + PCIe 3.0 x4 PCH, no NVLink/P2P, 128 GB RAM).

Highlights

  • 3.2K–3.45K tok/s Flat Prefill (2K → 16K ctx) at Full 1M NVFP4 Context:
    • 2,048-token chunked prefill with aliased GPU _work_arena scratch (23.8 / 24.6 GiB GPU0 at --ctx 1048576 --kv-mode nvfp4).
    • gdn_keyhead_f16 (2 V-heads/CTA, double-buffered 16B cp.async, 4-way split FMAs, 2 syncs/token — 3.1× faster GDN prefill).
    • moe_trellis_inner_mma_prefill_mul1 (N=64, M=64 smem-staged No-Split-K EXL3 Trellis FP16 Tensor Core MMA + grid.z=4 hot-expert M-splitting — 2.45×–2.81× faster MoE prefill).
    • qsa_attn_prefill_mma & qsa_attn_sparse_prefill_mma with warp-coalesced uint32_t NVFP4 loads + branchless pure-ALU E2M1 → IEEE-754 FP16 conversion (zero constant-cache serialization, fused Q-sigmoid gate, zero part_o — 4.2× faster dense QSA, 1.64× faster sparse QSA).
    • Block-32 Q8_0 PCIe 3.0 x4 prefill exchange (8.0 → 4.25 MB, halving GPU1 PCIe transfer time).
  • 236–262 tok/s Speculative Decode & Flat 6K Context Speed:
    • Lock-free cuStreamWaitValue32_v2 asymmetric ExpertSplit handoff (0.09 ms GPU1 wait on decode) + Dual-GPU CUDA Graphs (M=1..=8, both greedy and non-greedy via GPU sampler_topk_p1/p2).
    • SM86 Tensor Core mma.sync.m16n8k16 split-KV QSA (341 → 107 µs/layer) and FP16 DFlash2 block attention (242 → 67 µs/layer), plus FP16 DFlash2 prefix-cache ring snapshot/restore.
    • Native RadixArk DFlash2-Q8 (40K draft head), zero-cost prompt-lookup, and native MTP drafters with exact lossless verification & O(1) rollback.
  • Accuracy Beyond UD-Q6_K_XL in 24.5 GB VRAM:
    • qwen4-best.q4x (5.2 bpw EXL3 mul1 Trellis + Q8_0 dense + lossless BF16 Tier-0 + host-RAM PLE): 0.0194 KL / 95.9% top-1 vs exact BF16 teacher (16/16 golden parity).
  • Drop-In Server & WebUI:
    • OpenAI (/v1/chat/completions, /v1/responses), Anthropic (/v1/messages with thinking + tool_use), incremental live-streaming <tool_call> JSON deltas, multi-session hybrid prefix cache, and embedded llama.cpp WebUI (/).

Verified Benchmarks (2× RTX 3090, --ctx 1048576 --kv-mode nvfp4 --gpu0-expert-frac 0.48)

Workload Prefill Decode
q4x bench (pp512 / 2K / 4K / 8K / 16K, DFlash2-Q8) 1,968 / 3,203 / 3,244 / 3,242 / 3,203 tok/s 208–262 tok/s
Raw M=1 Decode (--spec none, pp2 / expert-split) — 136.7 / 127.7 tok/s
Live API — Short Python (pt=37, T=0.0) — 235.9 tok/s
Live API — 1.7K Context (pt=1,692, T=0.0) 3,454.1 tok/s 169.8 tok/s
Live API — 6K Sparse (pt=5,750, T=0.0 / T=1.0 thinking) 3,232.6 / 3,192.1 tok/s 141.2 / 126.3 tok/s
Live API — 11.5K Sparse Needle (pt=11,458, T=0.0) 3,146.1 tok/s 117.9 tok/s

Pre-Built Assets & Weights

  • Prebuilt Linux x86_64 CUDA sm_86 (RTX 3090 / Ampere) binaries: q4x-v0.1.0-linux-x86_64-cuda-sm86.tar.gz (q4x + q4x-verify, dynamically loads CUDA driver / cuBLAS at runtime; requires NVIDIA driver + CUDA 12/13 runtime libs).
  • Pre-Quantized Checkpoints: lxe/Qwen4-35B-A3B-q4x (qwen4-35b-a3b-amalgam.q4x 67.9 GB BF16 PLE for 128 GB+ RAM, qwen4-35b-a3b-amalgam-pleq8.q4x 48.7 GB Q8_0 PLE for 64 GB RAM, or modular weights).