Text Generation
MLX
Safetensors
prism_hadamard_qwen35
abliterated
mixed-precision
bonsai
conversational
Instructions to use KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit with MLX:
# Make sure mlx-lm is installed # pip install --upgrade mlx-lm # Generate text with mlx-lm from mlx_lm import load, generate model, tokenizer = load("KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit") prompt = "Write a story about Einstein" messages = [{"role": "user", "content": prompt}] prompt = tokenizer.apply_chat_template( messages, add_generation_prompt=True ) text = generate(model, tokenizer, prompt=prompt, verbose=True) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- LM Studio
- Pi
How to use KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit"
Configure the model in Pi
# Install Pi: npm install -g @earendil-works/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "mlx-lm": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit with Hermes Agent:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit"
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:8080/v1 hermes config set model.default KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit"
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:8080/v1 \ --custom-model-id "KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit" \ --custom-provider-id mlx-lm \ --custom-compatibility openai \ --custom-text-input \ --accept-risk \ --skip-health
Run OpenClaw
openclaw agent --local --agent main --message "Hello from Hugging Face"
Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit / compact /compress_adapter.py
Download compact/compress_adapter.py from KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit: direct link, hf CLI and curl.
- Browser
- Download file 4.79 kB
-
https://huggingface.co/KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit/resolve/main/compact/compress_adapter.py
- Command line
-
hf download hf://KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit/compact/compress_adapter.py
-
curl -L -o compress_adapter.py https://huggingface.co/KridgeDookie/Ternary-Bonsai-2-27B-ABLITERATED-UNCENSORED-PHILADELPHIA-CLASS-MLX-Mixed-2-4bit/resolve/main/compact/compress_adapter.py
4.79 kB
| """Approximate the verified mixed-Q8 edit as a small additive adapter. | |
| This is a new candidate, not an exact reconstruction of the BF16 surgery. | |
| Only exported-model behavioral evaluation may qualify it for publication. | |
| """ | |
| import json, math, time | |
| from pathlib import Path | |
| import numpy as np | |
| import torch | |
| from safetensors import safe_open | |
| from safetensors.torch import save_file | |
| from gguf import GGUFWriter | |
| R=Path('/workspace/bonsai2') | |
| if (R/'ADAPTERS_READY').exists():raise SystemExit(0) | |
| torch.manual_seed(1337) | |
| torch.set_num_threads(8) | |
| torch.backends.cuda.matmul.allow_tf32=False | |
| cfg=json.loads((R/'source_mlx/config.json').read_text()) | |
| src=safe_open(R/'source_mlx/model.safetensors',framework='pt',device='cpu') | |
| ref=safe_open(R/'reference/model.safetensors',framework='pt',device='cpu') | |
| ranks=(8,16,32) | |
| packs={rank:{} for rank in ranks} | |
| writers={} | |
| out=R/'adapters';out.mkdir(exist_ok=True) | |
| for rank in ranks: | |
| w=GGUFWriter(str(out/f'bonsai2-compact-r{rank}.gguf'),'qwen35') | |
| w.add_type('adapter');w.add_string('adapter.type','lora') | |
| w.add_float32('adapter.lora.alpha',float(rank)) | |
| w.add_name(f'Bonsai 2 Philadelphia compact rank {rank} correction') | |
| writers[rank]=w | |
| def decode(f,key,bits,group): | |
| p=f.get_tensor(key+'.weight').to(device='cuda',dtype=torch.int64) | |
| s=f.get_tensor(key+'.scales').cuda().float() | |
| b=f.get_tensor(key+'.biases').cuda().float() | |
| shifts=bits*torch.arange(32//bits,device='cuda',dtype=torch.int64) | |
| x=((p[...,None]>>shifts)&((1<<bits)-1)).float().reshape(p.shape[0],-1,group) | |
| return (x*s[...,None]+b[...,None]).reshape(p.shape[0],-1) | |
| def inverse_hadamard(x,block,signs): | |
| shape=x.shape;z=x.reshape(-1,block).clone();h=1 | |
| while h<block: | |
| v=z.reshape(-1,block//(2*h),2*h) | |
| a,b=v[...,:h].clone(),v[...,h:].clone() | |
| v[...,:h]=a+b;v[...,h:]=a-b;h*=2 | |
| return z.reshape(shape)/math.sqrt(block)*signs | |
| rows=[];started=time.time() | |
| for record in cfg['modules']: | |
| path=record['path'];parts=path.split('.') | |
| if len(parts)!=5 or parts[:2]!=['model','layers']:continue | |
| layer=int(parts[2]);component='.'.join(parts[3:]) | |
| stem={'mlp.down_proj':'ffn_down','self_attn.o_proj':'attn_output','linear_attn.out_proj':'ssm_out'}.get(component) | |
| if layer==0 or stem is None:continue | |
| key='language_model.'+path | |
| original=decode(src,key,2,128) | |
| if record['block']: | |
| original=inverse_hadamard(original,record['block'],src.get_tensor(key+'.signs').cuda().float()) | |
| target=decode(ref,key,8,32) | |
| delta=target-original | |
| u,s,v=torch.svd_lowrank(delta,q=40,niter=4) | |
| order=torch.argsort(s,descending=True);u=u[:,order];s=s[order];v=v[:,order] | |
| entry={'module':path,'shape':list(delta.shape),'delta_relative_norm':float(delta.norm()/target.norm()),'ranks':{}} | |
| probe=torch.randn(16,delta.shape[1],device='cuda') | |
| for rank in ranks: | |
| root=s[:rank].sqrt() | |
| a=(v[:,:rank]*root).T.contiguous().half() | |
| b=(u[:,:rank]*root).contiguous().half() | |
| assert torch.isfinite(a).all() and torch.isfinite(b).all() | |
| approx=b.float()@a.float() | |
| entry['ranks'][str(rank)]={'residual_relative_to_target':float((delta-approx).norm()/target.norm()),'delta_energy_captured':float(1-(delta-approx).square().sum()/delta.square().sum()),'probe_relative_error':float(((probe@original.T+(probe@a.float().T)@b.float().T)-(probe@target.T)).norm()/(probe@target.T).norm())} | |
| packs[rank][key+'.lora_a']=a.cpu();packs[rank][key+'.lora_b']=b.cpu() | |
| native_a=a | |
| if component=='linear_attn.out_proj': | |
| perm=torch.arange(a.shape[1],device='cuda').reshape(3,16,128).transpose(0,1).reshape(-1) | |
| native_a=a[:,torch.argsort(perm)] | |
| name=f'blk.{layer}.{stem}.weight' | |
| writers[rank].add_tensor(name+'.lora_a',native_a.cpu().numpy()) | |
| writers[rank].add_tensor(name+'.lora_b',b.cpu().numpy()) | |
| rows.append(entry) | |
| print('COMPRESSED',len(rows),path,entry['ranks']['8'],flush=True) | |
| del original,target,delta,u,s,v,approx | |
| assert len(rows)==126,len(rows) | |
| for rank in ranks: | |
| save_file(packs[rank],str(out/f'bonsai2-compact-r{rank}.safetensors')) | |
| w=writers[rank];w.write_header_to_file();w.write_kv_data_to_file();w.write_tensors_to_file();w.close() | |
| receipt={'method':'randomized SVD of canonical mixed-Q8 minus decoded original ternary weights','seed':1337,'svd_q':40,'svd_power_iterations':4,'ranks':ranks,'modules':126,'source_revision':'3f926b415992eaa2ae9dd7b573706494d6bbf787','reference_revision':'61231c9a2feed6457f47d1d50a691b8dc96b2613','gguf_adapter_input_basis':'canonical, cyclic GDN columns','mlx_adapter_input_basis':'canonical, grouped GDN columns','seconds':time.time()-started,'rows':rows} | |
| (out/'compression.json').write_text(json.dumps(receipt,indent=2)) | |
| (R/'ADAPTERS_READY').touch() | |