Skip to content

candle-core: add IQ4_XS (GGUF type 23) quantized dtype support - #3462

Open
latentcollapse wants to merge 7 commits into
huggingface:mainfrom
latentcollapse:feat/vram-budget-iq-star
Open

latentcollapse wants to merge 7 commits into
huggingface:mainfrom
latentcollapse:feat/vram-budget-iq-star

Conversation

@latentcollapse

@latentcollapse latentcollapse commented Apr 12, 2026 •

Copy link
Copy Markdown

Summary

Adds support for the IQ4_XS (GGUF type 23) quantized dtype across the Candle stack.

  • GgmlDType::IQ4_XS variant + BlockIQ4XS struct with GgmlType impl
  • Wire into QMatMul::forward via CPU dequant path (no Metal/CUDA GPU kernel exists upstream for this type; routes to dequantize_f16 + matmul on CPU)
  • Metal matmul dispatch: IQ4_XS returns an explicit error rather than silently routing to the wrong kernel
  • Removed two non-upstream-safe dtype additions from a prior WIP commit:
    • Q1_0_g128 (GGUF type 41): PrismML/Bonsai proprietary format — does not belong upstream
    • I2S (GGUF type 36): was mapped to IQ4_NL_4_4, which has been removed from the gguf spec

Note: This PR is based on top of #3461 (quantized Qwen3.5 support). The first commit in this branch (07c07d49) is the Qwen3.5 model; the IQ4_XS changes begin at the second commit. Please review/merge #3461 first and then rebase this branch — or I can rebase after #3461 lands.

Test plan

  • cargo check -p candle-core passes
  • cargo check -p candle-transformers passes
  • cargo test -p candle-core iq4_xs_dequant_and_matmul_fallback passes
  • IQ4_XS QTensor round-trip test passes
  • QMatMul::forward with IQ4_XS correctly routes to CPU dequant path
  • cargo check -p candle-metal-kernels skipped locally (Linux)

Matt and others added 5 commits April 11, 2026 14:56
Adds quantized_qwen35.rs implementing Qwen3.5 hybrid Gated DeltaNet SSM plus full-attention architecture for GGUF inference.

Fixes eight correctness bugs from the initial implementation that caused coherent but factually wrong output, including larger-variant SSM value-head repeat ordering.

Validated on Qwen3.5-0.8B-BF16, Qwen3.5-2B-Q8, and Qwen3.5-9B-Q4_K_M GGUFs. All three probes (raw factual, chat arithmetic, chat greeting) return correct output with greedy decoding.
- quantized_qwen35: add from_gguf_with_layer_limit for CPU/GPU split loading
  - set_device() helper to switch target device mid-load
  - keep_embeddings_on_device flag for embedding placement control
  - layer-by-layer device assignment up to max_device_layers
- candle-core/quantized: IQ* dtype registration groundwork (ggml_file, mod, k_quants, cuda, metal)
- candle-core/tests: quantized dtype coverage additions
- candle-nn/kv_cache: supporting changes for budget-aware inference path

Validated: Qwen3.5-9B-Q4_K_M loads cleanly at --vram-budget 6GB on RTX 5060 (8GB)
32 GPU layers, embeddings on CPU. Paris/2+2/hello all correct.

Co-Authored-By: Codex <noreply@openai.com>
…2S routing

Q1_0_g128 (GGUF dtype 41) is a PrismML/Bonsai-specific format from a
private llama.cpp fork. It does not belong in upstream Candle.

Metal GPU matmul for I2S and IQ4_XS now returns an explicit error instead
of silently routing to kernel_mul_mv_f32_f32 (which would produce garbage).
Both types are handled correctly via QMatMul::forward CPU dequant path.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
GGML_TYPE_IQ4_NL_4_4 (type 36) was removed from gguf files upstream.
BlockI2S was mapped to this tombstoned type and its implementation did
not match the actual IQ2_S format (type 22). No real GGUF file will
contain type-36 tensors.

D-166 PR scope is now: IQ4_XS (type 23) dtype support + CUDA CPU-fallback
dequant for unsupported types.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@latentcollapse
latentcollapse marked this pull request as ready for review April 19, 2026 01:20

This branch has not been deployed

No deployments
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