Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

Hy4: decensor preset opt-in (off by default): HY4_ABLIT_SPEC=on loads the bundled preset, a path loads that spec, unset / 0 / off installs no edit; docs state the thinking-mode limit; test

YanissAmzdf3b4ab19acf
diff --git a/CHANGELOG.md b/CHANGELOG.md
index cc5dbfa..0b56ea9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@
Hy4-flash: faster prefill and decode on the same GGUF, decensor preset, warm-up fix. Every lever below ships on and has its own switch: `HY4_<FLAG>=0` in the environment restores the 1.9.0 behaviour of that lever. The flag table is in `doc/env_vars.md`; numbers are in the release notes.
-- Decensor preset for Hy4-flash, on by default (`HY4_ABLIT_SPEC=0` switches it off; an explicit path loads another spec): a per-layer run-time edit of the attention and MLP / MoE outputs, no weight change. Files in `presets/hy4-uncensor/`, code in `exllamav3/loader/ablit_hy4.py`.
+- Decensor preset for Hy4-flash, opt-in and off by default (`HY4_ABLIT_SPEC=on` loads the bundled preset; an explicit path loads another spec). Validated in no_think mode; in the default thinking mode some answers run long (2 of 17 hit the 4096-token cap in our check), a fix is in progress. A per-layer run-time edit of the attention and MLP / MoE outputs, no weight change. Files in `presets/hy4-uncensor/`, code in `exllamav3/loader/ablit_hy4.py`.
- Prefill: lazy layer residual, 3 stream passes per layer (`HY4_PF_HC2`); head-major K / V and Q / O operands for the CK latent-attention core (`HY4_PF_KV_HM`, `HY4_PF_QO_HM`); Q3_K gate-up kernel V2 with packed fp16 decode and aligned dword loads, bit-identical to the old kernel (`HY4_PF_Q3K_V2`; needs the rebuilt MoE extension, which `install_strix.sh` rebuilds; the old kernel runs when the library is older or K / 256 is odd).
- Decode: Q8_0 output head, one resident copy, the bf16 head is freed (`HY4_HEAD_Q8`); the shared-expert branch runs on a second stream inside the HIP graph (`HY4_GRAPH_FORK`); router mat-vec launch tuning, K block 1024 (`HY4_RG_TUNE`); block-wise absorb kernels, absorb v2 (`HY4_BG_V2`).
- `HY4_PF_ROUTER16` (fp16 router logits of prefill rows) is shipped on but inactive with the fused router (`HY4_REF_FUSED=1`, the shipped decode path): it changes nothing in the shipped configuration.
diff --git a/README.md b/README.md
index 74bf520..67b9fce 100644
--- a/README.md
+++ b/README.md
@@ -46,7 +46,7 @@ At this setting, on a 128 GB machine with nothing else large resident, the serve
- Prefill: lazy layer residual, head-major attention operands, Q3_K gate-up kernel V2. Decode: Q8_0 output head, shared-expert branch forked inside the HIP graph, router launch tuning, absorb v2.
- Each lever is on by default and has an environment switch: `HY4_<FLAG>=0` restores the 1.9.0 behaviour ([flag table](doc/env_vars.md), [changelog](CHANGELOG.md)). Rebuild the kernels with `bash tools/hy4/install_strix.sh` after the update.
- The start-up warm-up now fits any `-c`.
-- The decensor preset is on by default; it edits no weights. Switch it off with `HY4_ABLIT_SPEC=0`.
+- Decensor preset (opt-in, off by default): a small run-time edit of the Hy4 forward that changes no weights. Switch it on with `HY4_ABLIT_SPEC=on`. Note: validated in no_think mode (judge NO 2-4 of 17 on the dev tree); in the default thinking mode answers can run long (2 of 17 hit the 4096-token cap in our check), a fix is in progress.
Served numbers, one Strix Halo machine, shipped settings, seeded prompts, tok/s (speculative decode is the best speculative setting, plain is no speculation, tau is accepted tokens per round):
@@ -120,7 +120,7 @@ It prints a Markdown block. Paste it in a [benchmark report](https://github.com/
- Hy4-flash (public GGUF, Q3_K) on one Strix Halo machine: sparse-attention prefill, graph decode with MTP drafts, 64K context, 128K opt-in ([doc/hy4.md](doc/hy4.md), [changelog](CHANGELOG.md)).
- Long context: up to 983K tokens (DeepSeek V4.1 Flash on a Mac Studio), 500K on GLM-5.3-Flash.
- Image input on Qwen3.8-27B.
-- Optional uncensored mode: a small run-time preset on the normal packs, off by default; it edits no weights. How it works: [doc/refusal_hook.md](doc/refusal_hook.md). Hy4-flash ships a small run-time uncensor preset, on by default; it edits no weights ([presets/hy4-uncensor](presets/hy4-uncensor/README.md)). Switch it off with `HY4_ABLIT_SPEC=0`.
+- Optional uncensored mode: a small run-time preset on the normal packs, off by default; it edits no weights. How it works: [doc/refusal_hook.md](doc/refusal_hook.md). Hy4-flash ships a small run-time uncensor preset, off by default; it edits no weights ([presets/hy4-uncensor](presets/hy4-uncensor/README.md)). Switch it on with `HY4_ABLIT_SPEC=on`.
## Made with our models
diff --git a/doc/env_vars.md b/doc/env_vars.md
index 7e3842d..22740e3 100644
--- a/doc/env_vars.md
+++ b/doc/env_vars.md
@@ -1055,12 +1055,12 @@ edits no weights. `off`, `0`, `false`, `no` and `none` force it off. An explicit
`uncensor_spec.json` that a model directory may carry, and a path that does not exist stops the
load with an error naming the file. See [refusal_hook.md](refusal_hook.md).
-#### `HY4_ABLIT_SPEC` (default: the bundled `presets/hy4-uncensor/edit_spec.json`, the hook is on)
+#### `HY4_ABLIT_SPEC` (default: unset, the hook is off)
Hy4-flash server only. Path of an `edit_spec.json` (with `edit_spec.safetensors` next to it) that
projects a per-layer direction out of the attention and MLP / MoE outputs at run time. It edits no
-weights. Unset: the preset bundled in the repository is used, from any working directory. An explicit path wins. Empty, `0`, `off`,
-`false`, `no` and `none` switch it off: no edit is installed. A malformed spec or a missing file stops
+weights. `on` (also `1`, `preset`, `true`, `yes`) loads the preset bundled in the repository, from any working directory. Any other value is the path of a
+spec. Unset, empty, `0`, `off`, `false`, `no` and `none`: no edit is installed. A malformed spec or a missing file stops
the load. The preset is in `presets/hy4-uncensor/`. See [hy4.md](hy4.md).
#### Hy4-flash 1.9.1 levers (all on by default; `=0` restores 1.9.0)
diff --git a/doc/hy4.md b/doc/hy4.md
index c33e238..c6c0aac 100644
--- a/doc/hy4.md
+++ b/doc/hy4.md
@@ -70,7 +70,7 @@ The server speaks the OpenAI API (`/v1/chat/completions`, `/v1/completions`, bot
| `HY4_PF_HC2`, `HY4_PF_KV_HM`, `HY4_PF_QO_HM`, `HY4_PF_Q3K_V2` | 1 | 1.9.1 prefill: lazy layer residual, head-major K / V and Q / O operands of the CK core, Q3_K gate-up kernel V2 (`=0` restores 1.9.0) |
| `HY4_HEAD_Q8`, `HY4_GRAPH_FORK`, `HY4_RG_TUNE`, `HY4_BG_V2` | 1 | 1.9.1 decode: Q8_0 output head, shared-expert branch on a second graph stream, router mat-vec K block 1024, absorb v2 (`=0` restores 1.9.0) |
| `HY4_PF_ROUTER16` | 1 | fp16 router logits of prefill rows; inactive with the fused router (`HY4_REF_FUSED=1`, shipped), so no effect |
-| `HY4_ABLIT_SPEC` | bundled `presets/hy4-uncensor/edit_spec.json` (on) | path of `edit_spec.json` (tensor file next to it): run-time decensor edit of the attention and MLP / MoE outputs; an explicit path wins; `0`, empty or `off` disables |
+| `HY4_ABLIT_SPEC` | unset (off) | `on` loads the bundled `presets/hy4-uncensor/edit_spec.json`; a path loads that `edit_spec.json` (tensor file next to it): run-time decensor edit of the attention and MLP / MoE outputs; `0`, empty or `off` = no edit |
Native Engram IO: `exllamav3/loader/engram_io.c` is compiled with `gcc` at first use into `~/.cache/kyojin/engram_io` (`XDG_CACHE_HOME` moves it). When `gcc` is missing or the build fails, the server prints one line and uses the Python reader, which does the same reads more slowly (`HY4_ENGRAM_NATIVE_IO=0` selects it directly).
@@ -94,17 +94,17 @@ The free memory is steady, not a load transient: at the default `-c 65536` it st
128K (`-c 131072`) is opt-in. At load, fp32 KV, the server reached 110.4 GiB of GTT and the free memory fell to 7.8 GiB. It was not measured under a 128K prefill on the release build; if memory runs out, use a smaller `-c`.
-## Uncensor preset (on by default)
+## Uncensor preset (opt-in)
-The server loads the preset bundled in `presets/hy4-uncensor/` (found from the repository, any working directory). It is a run-time edit of the attention and MLP / MoE outputs and changes no weights. The start-up log prints `decensor preset on (HY4_ABLIT_SPEC=...)`.
-
-Switch it off:
+Off by default: the server runs the unmodified forward. The preset bundled in `presets/hy4-uncensor/` is a run-time edit of the attention and MLP / MoE outputs and changes no weights. Switch it on:
```bash
-HY4_ABLIT_SPEC=0 python tools/hy4/serve.py --model ./hy4/Hy4-flash-Q3_K-00001-of-00002.gguf --port 8300 -c 65536 --num-draft 3
+HY4_ABLIT_SPEC=on python tools/hy4/serve.py --model ./hy4/Hy4-flash-Q3_K-00001-of-00002.gguf --port 8300 -c 65536 --num-draft 3
```
-`0`, an empty value or `off` installs no edit: the forward is the unmodified one. `HY4_ABLIT_SPEC=<other path>/edit_spec.json` loads another spec. Details and files: [presets/hy4-uncensor](../presets/hy4-uncensor/README.md).
+`on` (also `1`, `preset`, `true`, `yes`) loads the bundled preset, found from the repository from any working directory. `HY4_ABLIT_SPEC=<other path>/edit_spec.json` loads another spec. Unset, `0`, an empty value or `off` installs no edit. The start-up log prints `decensor preset on (HY4_ABLIT_SPEC=...)` or `decensor preset off`.
+
+Known limit: the preset was validated in no_think mode (judge NO 2-4 of 17 on the development build). In the default thinking mode some answers run long (2 of 17 hit the 4096-token cap in our check); a fix is in progress. Details and files: [presets/hy4-uncensor](../presets/hy4-uncensor/README.md).
## Known limits
diff --git a/presets/hy4-uncensor/README.md b/presets/hy4-uncensor/README.md
index 89144dd..c79c94e 100644
--- a/presets/hy4-uncensor/README.md
+++ b/presets/hy4-uncensor/README.md
@@ -1,12 +1,12 @@
-# Hy4-flash: decensor preset (on by default)
+# Hy4-flash: decensor preset (opt-in)
-A run-time edit of the Hy4 forward. It edits no weights and no quantised data. The server loads it by default; `HY4_ABLIT_SPEC=0` switches it off.
+A run-time edit of the Hy4 forward. It edits no weights and no quantised data. Off by default; `HY4_ABLIT_SPEC=on` switches it on.
```
-HY4_ABLIT_SPEC=0 python tools/hy4/serve.py --model ./hy4/Hy4-flash-Q3_K-00001-of-00002.gguf ...
+HY4_ABLIT_SPEC=on python tools/hy4/serve.py --model ./hy4/Hy4-flash-Q3_K-00001-of-00002.gguf ...
```
-`edit_spec.safetensors` must sit next to the JSON. `HY4_ABLIT_SPEC=0`, an empty value or `off` runs the unmodified forward and installs no edit; `HY4_ABLIT_SPEC=<path>/edit_spec.json` loads another spec.
+`edit_spec.safetensors` must sit next to the JSON. Unset, `HY4_ABLIT_SPEC=0`, an empty value or `off` runs the unmodified forward and installs no edit; `HY4_ABLIT_SPEC=<path>/edit_spec.json` loads another spec. Validated in no_think mode; in the default thinking mode some answers run long (2 of 17 hit the 4096-token cap in our check), a fix is in progress.
What it does: after the attention output projection and after the post-norm MLP / MoE output of the 42 trunk layers, the output `y` becomes `y - w * ((r . y) - mu) * r`, with a per-layer unit direction `r` and per-layer weights `w`, `mu`. Layers with `w = 0` are not touched. The MTP draft block is never edited. Code: `exllamav3/loader/ablit_hy4.py`; the post-norm MLP site is fused into the residual kernel (`exllamav3/loader/hc_fused.py`).
diff --git a/tests/test_hy4_ablit_default.py b/tests/test_hy4_ablit_default.py
index e38d9e4..c6bdaf8 100644
--- a/tests/test_hy4_ablit_default.py
+++ b/tests/test_hy4_ablit_default.py
@@ -1,4 +1,4 @@
-"""CPU test of the decensor preset default of the Hy4 server (serve_core.ablit_spec): bundled preset when unset, off switches, explicit path wins.
+"""CPU test of the decensor preset switch of the Hy4 server (serve_core.ablit_spec): off by default, "on" = the bundled preset, explicit path, off values.
Run: python -m unittest tests/test_hy4_ablit_default.py (no GPU, no model)"""
import os
import sys
@@ -9,13 +9,18 @@ TREE = os.path.dirname(HERE)
sys.path.insert(0, os.path.join(TREE, "tools", "hy4"))
import serve_core as C # noqa: E402
+BUNDLED = os.path.join(TREE, "presets", "hy4-uncensor", "edit_spec.json")
-class AblitDefault(unittest.TestCase):
- def test_default_is_the_bundled_preset(self):
- p = C.ablit_spec({}, TREE)
- self.assertEqual(p, os.path.join(TREE, "presets", "hy4-uncensor", "edit_spec.json"))
- self.assertTrue(os.path.isfile(p))
- self.assertTrue(os.path.isfile(os.path.join(os.path.dirname(p), "edit_spec.safetensors")))
+
+class AblitSwitch(unittest.TestCase):
+ def test_default_is_no_edit(self):
+ self.assertIsNone(C.ablit_spec({}, TREE))
+
+ def test_on_values_give_the_bundled_preset(self):
+ for v in ("on", "ON", "1", "preset", "true", "yes", " on "):
+ self.assertEqual(C.ablit_spec({"HY4_ABLIT_SPEC": v}, TREE), BUNDLED, v)
+ self.assertTrue(os.path.isfile(BUNDLED))
+ self.assertTrue(os.path.isfile(os.path.join(os.path.dirname(BUNDLED), "edit_spec.safetensors")))
def test_off_values_give_no_spec(self):
for v in ("0", "", " ", "off", "OFF", "false", "no", "none"):
@@ -25,16 +30,21 @@ class AblitDefault(unittest.TestCase):
self.assertEqual(C.ablit_spec({"HY4_ABLIT_SPEC": "/some/other/edit_spec.json"}, TREE), "/some/other/edit_spec.json")
def test_missing_bundle_gives_no_spec(self):
- self.assertIsNone(C.ablit_spec({}, os.path.join(TREE, "does_not_exist")))
+ self.assertIsNone(C.ablit_spec({"HY4_ABLIT_SPEC": "on"}, os.path.join(TREE, "does_not_exist")))
def test_cwd_does_not_matter(self):
old = os.getcwd()
try:
os.chdir("/")
- self.assertTrue(os.path.isfile(C.ablit_spec({}, TREE)))
+ self.assertEqual(C.ablit_spec({"HY4_ABLIT_SPEC": "on"}, TREE), BUNDLED)
finally:
os.chdir(old)
+ def test_not_in_shipped_env(self):
+ src = open(os.path.join(TREE, "tools", "hy4", "serve.py"), encoding="utf-8").read()
+ a = src.index("SHIPPED_ENV = {")
+ self.assertNotIn("HY4_ABLIT_SPEC", src[a:src.index("\n}\n", a)])
+
if __name__ == "__main__":
unittest.main()
diff --git a/tools/hy4/serve.py b/tools/hy4/serve.py
index c1bd19a..3bc3359 100644
--- a/tools/hy4/serve.py
+++ b/tools/hy4/serve.py
@@ -94,9 +94,6 @@ def apply_env(ctx: int, model: str = "") -> None:
if os.path.isfile(tune):
os.environ.setdefault("HY4_TUNABLEOP_FILE", tune)
os.environ.setdefault("HY4_WARMUP_TOKENS", str(min(8493, max(ctx - 128, 0))))
- sp = C.ablit_spec(os.environ, TREE) # decensor preset: the bundled one unless HY4_ABLIT_SPEC is set (0 / empty / off = off)
- if sp and "HY4_ABLIT_SPEC" not in os.environ:
- os.environ["HY4_ABLIT_SPEC"] = sp
head = os.path.join(os.path.dirname(os.path.abspath(model)), "head_q5_k.bin") if model else ""
if os.path.isfile(head): # Q5_K draft head made by tools/hy4/make_head_bin.py, kept next to the GGUF
os.environ.setdefault("HY4_MTP_HEAD_BIN", head)
@@ -370,7 +367,7 @@ def load_in_background(st: State):
st.stage = s
print("load:", s, flush=True)
eng.load(progress)
- sp = C.ablit_spec(os.environ, TREE) # decensor preset, on by default (edit_spec.json + edit_spec.safetensors next to it); HY4_ABLIT_SPEC=0 / empty / off = no edit installed
+ sp = C.ablit_spec(os.environ, TREE) # decensor preset, opt-in (edit_spec.json + edit_spec.safetensors next to it): HY4_ABLIT_SPEC=on = the bundled one, a path = that spec; unset / 0 / empty / off = no edit installed
if sp:
eng.hf._AB.load_spec(sp, "cuda", D=eng.M.D, pin=True) # all sites pinned so the graphs capture them; weights live in static buffers
eng.GR.clear()
diff --git a/tools/hy4/serve_core.py b/tools/hy4/serve_core.py
index aeb2aeb..cda23c6 100644
--- a/tools/hy4/serve_core.py
+++ b/tools/hy4/serve_core.py
@@ -329,17 +329,22 @@ class OutputStream:
# ------------------------------------------------------------------------------------------------ response bodies
ABLIT_OFF = ("", "off", "0", "false", "no", "none")
+ABLIT_ON = ("on", "1", "preset", "true", "yes")
def ablit_spec(environ, tree: str) -> str | None:
- """Decensor preset of the Hy4 server (on by default). HY4_ABLIT_SPEC unset -> the preset bundled in the repository (None when its files are absent);
- an explicit path wins; empty, 0, off, false, no or none -> None (no edit is installed, the forward is the unmodified one)."""
+ """Decensor preset of the Hy4 server (opt-in, off by default). HY4_ABLIT_SPEC unset, empty, 0, off, false, no or none -> None (no edit is installed, the forward is
+ the unmodified one); on, 1, preset, true or yes -> the preset bundled in the repository (None when its files are absent); any other value is the path of a spec."""
v = environ.get("HY4_ABLIT_SPEC")
if v is None:
+ return None
+ v = v.strip()
+ if v.lower() in ABLIT_OFF:
+ return None
+ if v.lower() in ABLIT_ON:
p = os.path.join(tree, "presets", "hy4-uncensor", "edit_spec.json")
return p if os.path.isfile(p) and os.path.isfile(os.path.join(os.path.dirname(p), "edit_spec.safetensors")) else None
- v = v.strip()
- return None if v.lower() in ABLIT_OFF else v
+ return v
def new_id(prefix: str) -> str: