Instructions to use korokoboom/Bonsai-2-9b-Shakespeare-SFT with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use korokoboom/Bonsai-2-9b-Shakespeare-SFT with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf korokoboom/Bonsai-2-9b-Shakespeare-SFT # Run inference directly in the terminal: llama cli -hf korokoboom/Bonsai-2-9b-Shakespeare-SFT
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf korokoboom/Bonsai-2-9b-Shakespeare-SFT # Run inference directly in the terminal: llama cli -hf korokoboom/Bonsai-2-9b-Shakespeare-SFT
Build from source code
git clone https://github.com/ggml-org/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-app # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama serve -hf korokoboom/Bonsai-2-9b-Shakespeare-SFT # Run inference directly in the terminal: ./build/bin/llama cli -hf korokoboom/Bonsai-2-9b-Shakespeare-SFT
Use Docker
docker model run hf.co/korokoboom/Bonsai-2-9b-Shakespeare-SFT
- Llama new
- LM Studio
- Jan
- vLLM
How to use korokoboom/Bonsai-2-9b-Shakespeare-SFT with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "korokoboom/Bonsai-2-9b-Shakespeare-SFT" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "korokoboom/Bonsai-2-9b-Shakespeare-SFT", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/korokoboom/Bonsai-2-9b-Shakespeare-SFT
- Ollama
How to use korokoboom/Bonsai-2-9b-Shakespeare-SFT with Ollama:
ollama run hf.co/korokoboom/Bonsai-2-9b-Shakespeare-SFT
- Unsloth Desktop
- Pi
How to use korokoboom/Bonsai-2-9b-Shakespeare-SFT with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf korokoboom/Bonsai-2-9b-Shakespeare-SFT
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:9931/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "korokoboom/Bonsai-2-9b-Shakespeare-SFT" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Docker Model Runner
How to use korokoboom/Bonsai-2-9b-Shakespeare-SFT with Docker Model Runner:
docker model run hf.co/korokoboom/Bonsai-2-9b-Shakespeare-SFT
- Lemonade
How to use korokoboom/Bonsai-2-9b-Shakespeare-SFT with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull korokoboom/Bonsai-2-9b-Shakespeare-SFT
Run and chat with the model
lemonade run user.Bonsai-2-9b-Shakespeare-SFT-{{QUANT_TAG}}List all available models
lemonade list
- Hermes Agent
How to use korokoboom/Bonsai-2-9b-Shakespeare-SFT with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf korokoboom/Bonsai-2-9b-Shakespeare-SFT
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:9931/v1 hermes config set model.default korokoboom/Bonsai-2-9b-Shakespeare-SFT
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use korokoboom/Bonsai-2-9b-Shakespeare-SFT with OpenClaw:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama serve -hf korokoboom/Bonsai-2-9b-Shakespeare-SFT
Configure OpenClaw
# Install OpenClaw: npm install -g openclaw@latest # Register the local server and set it as the default model: openclaw onboard --non-interactive --mode local \ --auth-choice custom-api-key \ --custom-base-url http://127.0.0.1:9931/v1 \ --custom-model-id "korokoboom/Bonsai-2-9b-Shakespeare-SFT" \ --custom-provider-id llama-cpp \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Bonsai Shakespeare 9B
This model is an experiment in QAT LoRA on a ternary model: can you fine-tune Ternary-Bonsai-2-9B while it only exists as 2-bit ternary weights?
Standard quantization-aware pipelines keep a higher-precision master copy and quantize on the way into each forward pass. Here there was no stored master copy. The base stayed as frozen ternary codes for the whole run, and the LoRA delta was trained directly against that grid. At the end the adapter was discarded and its effect was committed into the GGUF by rewriting the 2-bit codes in place. Installing Shakespeare cost 55,603,249 trit flips out of 6.9 billion weights (0.80%).
Shakespearean code review was chosen as the task because style transfer gives a clean signal to evaluate. Paste a git diff and the model answers with a short analytical think block, then a lament in the voice of a tragic hero, with the actual remedy spelled out at the end. Either the review opens with "Alas" or it doesn't, which makes the persona an unambiguous instrument for measuring whether ternary training worked.
The result is a plain GGUF with the same size, format, and inference cost as the original, with no adapter or sidecar weights to merge at serve time.
Example
Input: a raw git diff. The persona is baked into the weights, so no system prompt is required.
Output:
<think>
The diff changes `fetch_page` to return rows[:limit + 1] and removes the
empty-result guard, while `fetch_all` switches to while True with a blanket
except. The off-by-one returns one extra row per page, so the boundary row
appears on two consecutive pages...
</think>
Alas, poor pagination! This scroll doth turn but not for naught, for thou
dost slice `rows[:limit + 1]`, and so the last event is caught twice across
pages. One fate, yet doomed duplication: the same row shall live in both
scrolls, a ghost haunting two tombs.
Better cure this wound: fetch only `limit` rows, and let each page's tail
hold its own final row...
How it was trained
The whole pipeline runs from the original GGUF file alone. No reference fp16 checkpoint is needed.
- Artifacts from the GGUF. Hadamard sign vectors, the tokenizer, and the config are all rebuilt from GGUF metadata (
generate_artifacts.py). - Factored representation. The GGUF is decomposed into ternary codes, fp16 per-block scales, and dense sidecar tensors (
extract_gguf.py). - LoRA in rotated weight space. Each of the 200 rotated linear layers gets a rank-64 LoRA pair in f32. The base stays as frozen ternary codes. There is no fp16 master weight tensor; the master weight
M = ternary + B@Ais formed on the fly inside the forward pass. - STE with hysteresis. The forward pass rounds the master weight onto the ternary grid, using a straight-through estimator so gradients reach the LoRA as if rounding were the identity. The rounding keeps a hysteresis band: a weight must pass 0.60 of a block scale to flip up, and fall below 0.40 to flip back. This suppresses the flip-flop noise that otherwise destabilizes training near rounding boundaries.
- Runtime Hadamard rotation. Activations are rotated with
FWHT(xยทs)/โ4096at each linear layer, and the weights live permanently in rotated space. - Trit-flip merge. Training ends with one committed trit per weight, taken from the hysteresis state. The merge writes those trits back into the GGUF's 2-bit codes in place. Scales and metadata stay untouched, so what was evaluated is exactly what ships.
Training config
| setting | value |
|---|---|
| LoRA rank / alpha | 64 / 128 |
| learning rate | 1e-4, cosine decay, 20 warmup steps |
| effective batch | 32 (2 ร 16 accumulation) |
| epochs / steps | 3 / 870 |
| hysteresis threshold | 0.60 |
| trainable params | ~160M |
| data | ~9,300 diff + review pairs |
| wall clock | 21.4 h on a single 40GB GPU |
The data comes from diffs harvested from ronantakizawa/github-codereview, quality-filtered, deduplicated, and capped at 2,048 diff tokens. Review comments were restyled into Shakespearean tragedy by a teacher model, and a separate teacher pass generated 80โ120 word analytical think blocks that reason about the code change (never about the review). Loss is computed on the think and review tokens only.
Training dynamics
Loss fell from 2.31 to 1.40 over the run. Gradient norm peaked at 24 early in warmup, then settled around 3.8 for the rest of training. The flip curve is a gentle S: no flips for the first 20 steps while the LoRA grows from zero and the forward pass stays bit-identical to the base, steady commitment through the middle, then a hard flatten as the learning rate anneals. Total: 55.6M flips, 0.80% of rotated weights.
What we learned
- Rank 16 could not hold a persona. Our first runs (rank 16, 1.5k examples) plateaued at loss 2.3 and produced 0/15 persona on held-out prompts without a system message. Rank 64 broke through to 1.5 and the persona appeared. The binding constraint was capacity.
- Hysteresis works. Earlier plain-STE runs showed gradient norms climbing to 38 while loss rose. With hysteresis the gradient norm stabilizes and loss actually descends. The band costs a little stickiness, since weights parked between 0.5 and 0.6 never commit, which is why we settled on 0.60 rather than 0.75.
- With ~10k examples, epoch 3 is optional. Epoch-boundary loss barely moves (1.42 to 1.39), so there is no memorization cliff. Two epochs would have been nearly as good.
- Watch the token budget. The model thinks longer on hard diffs than its 80โ120 word training target, usually around 90โ150 words. Four of our first eval "failures" were simply the think block hitting the 400-token generation cap before the tragedy started. With enough room to think, persona consistency is 15/15.
Evaluation
Held-out diffs never seen in training, a plain "You are a code reviewerโฆ" system prompt, and thinking enabled:
- Persona consistency: 15/15. Every output opens its review in the tragic voice.
- Think quality: analytical, grounded in the actual diff, with no persona leakage into the reasoning.
- Technical substance: the weakest axis. The model reliably finds a plausible issue and dramatizes it, but it lands on the issue a human reviewer flagged about half the time, and it occasionally invents problems. Treat the technical content as a starting point.
Usage
This file needs PrismML's llama.cpp fork with support for type-42 ternary tensors. Stock llama.cpp cannot read it.
./llama-cli -m BonsaiShakespeareV3.gguf \
--chat-template chatml \
-p "<|im_start|>user
File: src/pagination.py (python)
<paste diff here><|im_end|>
<|im_start|>assistant
"
Tips:
- A system prompt is optional. The persona lives in the weights, so the diff alone is enough. Adding a system prompt won't stop the tragedy.
- Give it room to think. Budget at least 800 new tokens; the think block runs 90โ150 words before the review starts.
- Use greedy decoding for the most consistent persona.
Limitations
- This is a ternary 2.2-bits-per-weight model and inherits every capability limit of the base quantization.
- Single task, single persona. It reviews diffs as tragedy, and that is the whole job.
- Technical accuracy is imperfect (see above). The persona is the main event.
- It requires the custom inference fork and will not load in stock llama.cpp.
- The training data is teacher-generated English prose over real GitHub diffs, so expect the usual teacher-artifact biases.
Files in this repo
| path | contents |
|---|---|
BonsaiShakespeareV3.gguf |
The model. Everything else is for inspection and reproduction. |
training_scripts/ |
Self-contained scripts that operate from the GGUF alone. |
sft_data/train_v3.jsonl |
9,253 tokenized training examples. |
sft_data/eval_v3.jsonl |
500 held-out examples. |
sft_data/full_data.jsonl |
All 9,753 examples with raw diff, think, and review text. |
Inside training_scripts/:
generate_artifacts.pyโ Hadamard signs, tokenizer, and config from GGUF metadataextract_gguf.pyโ GGUF to ternary codes, scales, and dense substratedataset.pyโ tokenization and batching for training and evalmodel.pyโ ternary loader and the rotated Hadamard linear layerlora.pyโ LoRA-STE training with hysteresis; writeslora_final.ptandqstate_final.pteval.pyโ generation over the held-out splitmerge.pyโ trit-flip merge back into a GGUF
Reproducing this
From the original base GGUF, run everything from the repo root:
python training_scripts/generate_artifacts.py --gguf Ternary-Bonsai-2-9B-Q2_0.gguf
python training_scripts/extract_gguf.py
python training_scripts/lora.py
python training_scripts/eval.py --ckpt lora_out_v3/lora_final.pt --out eval_final.jsonl
python training_scripts/merge.py --qstate lora_out_v3/qstate_final.pt \
--gguf Ternary-Bonsai-2-9B-Q2_0.gguf \
--out BonsaiShakespeareV3.gguf
This uses the included sft_data/ split. Paths and hyperparameters are defined at the top of each script.
Credits
- Base model: PrismML Ternary-Bonsai-2-9B (Qwen3.5 hybrid architecture, Q2_0 ternary quantization)
- Diff data: ronantakizawa/github-codereview
- Training, data pipeline, and merge tooling: this repo
- Downloads last month
- 348
We're not able to determine the quantization variants.
Model tree for korokoboom/Bonsai-2-9b-Shakespeare-SFT
Base model
Qwen/Qwen3.5-9B-Base