FastBrain-9B / README.md
TypeScript's picture
Add native 4-bit/8-bit mixed-precision loading in joint_schema_model.py and GGUF documentation
f84a65d verified
|
Raw History Blame
10.9 kB
---
base_model: Cloudflare/clef-flash
library_name: transformers
license: apache-2.0
pipeline_tag: text-generation
tags:
- fastbrain
- clef
- gguf
- systemone
- decision-index
- tool-calling
- intent-classification
- structured-decision
---
<div align="center">
# FastBrain-9B
**Non-Autoregressive System-1 Structured Decision Model (`9.4B` Parameters)**
[![Architecture](https://img.shields.io/badge/Backbone-Qwen3.5--9B_Hybrid_(9.4B_Total)-3b82f6?style=flat-square)](#architecture)
[![Decision Head](https://img.shields.io/badge/Head-JointSchemaHead_(116M)-10b981?style=flat-square)](#architecture)
[![Decision Index](https://img.shields.io/badge/Decision_Index_v0.2.1-80.55%25_(%232_Overall_%C2%B7_%231_9B)-f59e0b?style=flat-square)](#benchmark-evaluation)
[![License](https://img.shields.io/badge/License-Apache_2.0-6366f1?style=flat-square)](./LICENSE)
</div>
**FastBrain-9B** (`9.4B` total parameters: `Qwen3.5-9B` hybrid backbone + `116M` `JointSchemaHead`) is a single-forward-pass, non-autoregressive **System-1 structured decision model**.
Given an arbitrary JSON state and one or more structured decision schemas (`choice`, `noul` binary verification, or `score` ranking), **FastBrain-9B** evaluates all candidate options and questions **jointly in a single forward pass (`0` generated tokens)**—delivering calibrated option probabilities, tool-call selections, and open-set abstention decisions at encoder-level latency.
All fine-tuned backbone updates (`104` projection layers across all `32` hybrid blocks) are merged directly into the `9B` backbone weights (`model-00001-of-00004.safetensors` .. `model-00004-of-00004.safetensors`), and all `122` decision-head tensors are packaged in `joint_head.safetensors`. **No external LoRA or PEFT adapter is required at inference time.**
---
## Benchmark Evaluation & Parameter Scale Comparison
Evaluated on the official **Cloudflare Decision Index (v0.2.1)** across **10 benchmarks (22,427 evaluation requests)**, **FastBrain-9B (`9.4B`)** achieves an overall Macro Mean of **`80.55%`**:
- **Ranks `#1` across all `<=9B` models on `10 / 10` benchmarks**, outperforming the same-size base model `Clef-flash` (`9.4B`, `74.96%`) by **`+5.59 pp`**, `Kev 9B` (`9B`, `76.51%`) by **`+4.04 pp`**, and `Laya` (`0.4B`, `58.09%`) by **`+22.46 pp`**.
- **Outperforms `3x`-larger `27B`-class models**: surpasses `Jev` (`27B`, `80.32%`) and `DiffusionGemma Jev` (`26B-A4B`, `69.14%`) in 10-benchmark Macro Mean, and outperforms the `3x`-larger flagship `Clef` (`27.4B`, `81.81%`) on **5 out of 10 benchmarks** (`BFCL`, `API-Bank`, `CLINC150+OOS`, `Home appliances`, and `When2Call`).
![FastBrain-9B Overview](./assets/benchmark_overview.png)
### Full 10-Benchmark Evaluation Matrix (Annotated by Model Parameter Scale)
![FastBrain-9B Scoreboard](./assets/benchmark_scoreboard.png)
### Fine-Grained Decision Calibration & Open-Set Reliability
![FastBrain-9B Calibration Breakdown](./assets/decision_calibration_breakdown.png)
### Summary Comparison by Model Parameter Scale
| Benchmark | Metric | `Laya`<br>*(0.4B / 421M)* | `DiffusionGemma Jev`<br>*(26B-A4B · 4B Act)* | `Clef-flash`<br>*(9.4B Base)* | `Kev 9B`<br>*(9B Dense)* | `Jev`<br>*(27B Dense)* | `Clef`<br>*(27.4B Flagship)* | **FastBrain-9B**<br>*(9.4B · Ours)* |
| :--- | :--- | :---: | :---: | :---: | :---: | :---: | :---: | :---: |
| **Parameter Scale** | **Total (Active)** | `0.42B` | `25.8B (4B MoE)` | `9.41B` | `9.0B` | `27.0B` | `27.36B` | **`9.41B`** |
| **BFCL** | Case Exact | 95.87% | 97.64% | 98.76% | 97.58% | 98.58% | 98.47% | **98.76% (#1)** |
| **ToolRet** | nDCG@10 | 51.31% | 45.28% | 67.26% | 65.72% | 65.50% | 68.18% | **67.26% (#2 · #1 9B)** |
| **API-Bank** | Accuracy | 86.22% | 85.24% | 93.11% | 89.76% | 90.35% | 91.93% | **93.70% (#1)** |
| **BANKING77** | Macro-F1 | 62.66% | 93.80% | 93.69% | 91.77% | 93.58% | 94.07% | **93.77% (#1 9B)** |
| **CLINC150+OOS** | Macro-F1 | 73.79% | 94.64% | 66.77% | 96.65% | 96.44% | 97.43% | **98.44% (#1)** |
| **Home appliances** | Case Exact | 23.86% | 68.18% | 96.59% | 88.64% | 88.64% | 96.59% | **97.73% (#1)** |
| **BRIGHT** | nDCG@10 | 25.00% | 18.69% | 38.49% | 38.53% | 43.37% | 48.03% | **38.58% (#1 9B)** |
| **Amazon ESCI** | Macro-F1 | 52.84% | 56.83% | 57.39% | 53.75% | 56.60% | 59.30% | **57.40% (#2 · #1 9B)** |
| **PhishNChips** | Accuracy | 60.45% | 55.65% | 71.95% | 72.10% | 88.20% | 91.70% | **78.75% (#1 9B)** |
| **When2Call** | Macro-F1 | 48.92% | 75.44% | 65.58% | 70.64% | 81.91% | 72.37% | **81.13% (#2 · #1 9B)** |
| **Macro Mean (10)** | **Average** | **58.09%** | **69.14%** | **74.96%** | **76.51%** | **80.32%** | **81.81%** | **80.55% (#2 · #1 9B)** |
---
## Architecture
1. **Hybrid Gated DeltaNet + Full-Attention Backbone (`9.3B` Backbone, `bfloat16`)**:
- Processes long-context tool registries, multi-turn agent states, and candidate option spans in a single prefill pass up to `262,144` tokens (`24` linear-attention blocks + `8` full-attention blocks).
- Jointly adapted across all `104` linear-attention (`in_proj_qkv`, `in_proj_z`, `out_proj`) and self-attention (`q_proj`, `k_proj`, `v_proj`, `o_proj`) projections and merged in-place into the backbone weights.
2. **Joint Schema Decision Head (`joint_head.safetensors`, `116M` Parameters)**:
- Extracts question-level and option-level span representations directly from the final hidden states and scores all questions (`choice`, `noul`, `score`) simultaneously without autoregressive decoding (`output_tokens = 0`).
3. **Compile-Time AST Schema-Aware Margin Calibration (`joint_schema_model.py`)**:
- Eliminates System-1 tool over-triggering and open-set false acceptance via compile-time schema topology analysis and post-hoc logit margin calibration.
---
## Quickstart
### 1. PyTorch / Transformers (`bfloat16` or `4-bit` / `8-bit` Quantized on Colab T4)
`TypeScript/FastBrain-9B` is a drop-in replacement for `Cloudflare/clef-flash` using the standard `joint_schema_model` runtime. It supports both full-precision `bfloat16` (`18.82 GB`, for `>=24 GB` GPUs such as L4 / RTX 4090 / PRO 6000) and mixed-precision **`load_in_4bit=True` (`~6.8 GB` VRAM, runs on a free Google Colab T4 16GB GPU)** or **`load_in_8bit=True` (`~11.2 GB` VRAM)** while keeping the `116M` `JointSchemaHead` in native `bfloat16`/`float16`:
```python
from huggingface_hub import snapshot_download
import sys
import torch
model_dir = snapshot_download("TypeScript/FastBrain-9B", ignore_patterns=["*.gguf"])
sys.path.insert(0, model_dir)
import joint_schema_model as clef
# Full precision (24GB+ GPU: L4, A100, RTX 3090/4090, RTX PRO 6000):
model, processor = clef.load_release_model(model_dir, device="cuda", dtype=torch.bfloat16)
# Or 4-bit NF4 mixed-precision (8GB–16GB GPU, e.g., free Google Colab T4):
# model, processor = clef.load_release_model(model_dir, device="cuda", dtype=torch.float16, load_in_4bit=True)
response = clef.systemone(model, processor, {
"model": "TypeScript/FastBrain-9B",
"state": {
"query": "Can you check my account balance?",
"tools": ["get_balance", "transfer_funds"],
},
"questions": {
"q": {
"type": "choice",
"query": "Select the best next action.",
"criteria": {
"a": "Call <tool_call>{\"name\": \"get_balance\", \"arguments\": {}}</tool_call>",
"b": "Could you please provide your account ID or authentication token first?",
"c": "I am unable to access personal banking records.",
},
},
},
})
print(response)
```
### 2. `llama.cpp` GGUF (`Q4_K_M` / `Q8_0` / `BF16`) via `/v1/systemone`
This repository includes official `llama.cpp` (`b11430`+ / `ClefModel`) GGUF quantizations that pack both the `Qwen3.5-9B` hybrid backbone and the `116M` `JointSchemaHead` (`dec.*` tensors preserved at `Q8_0` precision):
```bash
# Start llama-server on the /v1/systemone decision endpoint (6.04 GB Q4_K_M quant)
llama-server -hf TypeScript/FastBrain-9B:Q4_K_M --port 8080
# Query the single-forward-pass /v1/systemone endpoint
curl http://127.0.0.1:8080/v1/systemone \
-H "Content-Type: application/json" \
-d '{
"model": "FastBrain-9B",
"state": "Customer message: I was charged twice for my order last week and nobody has replied.",
"questions": {
"route": {
"type": "choice",
"instructions": "Which team should handle this?",
"criteria": {"billing": "Payments or invoices", "technical": "Bugs or outages"}
},
"urgent": {"type": "noul", "instructions": "Is the customer requesting urgent resolution?"}
}
}'
```
---
## Hardware Footprint, Quantization Tiers & Inference Speed
| Format / Precision Tier | Weight Footprint | Peak VRAM | Minimum Hardware | Typical Latency (`500–1k tok`) |
| :--- | :---: | :---: | :--- | :---: |
| **`FastBrain-9B-Q4_K_M.gguf`** *(4-bit + `Q8_0` Head)* | `6.04 GB` | `~7.2 GB` | **8GB GPU / Colab Free T4 (16GB) / Mac M1–M4** | `~90–220 ms` |
| **PyTorch `load_in_4bit=True`** *(NF4 + `fp16` Head)* | `~5.5 GB` | `~6.8 GB` | **Colab Free T4 (16GB) / RTX 3060–4060 (8GB+)** | `~180–280 ms` |
| **`FastBrain-9B-Q8_0.gguf`** *(Full 8-bit GGUF)* | `9.68 GB` | `~11.0 GB` | **12GB–16GB GPU / Colab T4 / Mac 16GB+** | `~80–180 ms` |
| **PyTorch `load_in_8bit=True`** *(INT8 + `bf16` Head)* | `~9.6 GB` | `~11.2 GB` | **Colab T4 (16GB) / RTX 4070 Ti (12GB+)** | `~130–210 ms` |
| **Native `bfloat16` (`safetensors` / `BF16.gguf`)** | `18.82 GB` (`18.16 GB`) | `20.3–24.7 GB` | **Colab L4 (24GB) / RTX 3090–4090 / PRO 6000 (96GB)** | **`38.8 ms` (`B=1`) · `61.7 ms` (`B=16` on G4 6000)** |
---
## Repository Structure
| File | Size | Description |
| :--- | :---: | :--- |
| `model-00001-of-00004.safetensors` .. `00004` | `18.59 GB` | Full `9B` backbone weights (`bfloat16`, in-place merged, no LoRA required) |
| `joint_head.safetensors` & `joint_head_config.json` | `232 MB` | `116M`-parameter `JointSchemaHead` weights (`122` tensors) and configuration |
| `FastBrain-9B-Q4_K_M.gguf` | `6.04 GB` | Recommended 4-bit GGUF (`dec.*` decision head, `ssm_`, and `attn_` preserved at `Q8_0`) |
| `FastBrain-9B-Q8_0.gguf` | `9.68 GB` | High-precision 8-bit GGUF (`ClefModel` architecture for `llama-server`) |
| `FastBrain-9B-BF16.gguf` | `18.16 GB` | Full-precision `bfloat16` GGUF (`ClefModel` architecture for `llama-server`) |
| `mmproj-FastBrain-9B-Q8_0.gguf` & `BF16.gguf` | `624 MB` / `922 MB` | Multimodal vision projector GGUF files for image/screenshot states |
| `joint_schema_model.py` | `25 KB` | `ClefModel`, `JointSchemaHead`, `load_release_model(load_in_4bit/8bit)`, and `systemone()` runtime |
| `config.json`, `tokenizer.json`, `processor_config.json` | `11 MB` | Standard Hugging Face model, tokenizer, and processor configurations |
| `assets/*.png` | `1.2 MB` | High-resolution technical benchmark and calibration charts |