license: apache-2.0
base_model:
- unsloth/Qwen4-35B-A3B-GGUF
base_model_relation: quantized
tags: - gguf
- llama.cpp
- qwen4
- moe
- abliterated
- uncensored
Qwen4-35B-A3B UD-Q4_K_XL abliterated (GGUF) + patched llama.cpp

🚀 Checkpoint 4 (2026-12-05): slightly faster, firmer, and the KV cache is now q8_0: no more q4_0 KV damage,
still 262k context on 8 GB. Prompt processing now reads only the cells Qwen4's indexer picks, straight from the
quantized cache (cp3 already did this for decode). That drops the f16 copy of the whole cache (512 MiB) and the dense
mask, and the room goes to q8_0 K/V and a larger batch. Same decode, same launch steps; the files are now named cp4
(the cp3 files are in this repo's history). If your GPU also drives a display and VRAM gets tight, lower$uBatch/UBATCHfirst.
| RTX 3070 Ti Laptop 8 GB | cp3 | cp4 |
|---|---|---|
| Context | 262,144 tokens | 262,144 tokens |
| KV cache | q4_0 | q8_0 |
| Perplexity, code (lower is better; a full q8_0 cache: 1.7614) | 1.7655 | 1.7620 |
| Prompt, 20.7k tokens | 955 t/s | 1,064 t/s |
| Prompt, 50k tokens | ~600-650 t/s | ~890-930 t/s |
| Prompt, 204k tokens | 824 t/s | |
| Decode (same day) | 35.4 t/s | 35.3 t/s |
| Linux, RTX 5070 12 GB: prompt, 20.7k tokens | 1,083 t/s | 1,473 t/s |
Unsloth's UD-Q4_K_XL of Qwen4-35B-A3B with OpenUncensored's refusal edit, and everything needed to serve it on an 8 GB
GPU with 32 GB of system RAM at 262,144 tokens of context: a prebuilt patched llama.cpp (llama-q4-cp4), launchers
and the Arrow chat template. Apache-2.0, like the original weights; who made which part:
Licenses and credits.
The model: Qwen4-35B-A3B-UD-Q4_K_XL-ablit-0000{1,2}-of-00002.gguf
Unsloth's UD-Q4_K_XL (two shards) with the 78 tensors of OpenUncensored's refusal edit replaced. Everything else is
Unsloth's file byte for byte: same header, same tensor types, same size (36.2 GB), same speed.
- The edit (directional ablation, from
OpenUncensored/Qwen4-35B-A3B-Uncensored,edit.safetensors):W' = W - 1.5 B Bᵀ Won the 2,048-wide output (residual) side, with B = 2 orthonormal
directions per tensor, layers 8-33. 78 tensors: the Gated DeltaNet outputssm_out(20), the attention outputattn_output(6), the shared-expertffn_down_shexp(26) and all 256 routed experts'ffn_down_exps(26). - How it was applied (the exact way): each of the 78 tensors was taken in BF16 from Unsloth's own BF16 GGUF, edited
in float64, and quantized again with ggml's quantizer to the type Unsloth gave that tensor (Q8_0, Q6_K or Q5_K),
with Unsloth's own imatrix (per expert for the routed experts). Only B and the strength came from the publisher, no
weights. - Why not dequantize, edit, requantize: measured on one expert tensor (layer 20, Q6_K), that shortcut adds 37% more
rounding error than Unsloth's own quantization (0.0245 vs 0.0178 relative), and keeps the edit 3x less precisely. - Checks:
- Before editing, the same recipe rebuilt Unsloth's unedited tensors: the 52 Q8_0 tensors byte for byte (so the BF16
source is the one Unsloth used), the 26 K-quant expert tensors to 97.7-99.9% of bytes at the same error (0.018053 vs
0.018051 on a Q6_K expert, 0.036164 vs 0.036155 on a Q5_K layer): near-tie rounding that differs between builds. - The written file: all 19.0 GB outside the 78 tensors identical to Unsloth's shard 1; shard 2 (the n-gram table)
identical to Unsloth's shard 2; the edit read back from the file within 2.4% along B.
- Before editing, the same recipe rebuilt Unsloth's unedited tensors: the 52 Q8_0 tensors byte for byte (so the BF16
- Behaviour: on 6 refusal-prone prompts (greedy, thinking off) the original refused 4, this file 0. Code answers
were unchanged. The publisher reports refusals 97 -> 2 (thinking off) and 99 -> 1 (thinking on) on 100 held-out
harmful requests, with MMLU and SQuAD 2.0 abstention unchanged. KL divergence was not measured here. The model
follows requests the original refuses; you are responsible for how you use it.
Shard 1 also carries Qwen4's MTP head (blk.40); the launchers leave MTP off (on 8 GB at this context it ran out of
VRAM on a 16k prefill).
llama-q4-cp4 vs stock llama.cpp
Prebuilt from upstream llama.cpp b12973 (59b716523f, the first release with Qwen4) plus local patches. Every patch is
switched by the launcher; off gives upstream behaviour. Measured on the setup below, each row an A/B of the same
build with that row's patches off and on:
| patches off | llama-q4-cp4 | |
|---|---|---|
| KV cache at 262k on 8 GB | q4_0 (q8_0 does not fit) | q8_0 |
| Decode, short context | 32.4 t/s | 37.2 t/s (two A/Bs chained) |
| Decode at a 93.6k context | 24.6 t/s | 33.3 t/s |
| Verbatim copy (ngram drafts) | 73.3 t/s | 170.0 t/s |
| Edit (copy with changes) | 67.6 t/s | 112.7 t/s |
| Prefill, 50k-token prompt | ~600-650 t/s (q4_0, ubatch 1,792) | ~890-930 t/s (q8_0, ubatch 3,328) |
| Prefill, 204k-token prompt | 824 t/s (q8_0) |
The four decode and copy rows were measured on cp3 with a q4_0 KV cache. cp4 changes prefill only: with q8_0 KV it
decodes the same as cp3 with q4_0 (README story test, same day: 35.3 vs 35.4 t/s; that day the machine ran ~5% below
the day of the table). Perplexity, code, 3 x 32k-token chunks (tokens 16k-32k scored): q4_0 KV 1.7655, cp4 (q8_0 KV,
q4_0 indexer keys) 1.7620, q8_0 KV dense 1.7614 (+-0.0118).
What the patches do:
| part | what |
|---|---|
| Work-stealing expert decode | The CPU experts' work is split into 64-row chunks over all threads instead of statically per expert, so the efficiency cores help instead of every layer waiting for the slowest core. CPU expert time 15.0 -> 12.5 ms/token. |
| Shorter CPU-GPU handoffs | Fused gate + up + SwiGLU on the CPU (input quantized once), the CPU step's GPU inputs read by one kernel, the expert-output upload not waited for until needed, one q8_1 quantize per matvec input. With work stealing: decode 32.4 -> 35.0 t/s. |
| Gearbox drafts + rollback | ngram drafts grow 24 -> 256 -> 512 tokens while accepted, and use the recurrent-state rollback, so a partly accepted draft no longer costs a checkpoint restore and a replay. Output identical. |
| Fused hc chain (cp1) | Scale, sigmoid, scale, hc post, RMS norm and mul in one CUDA kernel, which also writes the next matvec's q8_1 input. GPU kernels per token 2,137 -> 1,902. |
| Hot-expert cache (cp2) | 576 MiB of the busiest experts in VRAM: a miss is promoted only when its recent use beats the coldest slot, and the lookup runs inside the CPU step (no extra GPU step per layer). Decode 34.95 -> 37.2 t/s. |
| Cheaper rollback (cp2) | A rejected one-token draft step reads the DeltaNet inputs in place instead of gathering copies. Bit-identical. |
| Sparse attention in decode (cp3) | Qwen4's attention layers use an indexer that keeps 2,051 cells, but upstream decode on a quantized KV cache still scans every cell. cp3 gives the kernel only the picked cells; outputs equal the dense path within float32 rounding (max relative difference 5.9e-7 over 5,970 checks). Decode at 93.6k: 24.6 -> 33.3 t/s. |
| Sparse attention in prefill (cp4) | The same row lists for prompt processing, one per token: each query reads its picked cells straight from the quantized cache. Upstream prefill makes an f16 copy of the whole K and V cache (512 MiB at 262k) and a dense selection mask (0.5 MiB per ubatch token); both are gone, which is the room q8_0 K/V needs. Outputs differ from the dense path by float rounding only (the f16 tensor-core kernel vs the vec kernel decode always used); perplexity above. |
| Indexer key cache type (cp4) | The indexer's own key cache can take a type apart from -ctk; q4_0 saves 320 MiB at 262k against q8_0 keys. Perplexity 1.7615 -> 1.7620. |
| Chunked indexer scores, small-row gathers (cp4) | A prefill ubatch is scored 512 tokens at a time, so the score buffer is reused; gathers of 1-16-element rows run one thread per element. Same picks, same output bits; together they let ubatch 3,328 fit at 262k. |
Measured setup
RTX 3070 Ti Laptop (8 GB), 32 GB DDR5, i7-12700H (6 performance + 8 efficient cores). Context 262,144, q8_0 KV cache
(2.72 GB + 0.36 GB of q4_0 indexer keys), ubatch 3,328, flash attention, all 41 layers' experts in RAM (--n-cpu-moe 41,--load-mode none), the 10.7 GB n-gram table read from disk row by row (--lazy-mode auto, never in RAM), vision
projector on the CPU, 1 slot, 16 threads, temperature 1.0 / top-k 20 / top-p 0.95 (Qwen's thinking settings).
Chat template: Arrow for Qwen4
chat_template_sharp-v22.5.0-arrow4.2.2-qwen4.jinja is the Qwen4 port of
Arrow 4.2.2, an agent chat template that turns the
model's reasoning into action and keeps long tool runs on track (think cadence, status line, step back on repeated
failure, .arrow project memory; details on its page). Qwen4-specific:
- Renders Qwen4's own format: the native "Reasoning effort is set to X." line (Arrow's low / medium / xhigh map to
Qwen4's low / high / xhigh, thinking off to off), onetoolblock per result, compact<think>…</think>. - With Arrow's features off it renders byte-identical to the template in the GGUF.
- On routine tool steps the turn starts with thinking closed and the model acts; it thinks at decision points.
A real agent task, end to end: Hermes Agent's news curation (read two news files of 562 posts, pick 30-50 stories,
write and validate a web page), same build, same files, clean start each time:
| built-in template | Arrow 4.2.2-qwen4 | |
|---|---|---|
| Wall time | 46.5 min | 13.2 min |
| Generated tokens | 75,922 | 14,985 |
| Thinking | 208k characters (4 turns of 38-60k) | 7.5k characters |
| Result | 50 stories, every check passed | 48 stories; passed in the validator's tolerant mode (vocabulary diversity 66%, floor 68%) |
One run each. To use the GGUF's own template instead, swap the two $ChatTemplate lines in the launcher.
Requirements
- Windows x64:
llama-q4-cp4.tar.xz(CUDA 12.8 runtime included; NVIDIA driver 570+). - Linux x64:
llama-q4-cp4-linux.tar.xz(glibc 2.35+, e.g. Ubuntu 22.04+ / Debian 12+; NVIDIA driver 570+; CUDA
runtime included), with the launcherserver-Qwen4-35B-A3B-UD-Q4_K_XL-cp4.sh. - Both builds carry GPU code for RTX 30 (sm_86, + PTX), RTX 40 (sm_89) and RTX 50 (sm_120a), and portable CPU code
(AVX2 / FMA / F16C). Tested: the Windows build on an RTX 3070 Ti (RTX 30) and the Linux build on an RTX 5070 (RTX 50), each with
CUDA-vs-CPU op tests for the patched op families and its launcher end to end (tool call, a 20k-token prompt, a
long code copy); RTX 40 is compiled for but not tested. - 8 GB of VRAM and 32 GB of RAM for the launchers' settings. On a GPU that also drives a display, keep ~300 MiB of
VRAM free (Windows pages GPU memory below that): lower$uBatch/UBATCHfirst, or use q4_0 K/V. Prebuilt binaries only; the source of the local patches
is not published.
Run it
- Download every file in this repo into one folder.
- In that folder:
tar -xf llama-q4-cp4.tar.xz(createsllama-q4-cp4\). pwsh -File server-Qwen4-35B-A3B-UD-Q4_K_XL-cp4.ps1(llama-server on port 8080).$LlamaDirand$ModelDir
at the top of the launcher point elsewhere if you keep the files apart. Set$Threadsto about your CPU's core
count (16 is for the i7-12700H).
Linux: tar -xf llama-q4-cp4-linux.tar.xz -C ~, put the .gguf files, the .jinja template and the .sh launcher in
one folder, then ./server-Qwen4-35B-A3B-UD-Q4_K_XL-cp4.sh. LLAMA_DIR, MODEL_DIR and PORT override the
defaults.
Files
| file | bytes | sha256 |
|---|---|---|
| Qwen4-35B-A3B-UD-Q4_K_XL-ablit-00001-of-00002.gguf (the model, shard 1: 78 edited tensors, the rest Unsloth's bytes) | 24,719,106,144 | 9185f9a8b7287fb7dee6b680029ac1fcf91bfef9519ad51809663629011b5477 |
| Qwen4-35B-A3B-UD-Q4_K_XL-ablit-00002-of-00002.gguf (the model, shard 2: the n-gram table, identical to Unsloth's shard 2) | 11,520,258,240 | 419b93856e79a6f2338160d98d3b6b75042c57786af92c3010405b7b808dc4b4 |
| mmproj-Q8_0.gguf (vision projector, Q8_0, the launchers' default) | 610,655,360 | d1f2c665b7e77c14ccb1b9ae96671bd1d32e6a51023a06a4a899164184f5534d |
| mmproj-F16.gguf (vision projector, unchanged from Unsloth) | 899,283,200 | 3805de49141d2695d7d399ec67766b9f9d9b5f7b00050c1f3e78b3793be77ac6 |
| chat_template_sharp-v22.5.0-arrow4.2.2-qwen4.jinja (Arrow 4.2.2 for Qwen4, the launchers' chat template) | 98,598 | a4a9daeaa4b917a05ddc33e67ecc7cb2b53b6ad625c03566cdd7c915b84438f0 |
| llama-q4-cp4.tar.xz (prebuilt llama-q4-cp4, Windows x64) | 559,304,644 | 1707f79f714ed3457ad396baa8fcdf234ebee2a5e7dc90c0bf51a70e40efc4e6 |
| server-Qwen4-35B-A3B-UD-Q4_K_XL-cp4.ps1 (Windows launcher) | 15,768 | 4037ad8ecfa8bf4f5854e1670b36cbc846523ad6d1aa7151976005a4f0c88ce2 |
| llama-q4-cp4-linux.tar.xz (prebuilt llama-q4-cp4, Linux x64) | 571,719,492 | f57141ff41239789400aa3f9c339e72b1183f764988d947259466dbe2c277e14 |
| server-Qwen4-35B-A3B-UD-Q4_K_XL-cp4.sh (Linux launcher) | 5,044 | 4f46f93992c4962a22accdf9e87b459a783f82b0601aa38c95eb6c75a93b8c01 |
| qwen4_banner.png (the image at the top of this card) | 649,951 | ee5ae72e638e7d2da796fc969419311ed188857b8c7926c244daa8695ea8f22d |
Licenses and credits
The repository is released under Apache-2.0, the license of the original weights.
| part | by | license |
|---|---|---|
| Qwen4-35B-A3B weights | Qwen | Apache-2.0 |
UD-Q4_K_XL GGUF this file starts from (all but 78 tensors, unchanged), its imatrix and BF16 GGUF (used to rebuild the 78), mmproj-F16.gguf |
Unsloth | Apache-2.0 |
| Refusal-edit directions and strengths | OpenUncensored | Apache-2.0 |
| Chat template upstreams (Arrow builds on them) | froggeric, peculiar-ragdoll | Apache-2.0 |
| llama.cpp / ggml (upstream b12973), inside the prebuilt build | the ggml authors | MIT (notice below) |
CUDA 12.8 runtime libraries in the build archives (cudart, cublas, cublasLt) |
NVIDIA | redistributed under the CUDA Toolkit EULA |
The 78 edited tensors (edit applied to the BF16 weights, re-quantized), mmproj-Q8_0.gguf; local llama.cpp patches (binaries only); launchers; Arrow and its Qwen4 port |
gbuzhf | Apache-2.0 |
llama.cpp / ggml license notice (applies to the prebuilt build):
MIT License
Copyright (c) 2023-2026 The ggml authors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.