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 serve: decensor preset on by default (bundled presets/hy4-uncensor resolved from the repository, HY4_ABLIT_SPEC=0 or empty or off switches it off, explicit path wins), startup log line, CPU test

YanissAmzb47e3c34ad3a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7db04a4..13fbb08 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -2,7 +2,7 @@
## Unreleased
-- Optional decensor preset for Hy4-flash (`HY4_ABLIT_SPEC`, off by default): 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, 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`.
## 1.9.0: Hy4-flash v1
diff --git a/README.md b/README.md
index 2599b1d..b7d9f59 100644
--- a/README.md
+++ b/README.md
@@ -104,7 +104,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 has its own uncensor preset, off by default: `HY4_ABLIT_SPEC=<repo>/presets/hy4-uncensor/edit_spec.json` ([presets/hy4-uncensor](presets/hy4-uncensor/README.md)).
+- 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`.
## Made with our models
diff --git a/doc/env_vars.md b/doc/env_vars.md
index 45e6bc1..ea21198 100644
--- a/doc/env_vars.md
+++ b/doc/env_vars.md
@@ -1055,11 +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: unset, the hook is off)
+#### `HY4_ABLIT_SPEC` (default: the bundled `presets/hy4-uncensor/edit_spec.json`, the hook is on)
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. `off`, `0`, `false`, `no` and `none` force it off. A malformed spec or a missing file stops
+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
the load. The preset is in `presets/hy4-uncensor/`. See [hy4.md](hy4.md).
#### `EXL3_ABLIT_TORCH` (default: `0`)
diff --git a/doc/hy4.md b/doc/hy4.md
index 9b0272a..f369edc 100644
--- a/doc/hy4.md
+++ b/doc/hy4.md
@@ -65,7 +65,7 @@ The server speaks the OpenAI API (`/v1/chat/completions`, `/v1/completions`, bot
| `HY4_ENGRAM_NPHASH`, `HY4_ENGRAM_PF_WORKERS` | 1, 1 | Engram hash in numpy; one prefetch worker |
| `HY4_ENGRAM_NATIVE_IO` | 1 | Engram row reads in C threads (`pread`, no GIL) |
| `HY4_ENGRAM_FUSED` | 0 | two-launch fused Engram block in decode (opt-in) |
-| `HY4_ABLIT_SPEC` | unset (off) | path of `edit_spec.json` (tensor file next to it): run-time decensor edit of the attention and MLP / MoE outputs; the shipped preset is `presets/hy4-uncensor/`; `off` disables |
+| `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 |
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).
@@ -87,15 +87,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 (optional)
+## Uncensor preset (on by default)
-Off by default. One env line turns it on; the spec is a run-time edit of the attention and MLP / MoE outputs and changes no weights:
+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:
```bash
-HY4_ABLIT_SPEC=<repo>/presets/hy4-uncensor/edit_spec.json 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=0 python tools/hy4/serve.py --model ./hy4/Hy4-flash-Q3_K-00001-of-00002.gguf --port 8300 -c 65536 --num-draft 3
```
-`off` or an unset variable runs the unmodified forward. Details and files: [presets/hy4-uncensor](../presets/hy4-uncensor/README.md).
+`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).
## Known limits
diff --git a/presets/hy4-uncensor/README.md b/presets/hy4-uncensor/README.md
index 17a32d8..89144dd 100644
--- a/presets/hy4-uncensor/README.md
+++ b/presets/hy4-uncensor/README.md
@@ -1,12 +1,12 @@
-# Hy4-flash: decensor preset (opt-in)
+# Hy4-flash: decensor preset (on by default)
-A run-time edit of the Hy4 forward. It edits no weights and no quantised data. Off unless `HY4_ABLIT_SPEC` points at the spec.
+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.
```
-HY4_ABLIT_SPEC=/path/to/presets/hy4-uncensor/edit_spec.json python tools/hy4/serve.py --model ./hy4/Hy4-flash-Q3_K-00001-of-00002.gguf ...
+HY4_ABLIT_SPEC=0 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=off` (or unset) runs the unmodified forward.
+`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.
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
new file mode 100644
index 0000000..e38d9e4
--- /dev/null
+++ b/tests/test_hy4_ablit_default.py
@@ -0,0 +1,40 @@
+"""CPU test of the decensor preset default of the Hy4 server (serve_core.ablit_spec): bundled preset when unset, off switches, explicit path wins.
+Run: python -m unittest tests/test_hy4_ablit_default.py (no GPU, no model)"""
+import os
+import sys
+import unittest
+
+HERE = os.path.dirname(os.path.abspath(__file__))
+TREE = os.path.dirname(HERE)
+sys.path.insert(0, os.path.join(TREE, "tools", "hy4"))
+import serve_core as C # noqa: E402
+
+
+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")))
+
+ def test_off_values_give_no_spec(self):
+ for v in ("0", "", " ", "off", "OFF", "false", "no", "none"):
+ self.assertIsNone(C.ablit_spec({"HY4_ABLIT_SPEC": v}, TREE), v)
+
+ def test_explicit_path_wins(self):
+ 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")))
+
+ def test_cwd_does_not_matter(self):
+ old = os.getcwd()
+ try:
+ os.chdir("/")
+ self.assertTrue(os.path.isfile(C.ablit_spec({}, TREE)))
+ finally:
+ os.chdir(old)
+
+
+if __name__ == "__main__":
+ unittest.main()
diff --git a/tools/hy4/serve.py b/tools/hy4/serve.py
index 8e8f40d..c1bd19a 100644
--- a/tools/hy4/serve.py
+++ b/tools/hy4/serve.py
@@ -94,6 +94,9 @@ 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)
@@ -367,11 +370,13 @@ def load_in_background(st: State):
st.stage = s
print("load:", s, flush=True)
eng.load(progress)
- sp = os.environ.get("HY4_ABLIT_SPEC", "").strip() # optional decensor spec (edit_spec.json + edit_spec.safetensors next to it); unset or off = the unmodified forward
- if sp and sp.lower() not in ("off", "0", "false", "no", "none"):
+ 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
+ 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()
- print("decensor spec armed:", sp, flush=True)
+ print(f"decensor preset on (HY4_ABLIT_SPEC={sp})", flush=True)
+ else:
+ print("decensor preset off", flush=True)
if a.slots > 1:
import mu_engine
st.sched = mu_engine.MuScheduler(eng, chunk=a.sched_chunk)
diff --git a/tools/hy4/serve_core.py b/tools/hy4/serve_core.py
index 4dd4ee6..aeb2aeb 100644
--- a/tools/hy4/serve_core.py
+++ b/tools/hy4/serve_core.py
@@ -328,6 +328,20 @@ class OutputStream:
# ------------------------------------------------------------------------------------------------ response bodies
+ABLIT_OFF = ("", "off", "0", "false", "no", "none")
+
+
+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)."""
+ v = environ.get("HY4_ABLIT_SPEC")
+ if v is None:
+ 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
+
+
def new_id(prefix: str) -> str:
return f"{prefix}-{uuid.uuid4().hex[:24]}"