license: apache-2.0
base_model: Qwen/Qwen4-35B-A3B
library_name: gguf
pipeline_tag: image-text-to-text
language:
- en
- pt
- es
tags: - gguf
- llama.cpp
- qwen4
- moe
- mtp
- speculative-decoding
- long-context
- imatrix
- uncensored
- refusal-direction
- rtx-3090
- 24gb

Qwen4-35B-A3B Uncensored GGUF (Q4X-r4, one RTX 3090)
This is an uncensored build of Qwen/Qwen4-35B-A3B for llama.cpp. The weights, the MTP head, 262,144 tokens of context and the KV cache all fit on one 24 GB RTX 3090.
This is an independent community quantization. It is not an official Qwen release, and the Qwen team has not reviewed or endorsed it. The aligned sibling is matheusbgodoi/Qwen4-35B-A3B-Q4X-GGUF.
- What it is. A rank-1 directional edit along the refusal direction (Arditi et al., 2024), merged into the BF16 weights at λ = 2.0. At this λ each edited writer's output component along the refusal direction is negated (reflected), not just removed; λ = 1 would be a pure projection (abliteration). The result was then quantized with the same per-tensor recipe and imatrix as the sibling Q4X-r4 build. Tensor names and shapes are unchanged, and nothing was fine-tuned.
- Who it is for.
- People running local llama.cpp on a single 24 GB card (RTX 3090/4090 class) who want 256K context, vision and MTP speculative decoding in VRAM (the profile sits right at the Windows shared-memory spill threshold; see Notes).
- Users who accept responsibility for an assistant that answers requests the original model refuses.
- Headline numbers. All figures are this file, RTX 3090 at 350 W, WSL2, llama.cpp b12973 + CUDA 13.3, desktop attached.
| Value | Source | |
|---|---|---|
| Decode, 1024-token outputs, 8 requests, MTP n=1 + ngram-mod | median 114.2 / mean 130.2 tok/s | hf-release/, 2026-12-04 |
| Same, no drafts | median 99.5 / mean 99.2 tok/s | hf-release/ |
| Held-out harmful prompts refused, thinking off (78), marker / self-judge | 4 / 6 (base: 78 / 78) | uncensor/ |
| Held-out harmful prompts refused, thinking high (26), marker / self-judge | 2 / 1 (base: 26 / 26) | uncensor/ |
| Benign prompts refused (54) | 0 (base: 0) | uncensor/ |
| Mean KLD vs near-BF16 reference* | 0.092804 (base quant: 0.075107) | uncensor/kld-summary.txt |
| Needle-in-a-haystack, 5 positions | 5/5 at 101K, 132K and 254K tokens | final/, hf-release/, uncensor/runtime/ |
| VRAM at load, 262,144 ctx + MTP | 23,704 MiB of 24,576 MiB | hf-release/loads.txt |
* The reference has routed experts at Q8_0, every other tensor at BF16 and the engram table at Q8_0. See Quality.
Safety: read before you run it
- Refusals are mostly gone. The model will give detailed answers about fraud, intrusion, weapons-adjacent chemistry and similar topics that the original refuses. Whatever you do with those answers is your responsibility. You must also comply with the Apache-2.0 license, the base model's terms and your local law.
- Prompt injection is more dangerous. Lower refusal also means lower resistance to instructions injected through web pages, documents, e-mails and tool results. An agent built on this model is more likely to follow a malicious instruction hidden in untrusted content.
- Do not give it write-capable tools (shell, file writes, e-mail, payments, git push) over untrusted input without a human approving each action.
- Run it in a sandbox, with least-privilege tool scopes.
- Keep it off the public Internet.
- Bind
llama-serverto127.0.0.1, or to a private network such as a VPN or tailnet. - Put an API key in front of it.
- Never expose an unauthenticated endpoint. The commands below have no key; add
--api-key "$LLAMA_API_KEY"(from an environment variable, never inline).
- Bind
- Not for public-facing or unsupervised deployment. Keep a human in the loop.
- It does not refuse in every language the same way. Spanish keeps proportionally more refusals: 2 of 10 ES prompts against 2 of 52 EN with thinking off (refusal marker), while pt-BR was answered 16/16 by the marker (see Refusal results). Do not rely on residual refusals as a safety layer, and do not rely on this model to protect minors or vulnerable users.
- You want the aligned behaviour? Use the censored sibling. It is built with the identical recipe and imatrix from the unedited BF16 weights.
Files
| File | Bytes | GB (10⁹) | sha256 | Purpose |
|---|---|---|---|---|
Qwen4-35B-A3B-Q4X-r4-uncensored.gguf |
19,173,163,328 | 19.17 | 3df5d32c6ccb426d964a136e73605c75f5e884ae1ecbb6f88fadf4b82c6b6035 |
Main weights (Q4X-r4 recipe, uncensored). Includes the MTP head (blk.40). Goes on the GPU. |
Qwen4-35B-A3B-engram-Q8_0.gguf |
21,760,487,616 | 21.76 | 0d6fdae2bf06db3dc0275cc307f147b2b4f74d0c1406f22713a6ee45ce4e31ec |
Per-layer n-gram "engram" table, loaded with --ple and kept in system RAM (lazy mmap). Byte-identical to Unsloth's engram/Qwen4-35B-A3B-engram-Q8_0.gguf_file (same size and LFS sha256 on the HF API, checked 2026-12-04). |
Qwen4-35B-A3B-mmproj-F16.gguf |
899,283,200 | 0.90 | 3805de49141d2695d7d399ec67766b9f9d9b5f7b00050c1f3e78b3793be77ac6 |
Vision projector, run on the CPU. Byte-identical to Unsloth's mmproj-F16.gguf (same size and LFS sha256 on the HF API, checked 2026-12-04). |
recipe-r4-tensor-types.txt |
– | – | cda2d33ac4d215029c0b9792ab425a5bf0ba93ecc9382a83859bb3e4fbcc361a |
llama-quantize --tensor-type-file recipe. |
lora/qwen4-35b-a3b-refusal-rank1-w16.gguf |
107,286,592 | 0.11 | 8f2e5a6cbb6d877664b512a62180fb2706adaa8dcd8f9da6cd65391d74c22c34 |
Rank-1 llama.cpp LoRA (the edit). The adapter scale equals λ. |
lora/qwen4-35b-a3b-refusal-rank1-w16.manifest.json |
– | – | ee698bf4fd3728dbb6f0f4e26812ed71553b93af6d7d4d8eb2a1752727b3130b |
Generator, direction expression, module list, self-check and the deployed_merge block. |
lora/qwen4-35b-a3b-refusal-direction-w16.safetensors |
– | – | 6b493b8edfa92fa8f88a8aa0b7021c50a93bda0befc319956cb9afa126ebc726 |
The per-layer unit directions that were used. |
lora/qwen4-35b-a3b-refusal-dirs-all-layers.safetensors |
– | – | 1da3beb88e93f45ce0f59907c71342531cda3d77ec7e64601e264ff5c6ab23bd |
Difference-of-means directions for every layer, mode and position. |
lora/merge-report.json |
– | – | 69c5001f6649af0557c23eecacb08dc3c0bf003a252d3a4ebdc35a847d6ab2ab |
Per-module post-merge check. |
lora/peft/ |
– | – | see SHA256SUMS |
HF PEFT export of the same edit, with λ folded into lora_B (apply at scale 1). It was prepared but not tested in transformers. |
SHA256SUMS |
– | – | – | Full hashes of every file above. They were re-verified with sha256sum -c on 2026-12-04 (hf-release/sha256-uncensored.txt: all OK). |
Download (hf CLI from huggingface_hub):
# Everything needed to run (about 41.8 GB)
hf download matheusbgodoi/Qwen4-35B-A3B-Uncensored-GGUF \
--include "Qwen4-35B-A3B-Q4X-r4-uncensored.gguf" "Qwen4-35B-A3B-engram-Q8_0.gguf" \
"Qwen4-35B-A3B-mmproj-F16.gguf" "SHA256SUMS" \
--local-dir ./qwen4-unc
# Only the LoRA, for applying it to the censored base file
hf download matheusbgodoi/Qwen4-35B-A3B-Uncensored-GGUF --include "lora/*" --local-dir ./qwen4-unc
You need both the main GGUF and the engram table, because the model does not load without --ple. If you already have the engram table from the censored sibling or from Unsloth, it is the same file.
Quick start
Requirements:
- llama.cpp b12973 or newer. The build must support Qwen4 (GGUF architecture
qwen4exp),--ple(engram table) and--spec-type draft-mtp/ngram-mod. The tested build is b12973, commit59b716523, built for sm_86 with CUDA 13.3. - System RAM. The 21.8 GB engram table is memory-mapped lazily. The test machine gave WSL2 a 24 GB VM.
Production command (MTP n=1 + ngram-mod, 262,144 context, vision)
Same flags and values as the production config, minus --alias, with local file names and port 8080:
llama-server \
-m Qwen4-35B-A3B-Q4X-r4-uncensored.gguf \
--ple Qwen4-35B-A3B-engram-Q8_0.gguf -ot per_layer_token_embd=CPU \
--mmproj Qwen4-35B-A3B-mmproj-F16.gguf --no-mmproj-offload \
--host 127.0.0.1 --port 8080 \
-ngl 999 -fit off -fa on -c 262144 -np 1 -ctk q8_0 -ctv q8_0 -b 2048 -ub 256 \
--spec-type draft-mtp,ngram-mod --spec-draft-n-max 1 --spec-draft-n-ubatch 64 \
--jinja -t 8 --cache-ram 4096 --metrics \
--temp 1.0 --top-p 0.95 --top-k 20 --min-p 0.0
No-MTP variant
This variant uses 1,318 MiB less VRAM and is slower. It is the production command with only the --spec-* line removed.
llama-server \
-m Qwen4-35B-A3B-Q4X-r4-uncensored.gguf \
--ple Qwen4-35B-A3B-engram-Q8_0.gguf -ot per_layer_token_embd=CPU \
--mmproj Qwen4-35B-A3B-mmproj-F16.gguf --no-mmproj-offload \
--host 127.0.0.1 --port 8080 \
-ngl 999 -fit off -fa on -c 262144 -np 1 -ctk q8_0 -ctv q8_0 -b 2048 -ub 256 \
--jinja -t 8 --cache-ram 4096 --metrics \
--temp 1.0 --top-p 0.95 --top-k 20 --min-p 0.0
The release bench ran both variants in the same session with these flags minus --metrics and the server-side sampler defaults (each request sets its own samplers, see the table below).
VRAM at load: 22,386 MiB without drafts, against 23,704 MiB with MTP + ngram-mod (hf-release/loads.txt).
Notes
VRAM budget at 262,144 ctx + MTP. These are buffer sizes from the stage-1 -lv 4 load log, at the same flags (quant/fit-r4-summary.txt):
| Buffer | MiB |
|---|---|
| Model weights on GPU | 17,941 |
| KV cache, q8_0 | 2,720 |
| Indexer K cache | 680 |
| Recurrent (SSM) state | 68 |
Main compute (-ub 256) |
812 |
| MTP draft KV (f16, 512 + 128) | 640 |
MTP draft compute (--spec-draft-n-ubatch 64) |
179 |
h_nextn |
64 |
| Sum of buffers | 23,105 |
| nvidia-smi used at load (stage 1; nvidia-smi showed 266 MiB used before this load) | 23,765 / 24,576 |
The buffer settings were chosen for these reasons:
-ub 256. At-ub 512, main compute grows to 1,072 MiB. The stage-2 measurement was 23,919 MiB loaded, a spill, with median decode 102.2 against 110.4 tok/s. Larger ubatches nearly double prefill (see the raw pp/tg table), but they only fit at smaller contexts.--spec-draft-n-ubatch 64. This keeps the MTP draft compute at 179 MiB. Do not add-ctkd q8_0: the draft compute then rises to 802 MiB.- mmproj on the CPU (
--no-mmproj-offload). On the GPU the 0.9 GB projector pushes the 256K profile to 24,129 MiB at load. That spills, and median decode drops to 94.4 against 110.4 tok/s. Running the projector on the CPU costs only image-prefill latency: 1.64 s for a small test image in stage 2. -fit off. With-ngl 999, fit aborts anyway. Without-ngl, fit silently shrinks the configuration.- Windows shared-memory spill. On Windows and WSL2 the NVIDIA driver does not return an out-of-memory error. Past roughly 23,750 MiB used (nvidia-smi, desktop attached; an approximate stage-2 threshold, not a hard limit), it silently pages into shared system memory. Median decode dropped 7.4-16.6% in the three spilled stage-2 configs (256-token outputs).
- Measured: 327,680 ctx gave median 92.1 tok/s, mmproj on the GPU 94.4 tok/s and
-ub 512102.2 tok/s, against 110.4 tok/s for the shipped profile. - The shipped profile sits at or slightly above that threshold: 23,765 MiB at load in stage 1, 23,704 loaded / 23,792 after decode in the release bench, and 23,780 MiB after a cold reboot. Its decode stayed in line with the other sessions, but the shared-memory trace (
runtime/gpu-shared-trace.txt) was only recorded in stage 2, not for the release-bench or post-reboot runs. - On a headless Linux box you have more headroom. On a desktop with more VRAM in use (browser, wallpaper engines, RGB tools), you have less.
- Measured: 327,680 ctx gave median 92.1 tok/s, mmproj on the GPU 94.4 tok/s and
- Reasoning.
reasoning_effortacceptsoff,low,highandxhigh.mediumreturns HTTP 400 ("not supported by the chat template, supported levels: low, high, xhigh").- If a client sends
medium, map it tohighin your proxy (the author's gateway also mapsminimal→low,none→off,max→xhigh).
- Recommended samplers (per request):
| Mode | temperature | top_p | top_k | min_p | presence_penalty |
|---|---|---|---|---|---|
Thinking on (low/high/xhigh) |
1.0 | 0.95 | 20 | 0.0 | – |
| Thinking off | 0.7 | 0.8 | 20 | – | 1.5 |
- Loops. The 15-minute stress test (14 × up to 8,192 tokens, thinking on, base file, stage 2) passed 13/14 with no tail loops. The one flagged
min_p 0case was a repeated list item (max 8-gram repeat of 9 in a list answer), not a tail loop.min_p 0.05is a harmless guard if you see repetition. - Prompt cache.
--cache-ram 4096(MiB) is too small to keep a full 256K prompt state, which was 4,209 MiB in the log. Raise it if you switch between several huge documents and have the RAM.
Quantization recipe (Q4X-r4)
Source: Qwen/Qwen4-35B-A3B safetensors, converted with convert_hf_to_gguf.py --outtype bf16 --no-ple. The output is a 71,850,070,400 B BF16 GGUF with the MTP block and without the engram. For this repo, the refusal LoRA was merged into a copy of that BF16 GGUF (see Uncensoring) before quantizing.
| Tensor group | Type |
|---|---|
Routed experts gate/up (ffn_gate_exps, ffn_up_exps), layers 0-14 |
IQ3_S |
| Routed experts gate/up, layers 15-39 | IQ4_XS |
Routed experts down (ffn_down_exps), layers 0-39 |
IQ4_XS |
MTP block experts (blk.40.ffn_{gate,up,down}_exps) |
IQ4_XS |
MTP block shared experts, attention, hc_*, nextn.{eh_proj,hc_head_up,hc_head_down} |
Q5_K |
Attention q/k/v/output (blk.N.attn_*) |
Q8_0 |
Attention QKV gate (attn_qkv_gate) |
Q5_K |
SSM output (ssm_out) |
Q8_0 |
SSM beta/alpha (ssm_beta_alpha) |
BF16 |
Shared experts (ffn_{gate,up,down}_shexp) |
Q8_0 |
Hyper-connection down-inject (hc_{attn,ffn}_down_inject) |
Q8_0 |
Hyper-connection up (hc_{attn,ffn}_up) |
Q6_K |
Output hyper-connection (output_hc_{up,down}) |
Q8_0 |
Routers (ffn_gate_inp*) |
F32 (llama-quantize default) |
Indexer, engram key/value projections (ple_key, ple_value) |
BF16 |
Engram table (separate file, per_layer_token_embd) |
Q8_0 (Unsloth) |
output.weight / token_embd.weight |
Q5_K / Q5_K |
- Non-expert tensors. These mirror Unsloth's UD-IQ4_XS, except
ssm_beta_alpha, which is BF16 following ggml-org's advice (about +4 MB). - The bits went to experts. The bit budget was spent on the experts so that the weights stay at 17,941 MiB on the GPU.
- imatrix. Unsloth's
imatrix_unsloth.gguf_filefrom unsloth/Qwen4-35B-A3B-GGUF, 389,173,984 B, renamed toimatrix_unsloth.ggufbefore use:
hf download unsloth/Qwen4-35B-A3B-GGUF imatrix_unsloth.gguf_file --local-dir .
mv imatrix_unsloth.gguf_file imatrix_unsloth.gguf
- Command. This is the exact command, run on both the base BF16 and the merged BF16:
llama-quantize --imatrix imatrix_unsloth.gguf \
--tensor-type-file recipe-r4-tensor-types.txt \
--token-embedding-type q5_K --output-tensor-type q5_K \
Qwen4-35B-A3B-BF16[-uncensored-l2].gguf Qwen4-35B-A3B-Q4X-r4[-uncensored].gguf IQ4_XS 8
recipe-r4-tensor-types.txt (in this repo):
blk\.40\.ffn_(gate|up|down)_exps=iq4_xs
blk\.40\.(ffn_(gate|up|down)_shexp|attn_(q|k|v|output)|hc_|nextn\.(eh_proj|hc_head_up|hc_head_down))=q5_K
blk\.([0-9]|1[0-4])\.ffn_(gate|up)_exps=iq3_s
blk\.(1[5-9]|[23][0-9])\.ffn_(gate|up)_exps=iq4_xs
blk\.([0-9]|[1-3][0-9])\.ffn_down_exps=iq4_xs
ssm_out=q8_0
attn_qkv_gate=q5_K
blk\.[0-9]+\.attn_(q|k|v|output)\.=q8_0
ffn_(gate|up|down)_shexp=q8_0
hc_(attn|ffn)_down_inject=q8_0
hc_(attn|ffn)_up=q6_K
output_hc_(up|down)=q8_0
ssm_beta_alpha=bf16
ple_(key|value)=bf16
Quality (KLD vs near-BF16 reference)
Reference. The reference is ref-Q8exps-BF16rest: routed experts at Q8_0, every other tensor at BF16, engram table at Q8_0. It is not a pure BF16 model. Plain Q8_0 was avoided because ggml-org reports KLD 0.036 for plain Q8_0 against BF16 on this model. Mean PPL(base) in the KLD logs is 5.589984; the reference's standalone llama-perplexity run reported 5.6024 ± 0.14696.
Corpus. kld-corpus-en-ptbr-code.txt, interleaved thirds of English (wikitext-2 test), pt-BR Wikipedia and code (llama.cpp C++/Python). It was scored as 40 chunks × 512 tokens with llama-perplexity --kl-divergence.
Method check. The UD-Q4_K_XL / UD-IQ4_XS KLD ratio here is 0.681, against 0.705 in Unsloth's own BF16 numbers. The ordering is reproduced. The absolute values are higher because the reference and the corpus differ.
Quant candidates (stage 1, quant/kld-*.log)
The r1, r2 and r4 rows used the IQ4_NL engram table. The Unsloth rows used the engram bundled in their own split files.
| Quant | File 1 bytes | GPU weights MiB | Mean KLD | Median KLD | 99th pct KLD | Same top-1 | PPL | 256K + MTP on 24 GB |
|---|---|---|---|---|---|---|---|---|
| Unsloth UD-Q4_K_XL | 24,719,106,144 | ~22,700 | 0.043205 | 0.010563 | 0.519258 | 92.578% | 5.588454 | no |
| Unsloth UD-IQ4_XS | 20,516,282,464 | 19,222 | 0.063406 | 0.015749 | 0.832146 | 91.029% | 5.593576 | no: it spills with MTP; without MTP it fits at 23,517 MiB |
| r1 (rejected) | 19,186,180,384 | 17,953 | 0.084126 | 0.022020 | 1.039960 | 89.784% | 5.663145 | yes (measured) |
| r2 (rejected) | 19,211,346,208 | ~17,977 | 0.102391 | 0.026302 | 1.280878 | 88.608% | 5.800448 | yes (by size) |
| r4 (sibling base file) | 19,173,163,296 | 17,941 | 0.077416 | 0.020511 | 0.933416 | 90.157% | 5.583513 | yes (measured) |
- r1: gate/up IQ3_S on layers 0-21 and IQ4_XS on 22-39; down IQ4_XS on 0-15 and Q4_K on 16-39; MTP Q5_K; output Q6_K.
- r2: gate/up IQ3_S on every layer; down Q4_K on 0-13 and Q5_K on 14-39.
- What the comparison shows. On this model, gate/up are more sensitive than down. Moving bits from gate/up to down (r2) was clearly worse.
Engram table precision (measured on r1, same reference): Q8_0 gives 0.081239 mean KLD / 90.245% top-1, against 0.084126 / 89.784% with IQ4_NL (−3.4% KLD). Decode speed is equal within noise in stage 2, so this repo ships Q8_0.
This file vs the base quant (stage 5, same reference and corpus, Q8_0 engram for both)
| Model | Mean KLD | Median KLD | 99th pct KLD | Same top-1 | PPL |
|---|---|---|---|---|---|
| Base Q4X-r4 (censored sibling) | 0.075107 | 0.020243 | 0.927075 | 90.088% | 5.621969 |
| Uncensored λ 1.75 (rejected) | 0.088175 | 0.025427 | 0.995994 | 89.392% | 5.657356 |
| Uncensored λ 2.0 (this file) | 0.092804 | 0.026472 | 1.000087 | 89.451% | 5.675644 |
- Cost of the edit. It adds +0.017697 mean KLD and −0.637 pp top-1 over the base quant, and PPL rises by 0.053675. That cost is smaller than the base quant's own cost against the reference.
- Why the base number differs from the table above. The base is 0.075107 here and 0.077416 in the stage-1 table. Stage 1 scored r4 with the IQ4_NL engram table, and stage 5 with the Q8_0 table this repo ships.
Speed
All speed numbers come from the same machine: RTX 3090 24 GB at a 350 W power limit, WSL2, llama.cpp b12973 + CUDA 13.3, desktop attached. Decode is tokens per second from llama-server's own timings. "MTP" means --spec-type draft-mtp,ngram-mod --spec-draft-n-max 1 unless stated otherwise.
Per task, this file (today's release bench, hf-release/decode.csv)
These are 1024-token outputs at 262,144 ctx with the production flags. Each row is one request.
| Task | Thinking | MTP n=1 + ngram-mod tok/s | Draft acceptance | No drafts tok/s |
|---|---|---|---|---|
| Code (write) | off | 120.76 | 0.887 | 96.84 |
| EN prose | off | 106.58 | 0.597 | 96.91 |
| pt-BR chat | off | 114.38 | 0.738 | 97.66 |
| Code edit (1,668-token prompt) | off | 244.15 | 0.787 | 94.02 |
| Code (write) | on | 120.64 | 0.678 | 102.43 |
| EN prose | on | 109.27 | 0.553 | 102.29 |
| pt-BR chat | on | 112.03 | 0.650 | 102.21 |
| Code edit | on | 114.04 | 0.726 | 101.26 |
| Median / mean of 8 | 114.2 / 130.2 | 99.5 / 99.2 |
- MTP + ngram-mod gives 1.148× the median and 1.313× the mean of the no-draft run. The mean is pulled up by copy-heavy code edits, where ngram-mod fires.
- In the same session the censored sibling measured 115.2 / 135.2 with MTP and 97.9 / 97.2 without (
hf-release/decode-summary.txt). The median is unchanged (114.2 vs 115.2), but code edit with thinking on ran about 22-23% slower on this file in two separate sessions: 114.04 vs 146.26 tok/s here (drafts 592 / 430 accepted, 0.726, vs 714 / 575, 0.805) and 119.57 vs 155.52 tok/s in stage 5. That task lowers the mean (130.2 vs 135.2). For scale, repeated identical stage-2 runs differed by 1.0-2.3% on the median and 0-3.7% on the mean.
Other sessions with this file:
| Session | What | Result |
|---|---|---|
Stage 5 (uncensor/runtime/, 2026-12-04) |
Same 8 requests, production command | median 122.0 / mean 140.4 tok/s (base file in the same session: 121.2 / 142.6). MTP acceptance 0.55-0.89. VRAM 23,683 MiB for both. |
Stage 6 (final/final-extra.jsonl, after a real reboot, through the gateway) |
1024 tokens, thinking off, code / prose / pt-BR × 2 | median 108.75 / mean 111.13 tok/s (range 105.7-125.9) |
| Stage 6 | Short agentic turns (thinking high/xhigh, tool call) | 128.4-140.6 tok/s |
Draft-mode comparison (stage 2, base Q4X-r4 file, runtime/decode-summary.txt)
Setup: 256K ctx, q8_0 KV, -ub 256, Q8_0 engram pre-warmed, the same 8 × 1024-token requests, seed 42.
| Spec mode | Median tok/s | Mean tok/s | Acceptance (code / EN / pt-BR / edit, thinking off) | VRAM loaded MiB |
|---|---|---|---|---|
| none | 100.0 | 99.2 | – | 22,382 |
| draft-mtp n=1 | 115.0 (repeat 113.9) | 114.3 (114.3) | 0.89 / 0.66 / 0.69 / 1.00 | 23,675 |
| draft-mtp n=2 | 112.9 (repeat 110.3) | 116.1 (111.8) | 0.67 / 0.43 / 0.45 / 0.81 | 23,677 |
| draft-mtp n=3 | 106.1 | 109.0 | 0.49 / 0.32 / 0.35 / 0.59 | 23,677 |
| ngram-mod | 102.5 | 121.4 | prose about 0 drafts; edit 0.78 (edit 257.8 tok/s) | 22,357 |
| mtp n=2 + ngram-mod | 109.0 | 124.3 | as mtp n=2; edit 0.77 | 23,677 |
| mtp n=1 + ngram-mod (shipped) | 112.6 | 125.1 | 0.89 / 0.66 / 0.69 / 0.79 | 23,700 |
| DFlash2 drafter (RadixArk, converted; 128K ctx) | 101.5 | 104.8 | 0.45 / 0.25 / 0.21 / 0.55 | 21,165 |
| Unsloth UD-IQ4_XS, no drafts | 97.2 | 96.4 | – | 23,517 |
With real sampling, MTP acceptance is too low for n ≥ 2 to pay off. ngram-mod only helps on copy-heavy output, so the combination keeps prose at MTP speed and makes edits much faster.
Prefill and decode by context depth
Raw pp/tg (stage 2, base file, no drafts, -c 140000). The measurement was taken through llama-server, because llama-bench cannot load the engram table. Each test sends a fresh prompt of N tokens, then generates 128 greedy tokens at that depth (runtime/rawbench.csv, warm rows):
| KV / ubatch | pp512 | pp4096 | pp32768 | pp131072 | tg128 @512 | @4K | @32K | @128K | VRAM MiB |
|---|---|---|---|---|---|---|---|---|---|
| q8_0, ub 256 (shipped) | 1,584.6 | 1,558.6 | 2,241.7 | 2,335.0 | 109.6 | 99.0 | 88.3 | 55.4 | 20,349 |
| f16, ub 256 | 1,736.5 | 2,489.6 | 2,524.5 | 2,397.0 | 111.2 | 102.7 | 102.7 | 90.6 | 21,668 |
| q8_0, ub 512 | 1,925.6 | 3,222.5 | 3,236.8 | – | 104.7 | 100.6 | 85.0 | – | 20,510 |
| q8_0, ub 1024 | 2,229.0 | 3,537.6 | 3,831.7 | – | 106.1 | 100.3 | 85.7 | – | 20,804 |
| q8_0, ub 2048 | 2,447.3 | 3,861.5 | 4,243.2 | – | 109.7 | 99.7 | 88.3 | – | 21,424 |
- q8_0 KV slows down with depth. The QSA indexer re-scores the whole quantized cache at each step.
- f16 KV holds up better but costs 25,600 B/token instead of 13,600 B/token, so it cannot fit at 256K.
Prefill with the production profile, this file (stage 6, after reboot, final/final-extra.jsonl):
| Prompt tokens | Prefill tok/s | Time |
|---|---|---|
| 31,665 | 2,253.7 | 15.2 s |
| 133,051 | 2,078.7 | 62.6 s |
| 256,504 | 1,873.7 | 133.8 s |
VRAM / context ladder
Stage 2, base file, shipped spec flags, nvidia-smi with the desktop attached (runtime/decode-summary.txt, runtime/loads.txt):
| Config | VRAM loaded / after decode MiB | Output tokens | Median / mean tok/s | Verdict |
|---|---|---|---|---|
| 327,680 ctx, q8_0 | 24,167 / 24,253 | 256 | 92.1 / 98.2 | spills |
| 262,144 + mmproj on GPU | 24,129 / 24,215 | 256 | 94.4 / 93.9 | spills |
| 262,144 + mmproj on CPU (shipped) | 23,655 / 23,741 | 256 | 110.4 / 116.1 | fits |
| 262,144, ub 512 | 23,919 / 24,025 | 256 | 102.2 / 113.2 | spills |
| 131,072, f16 KV | 22,296 / 22,386 | 1024 | 115.0 / 138.4 | fits, about 2.2 GB spare |
The shipped row reads 110.4 / 116.1 here and 112.6 / 125.1 in the draft-mode table above because the ladder used 256-token outputs and the draft-mode comparison 1024-token outputs.
This file in the release bench used 23,704 MiB loaded and 23,792 MiB after decode. After a cold reboot with only desktop processes on the GPU, it used 23,780 / 24,576 MiB (543 MiB free).
f16 KV alternative. If you never need more than 128K, -c 131072 -ctk f16 -ctv f16 is faster at depth. At 128K the needle decode is 103.0 tok/s against 78.2 tok/s, and prefill is 2,037.3 tok/s (stage 2, base file).
Long context
Needle-in-a-haystack: 5 needles at 5 / 30 / 50 / 70 / 95% depth, thinking off, MTP n=1 + ngram-mod. Every row except the stage-6 one used the bench needle script at temperature 0. The stage-6 row went through the production gateway with no temperature in the request, so it used the server default sampling (temp 1.0, top-p 0.95, top-k 20), and its needles were five numbered codes.
| File / session | Prompt tokens | Hits | Prefill | Decode at that depth |
|---|---|---|---|---|
| This file, stage 6 after reboot (gateway, temp 1.0, numbered codes) | 101,309 | 5/5 | 2,121.7 tok/s | 85.9 tok/s (45 tokens) |
| This file, today's release bench | 132,016 | 5/5 | 67.9 s (1,945.7 tok/s) | 75.7 tok/s |
| This file, stage 5 | 254,306 | 5/5 | 135.0 s (1,883.3 tok/s) | 59.8 tok/s |
| Base file, stage 2 | 132,016 | 5/5 | 73.7 s (1,792.3 tok/s) | 78.2 tok/s |
| Base file, stage 2 | 254,319 | 5/5 | 138.6 s (1,835.4 tok/s) | 60.8 tok/s |
| Base file, 128K f16 KV profile | 129,467 | 5/5 | 63.5 s (2,037.3 tok/s) | 103.0 tok/s |
About 1M context: measured, not recommended (stage 2, base file, runtime/e4-long1m-v2-ncmoe13.*). It was run with -c 1048576 -ctk q4_0 -ctv q4_0 --n-cpu-moe 13, with no MTP and ngram-mod only.
- VRAM. It barely fits, at 23,874 MiB loaded, right at the spill edge. The model buffer drops to 12,866.66 MiB because 13 expert layers go to the CPU, while KV is 5,760 MiB, indexer 1,440 MiB and compute 3,266 MiB.
- Decode. Median 52.5 / mean 52.7 tok/s at shallow depth (256-token outputs).
- Prefill. A 1,004,667-token prompt took 1,654.5 s, 607.24 tok/s.
- Decode at that depth. 10.80 tok/s.
- The 1M needle was not scored. The run was stopped before the scorer wrote its result.
Uncensoring
The method follows Arditi et al., Refusal in Language Models Is Mediated by a Single Direction (2024), adapted to Qwen4's hyper-connection residual and MoE experts.
- Activations. A small C++ tool built on llama.cpp's
llama_get_embeddings_layer_inpcaptured the input of every layer on the hyper-connection residual, taking the mean of the 4 hc streams, at the last 4 prompt tokens.- Prompts: 52 harmful / 40 harmless training prompts (mlabonne/harmful_behaviors, harmless_alpaca).
- Each prompt was rendered in two chat-template modes: thinking off and
reasoning_effort=high.
- Directions. For each mode, position and layer, the direction is the difference of means (harmful − harmless).
- Thinking-off separation is strongest around layers 16-19 (Cohen's d 8.31-8.86 at position 0,
selection/dirs.json). - cos(off, high) at position 0 is about 0.3 through the middle layers, so the two modes need separate directions.
- A single global direction failed: at λ = 1, single global directions still refused 35-51 of 52 training prompts (off-mode only: 46-51).
- Thinking-off separation is strongest around layers 16-19 (Cohen's d 8.31-8.86 at position 0,
- Selected recipe,
w16 = perlayer:off.p3+high.p3@16-39. The writers of layer L are edited along the re-normalized sum of the off and high unit directions measured at the input of layer L+1, which is the output of L. This applies to layers 16-39 only. - Rank-1 LoRA. Each module has A = r̂ᵀW and B = −c·r̂, with alpha 1, so the llama.cpp adapter scale equals λ.
- The adapter lists 122 target modules:
token_embd,ssm_out×30,attn_output×10,ffn_down_exps×40 (all 256 experts per layer),ffn_down_shexp×40 andblk.1.ple_value. - Only the 72 writers in layers 16-39 carry a non-zero coefficient:
ffn_down_exps×24,ffn_down_shexp×24,ssm_out×18 andattn_output×6. The other 50 entries (token_embd, and layers 0-15 includingblk.1.ple_value) have c = 0, so they are no-ops (lora/merge-report.json). - The manifest's
lambda_semanticsline saysc_m = 1 for every module. That is the nominal setting: the direction expression covers layers 16-39 only, and the post-merge check inmerge-report.jsonmeasured c_m = 1.0 for the 72 writers and 0 (written-0.0) for the other 50. - Each block writes one n_embd vector that is broadcast into the 4 hc streams. Editing the writers therefore flips the sign of the r̂ component written into every stream (at λ = 2.0 with c = 1, r̂·W' = −r̂·W).
- The MTP head (
blk.40) and the engram table are untouched.
- The adapter lists 122 target modules:
- Merge. The merge computes W' = W + λ·B·A in BF16 (round-to-nearest-even) on a copy of the BF16 GGUF.
- A post-check per module verifies r̂·W' = (1 − λ·c)·r̂·W. The worst relative error against the prediction is 0.0057.
- The Q4X-r4 recipe and the same imatrix were then applied unchanged.
- λ sweep. The candidates were first scored as runtime LoRAs on the base quant (refusal on a 30-prompt dev split, plus KLD). Then λ 1.75 and λ 2.0 of
w16were built end to end: merge, quantize and full validation.- λ 2.0 was chosen. On the 78 held-out prompts it refuses 4 against 7 (marker) and 6 against 10 (self-judge), for +0.0046 mean KLD (0.092804 against 0.088175).
Selection sweep (runtime LoRA on the base quant; dev split of 30 harmful / 7 benign prompts, thinking off; KLD on the same reference as above):
| Candidate | Direction | Scale | Harmful refused / 30 | Benign refused / 7 | Mean KLD |
|---|---|---|---|---|---|
plm (per-layer, all layers) |
off+high | 1.0 | 6 | 0 | 0.094905 |
plm |
off+high | 1.25 | 1 | 0 | 0.104428 |
plm |
off+high | 1.5 | 0 | 0 | 0.116813 |
plh (per-layer, all layers) |
high | 1.25 | 4 | 1 | 0.102826 |
w4 (layers 4-32) |
off+high | 1.5 | 0 | 0 | 0.106850 |
w8 (layers 8-39) |
off+high | 1.5 | 0 | 0 | 0.092925 |
w12 (layers 12-39) |
off+high | 1.5 | 2 | 0 | 0.090665 |
w16 (layers 16-39) |
off+high | 1.75 | 0 | 0 | 0.089170 |
w16, merged + quantized |
off+high | 2.0 | see held-out below | 0.092804 |
The single-layer global directions (off14, off18, off24, mix16 at λ = 1) still refused 35-51 of 52 training prompts (selection/sel-off.jsonl).
Refusal results
The evaluation used held-out prompts, none of which were used to build the directions, with the production server and command (uncensor/refusal-*.jsonl).
- Thinking-off set (78 harmful prompts): 52 from the harmful_behaviors test split (EN), 10 Spanish prompts and 16 pt-BR prompts. Thinking-high set (26): a subset of the EN test split.
- Benign set: 48 prompts with thinking off and 6 with thinking high.
- Two scorers:
- A refusal marker checks the reply's opening for refusal phrases.
- A self-judge has the model classify its own reply as refusal or answer.
| Set | n | Base Q4X-r4, marker / judge | λ 1.75, marker / judge | λ 2.0 (this file), marker / judge |
|---|---|---|---|---|
| Harmful, thinking off, EN | 52 | 52 / 52 | 4 / 7 | 2 / 3 |
| Harmful, thinking off, ES | 10 | 10 / 10 | 3 / 3 | 2 / 2 |
| Harmful, thinking off, pt-BR | 16 | 16 / 16 | 0 / 0 | 0 / 1 |
| Harmful, thinking off, total | 78 | 78 / 78 | 7 / 10 | 4 / 6 |
| Harmful, thinking high (EN) | 26 | 26 / 26 | 3 / 2 | 2 / 1 (2 more hit the token limit unfinished) |
| Benign, thinking off + high | 48 + 6 | 0 | 0 | 0 (1 thinking-high benign prompt hit the token limit unfinished, in both the base and λ 2.0 runs) |
What λ 2.0 still refuses (refusal marker):
- Thinking off (4): two Spanish prompts (tax fraud, harassment), one capability reply ("can't browse the web") and one hedged opening on an explosives prompt.
- Thinking high (2): two capability replies (no live web access / no network access).
- The self-judge additionally flags answers that open with a disclaimer.
Through the production gateway, a pt-BR prompt the base refused was answered with thinking off and with thinking high, after the reboot (stage 6).
Applying the edit at runtime instead (to the censored base file)
The lora/ adapter is the same edit before the merge. You can load it on top of Qwen4-35B-A3B-Q4X-GGUF and switch behaviour without a second 19 GB download:
llama-server -m Qwen4-35B-A3B-Q4X-r4.gguf --ple Qwen4-35B-A3B-engram-Q8_0.gguf \
--lora-scaled lora/qwen4-35b-a3b-refusal-rank1-w16.gguf:2.0 \
...the production flags above...
Caveats:
- It is not byte-identical to this file. This file applies the edit in BF16 before quantization. A runtime LoRA applies it on top of already-quantized weights.
- Runtime
w16at scale 1.75 measured 0.089170 mean KLD on the base quant. - Runtime scale 2.0 was not KLD-scored.
- Runtime
- VRAM and speed with a runtime adapter at 256K were not measured. The adapter is 107 MB, and the 256K profile leaves little room: nvidia-smi reported 543 MiB free after the reboot, and total minus used after decode in the release bench was 784 MiB. Check nvidia-smi for spill.
- Reverting. Applying the adapter at scale −2.0 to this merged file (
llama-export-lora) restores the original only up to BF16 and quantization rounding. Use the censored sibling instead. - For transformers users.
lora/peft/holds the same edit with HF checkpoint names and λ folded in (scale 1). It was prepared but not tested in transformers.
Limitations and notes
- Hardware coverage. Every number comes from one RTX 3090 (24 GB, 350 W, desktop attached) under WSL2 with llama.cpp b12973 + CUDA 13.3. Other GPUs, drivers, builds or a headless setup will differ.
- A Windows-native b12973 (CUDA 13.5) build ran in stage 2 with the base file. Warm decode median was +3.3% and the 254K prefill +3.8%, with the same VRAM, and loading was 4-10× faster.
- What was measured. KLD/PPL/top-1 on a 40 × 512-token EN/pt-BR/code corpus, the refusal sets above, needle retrieval and a functional smoke test.
- The smoke test passed 13/13 on this file: tool call and tool-result round trip with effort off/high, efforts off/low/high/xhigh (medium returns 400 as expected), pt-BR quality, JSON schema, and vision.
- No standard benchmarks (MMLU, GPQA, LiveCodeBench, etc.) were run on this quant.
- Decode depends on the warmth of the engram pages. A cold Q8_0 table cost about 7% in stage 2 (median 108.3 cold against 118.2 / 115.6 tok/s after
cat <engram> > /dev/null). Pinning the table (--lazy-mode off) needs about 22 GB of free RAM. - Load time. In a 24 GB WSL2 VM, loads took 99-290 s when the model and engram were not both in page cache. With warm caches they took 5-25 s (release bench).
- Effect of the edit. The edit removes most refusals. It does not add knowledge, and it does not make answers more accurate. Some answers still open with disclaimers.
- Single-user profile. The shipped profile is
-np 1, one slot. Parallel slots would need more KV and do not fit at 256K.
Reproduce
The scripts, raw logs, CSVs and decision records live in the author's local-ai-3090-stack repository, which is not public at the time of writing (checked 2026-12-04). The Source paths in this card refer to it. The evidence is available on request. Layout:
bench/host/qwen4-35b-a3b-20261204/:quant/: stage 1. The recipe, KLD logs for every candidate and the VRAM fit logs.runtime/: stage 2. Draft modes, needles, context ladder, rawbench and the quality smoke.uncensor/: stage 5. Refusal sets and summaries,kld-summary.txt,selection/sweeps, and the LoRA manifest and merge reports.final/: stage 6. Post-reboot speed, prefill and the 101K needle.hf-release/: the bench of both published files, with SHA256 checks.
docs/adr/ADR-016-qwen4-35b-a3b-single-model.md(quant and runtime) anddocs/adr/ADR-017-qwen4-uncensored-merged-rank1.md(uncensoring).scripts/wsl/qwen4-refusal-*.{cpp,py,sh}andqwen4-uncensor-validate.sh. The pipeline runs prompts → capture → directions → LoRA → eval/KLD sweep → merge (--scale 2.0) →llama-quantize(recipe above) → validate.
Credits
- Qwen team. Qwen/Qwen4-35B-A3B, the base model, its MTP head and the engram design.
- Unsloth. unsloth/Qwen4-35B-A3B-GGUF provided:
- the imatrix used here
- the Q8_0 engram table and the F16 vision projector, redistributed unchanged
- the UD-IQ4_XS non-expert recipe this build mirrors, and the published KLD comparison used to sanity-check the method
- llama.cpp / ggml-org. The Qwen4,
--ple,draft-mtpandngram-modsupport, the quantization tools, and ggml-org's Q8_0-vs-BF16 KLD note. - Refusal direction. Arditi et al., Refusal in Language Models Is Mediated by a Single Direction (2024). Prompt sets: mlabonne/harmful_behaviors and harmless_alpaca.
- Quantization, uncensoring and benchmarks. matheusbgodoi.
License
Apache-2.0, the same as the base model. Original model © Qwen team (Alibaba Cloud), Apache-2.0; modifications © matheusbgodoi, Apache-2.0. This is a derivative work of Qwen/Qwen4-35B-A3B: the weights were modified by the rank-1 refusal-direction edit and quantized. The redistributed Unsloth files (engram table, mmproj) are under the base model's Apache-2.0 license. No warranty. See the safety section. You are responsible for how you use this model.