Text Generation
MLX
Safetensors
English
prism_hadamard_qwen35
prism-hadamard-qwen35
ternary
qwen3.5
swift-bonsai-2
speculative-decoding
apple-silicon
conversational
Instructions to use EngineeringWithJay/Swift-Bonsai-2-27B-MLX with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- MLX
How to use EngineeringWithJay/Swift-Bonsai-2-27B-MLX 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("EngineeringWithJay/Swift-Bonsai-2-27B-MLX") 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 EngineeringWithJay/Swift-Bonsai-2-27B-MLX with Pi:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "EngineeringWithJay/Swift-Bonsai-2-27B-MLX"
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": "EngineeringWithJay/Swift-Bonsai-2-27B-MLX" } ] } } }Run Pi
# Start Pi in your project directory: pi
- MLX LM
How to use EngineeringWithJay/Swift-Bonsai-2-27B-MLX with MLX LM:
Generate or start a chat session
# Install MLX LM uv tool install mlx-lm # Interactive chat REPL mlx_lm.chat --model "EngineeringWithJay/Swift-Bonsai-2-27B-MLX"
Run an OpenAI-compatible server
# Install MLX LM uv tool install mlx-lm # Start the server mlx_lm.server --model "EngineeringWithJay/Swift-Bonsai-2-27B-MLX" # Calling the OpenAI-compatible server with curl curl -X POST "http://localhost:8080/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "EngineeringWithJay/Swift-Bonsai-2-27B-MLX", "messages": [ {"role": "user", "content": "Hello"} ] }' - Hermes Agent
How to use EngineeringWithJay/Swift-Bonsai-2-27B-MLX 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 "EngineeringWithJay/Swift-Bonsai-2-27B-MLX"
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 EngineeringWithJay/Swift-Bonsai-2-27B-MLX
Run Hermes
hermes
- Atomic Chat
- OpenClaw
How to use EngineeringWithJay/Swift-Bonsai-2-27B-MLX with OpenClaw:
Start the MLX server
# Install MLX LM: uv tool install mlx-lm # Start a local OpenAI-compatible server: mlx_lm.server --model "EngineeringWithJay/Swift-Bonsai-2-27B-MLX"
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 "EngineeringWithJay/Swift-Bonsai-2-27B-MLX" \ --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"
Download runtime/artifact.py from EngineeringWithJay/Swift-Bonsai-2-27B-MLX: direct link, hf CLI and curl.
- Browser
- Download file 5.63 kB
-
https://huggingface.co/EngineeringWithJay/Swift-Bonsai-2-27B-MLX/resolve/main/runtime/artifact.py
- Command line
-
hf download hf://EngineeringWithJay/Swift-Bonsai-2-27B-MLX/runtime/artifact.py
-
curl -L -o artifact.py https://huggingface.co/EngineeringWithJay/Swift-Bonsai-2-27B-MLX/resolve/main/runtime/artifact.py
5.63 kB
| """Save and reload MLX packs with an explicit matching-runtime requirement.""" | |
| import json | |
| import shutil | |
| from pathlib import Path | |
| import mlx.core as mx | |
| from mlx.utils import tree_flatten | |
| from mlx_lm.models.qwen3_5 import TextModel, TextModelArgs | |
| from runtime import Packed | |
| from mlx import nn | |
| def save_model(model, info, tokenizer_path, directory): | |
| directory = Path(directory) | |
| modules = [] | |
| for name, module in model.named_modules(): | |
| if isinstance(module, Packed): | |
| if module.dtype != mx.float16: | |
| raise ValueError("Only float16 packed artifacts are supported") | |
| modules.append( | |
| { | |
| "path": name, | |
| "block": module.block, | |
| "embedding": module.embedding, | |
| "dtype": "float16", | |
| } | |
| ) | |
| config = { | |
| "schema_version": 1, | |
| "model_type": "prism_hadamard_qwen35", | |
| "requires_runtime": "examples/python/hadamard/artifact.py", | |
| "text_config": info["config"], | |
| "modules": modules, | |
| "quantization": {"bits": 2, "group_size": 128, "mode": "affine"}, | |
| } | |
| directory.mkdir(parents=True, exist_ok=False) | |
| mx.save_safetensors( | |
| str(directory / "model.safetensors"), | |
| dict(tree_flatten(model.parameters())), | |
| metadata={"format": "mlx"}, | |
| ) | |
| (directory / "config.json").write_text(json.dumps(config, indent=2)) | |
| shutil.copyfile(tokenizer_path, directory / "tokenizer.json") | |
| (directory / "README.md").write_text( | |
| "# Experimental folded MLX pack\n\nRequires the accompanying Hadamard-aware loader. Do not load as an ordinary affine Qwen checkpoint: that would omit activation and inverse-embedding transforms. The source numerical and performance reports are separate from serialization integrity.\n" | |
| ) | |
| return config | |
| def validate_record(original, record, arrays, signs): | |
| if not isinstance(original, (nn.Linear, nn.Embedding)): | |
| raise ValueError("Unsupported packed module target") | |
| if record["embedding"] != isinstance(original, nn.Embedding): | |
| raise ValueError("Packed module kind mismatch") | |
| rows, width = original.weight.shape | |
| if width % 128: | |
| raise ValueError("Invalid packed width") | |
| expected = [(rows, width // 16), (rows, width // 128), (rows, width // 128)] | |
| if [a.shape for a in arrays] != expected or arrays[0].dtype != mx.uint32: | |
| raise ValueError("Invalid packed tensor shapes or storage dtype") | |
| for array in arrays[1:]: | |
| if array.dtype not in (mx.float16, mx.float32, mx.bfloat16): | |
| raise ValueError("Invalid affine dtype") | |
| if not mx.all(mx.isfinite(array)).item(): | |
| raise ValueError("Non-finite affine parameters") | |
| block = record["block"] | |
| if block: | |
| if width % block or signs is None or signs.shape != (width,): | |
| raise ValueError("Invalid transform dimensions") | |
| if not mx.all((signs == 1) | (signs == -1)).item(): | |
| raise ValueError("Invalid sign values") | |
| elif signs is not None: | |
| raise ValueError("Unexpected sign vector") | |
| def load_model(directory): | |
| directory = Path(directory) | |
| config = json.loads((directory / "config.json").read_text()) | |
| if ( | |
| config.get("schema_version") not in (1, 2) | |
| or config.get("model_type") != "prism_hadamard_qwen35" | |
| ): | |
| raise ValueError("Unsupported packed model schema") | |
| model = TextModel(TextModelArgs.from_dict(config["text_config"])) | |
| weights = mx.load(str(directory / "model.safetensors")) | |
| seen = set() | |
| for record in config["modules"]: | |
| if record["path"] in seen: | |
| raise ValueError("Duplicate packed module") | |
| seen.add(record["path"]) | |
| parts = record["path"].split(".") | |
| parent = model | |
| for part in parts[:-1]: | |
| parent = parent[int(part)] if part.isdigit() else getattr(parent, part) | |
| name = record["path"] | |
| arrays = [ | |
| weights[name + "." + suffix] for suffix in ("weight", "scales", "biases") | |
| ] | |
| if record["dtype"] != "float16": | |
| raise ValueError("Unsupported activation dtype") | |
| block = record["block"] | |
| if block and block not in (512, 1024, 2048, 4096): | |
| raise ValueError("Unsupported block size") | |
| signs = weights.get(name + ".signs") | |
| if block and signs is None: | |
| raise ValueError("Missing sign vector") | |
| original = getattr(parent, parts[-1]) | |
| validate_record(original, record, arrays, signs) | |
| setattr( | |
| parent, | |
| parts[-1], | |
| Packed(arrays, block, signs, record["embedding"], mx.float16), | |
| ) | |
| model.load_weights(list(weights.items()), strict=True) | |
| model.eval() | |
| mx.eval(model.parameters()) | |
| return model, config | |
| def save_and_verify(model, info, tokenizer_path, directory, input_ids): | |
| import numpy as np | |
| config = save_model(model, info, tokenizer_path, directory) | |
| reloaded, _ = load_model(directory) | |
| x = mx.array([input_ids], dtype=mx.int32) | |
| def evaluate(m): | |
| hidden = m.model(x, cache=m.make_cache()) | |
| y = m.lm_head(hidden[:, -1:, :]) | |
| mx.eval(y) | |
| return np.asarray(y) | |
| expected = evaluate(model) | |
| actual = evaluate(reloaded) | |
| np.testing.assert_array_equal(actual, expected) | |
| result = { | |
| "reload_logits_exact": True, | |
| "checked_logits": actual.size, | |
| "packed_modules": len(config["modules"]), | |
| } | |
| Path(directory, "reload-validation.json").write_text(json.dumps(result, indent=2)) | |
| return result | |