hletrd commited on
Commit
c738bac
·
verified ·
1 Parent(s): 5dcff07

Add clairic-Q4_K_M.gguf

Browse files
Files changed (4) hide show
  1. .gitattributes +1 -0
  2. README.md +259 -0
  3. clairic-Q4_K_M.gguf +3 -0
  4. kl.png +0 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ clairic-Q4_K_M.gguf filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,259 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ license_link: LICENSE
4
+ base_model:
5
+ - Cloudflare/clairic
6
+ base_model_relation: quantized
7
+ library_name: gguf
8
+ pipeline_tag: image-text-to-text
9
+ tags:
10
+ - gguf
11
+ - llama-cpp
12
+ - quantized
13
+ - clairic
14
+ - qwen3_5
15
+ - multimodal
16
+ - structured-output
17
+ - information-extraction
18
+ ---
19
+
20
+ <div align="center">
21
+
22
+ <img class="block dark:hidden mx-auto" src="https://raw.githubusercontent.com/XylolabsInc/tensix-bfp-gptq/main/assets/xylolabs-lockup.svg" alt="Xylolabs" width="256" height="40">
23
+ <img class="hidden dark:block mx-auto" src="https://raw.githubusercontent.com/XylolabsInc/tensix-bfp-gptq/main/assets/xylolabs-lockup-dark.svg" alt="Xylolabs" width="256" height="40">
24
+
25
+ <h1>Clairic GGUF</h1>
26
+
27
+ [![Base model](https://img.shields.io/badge/base-Cloudflare%2Fclairic-blue)](https://huggingface.co/Cloudflare/clairic)
28
+ [![Formats](https://img.shields.io/badge/formats-Q4__K__M-5B2C83)](#files)
29
+ [![License](https://img.shields.io/badge/license-Apache--2.0-green)](https://huggingface.co/Xylolabs/clairic-GGUF/blob/main/LICENSE)
30
+ [![Code](https://img.shields.io/badge/code-llama.cpp-black)](https://github.com/ggml-org/llama.cpp)
31
+
32
+ </div>
33
+
34
+ GGUF quants of [Cloudflare/clairic](https://huggingface.co/Cloudflare/clairic) (27B, a fine-tune of [Qwen/Qwen3.8-27B](https://huggingface.co/Qwen/Qwen3.8-27B) for structured extraction) for llama.cpp, on CUDA, Metal or CPU. Stock llama.cpp runs it, with image input through the mmproj file.
35
+
36
+ - **Files:** Q4_K_M (one file with the tokenizer and chat template inside).
37
+ - **Q4_K_M:** KL 0.0518 from the f32 reference, top-1 93.93 %.
38
+ - **Cloudflare's description:** [below](#cloudflares-original-model-description), unchanged.
39
+
40
+ ## Files
41
+
42
+ - `clairic-<QUANT>.gguf` is one file per quant: the language model.
43
+
44
+ | Quant | Size | PPL | Mean KL vs f32 reference | Same top-1 vs f32 reference |
45
+ |---|---|---|---|---|
46
+ | Q4_K_M | 16.78 GB | 10.9329 | 0.0518 | 93.93% |
47
+
48
+ How we measured:
49
+
50
+ - **Reference:** the model in transformers with f32 compute on Cloudflare's BF16 weights (PPL 10.5470).
51
+ - **KL, top-1, PPL:** 12 chunks of 4,096 tokens, scoring positions 2,048 to 4,095 of each (24,564 tokens): 9 held-out chat-formatted chunks (English, Korean, code, math, JSON extraction from a schema, and Clairic's own field-extraction prompts) and 3 from wikitext-2.
52
+
53
+ ![Mean KL and same top-1 against the f32 reference by file size](kl.png)
54
+
55
+ ## The extraction head
56
+
57
+ Cloudflare's typed extraction head (`clair_head.safetensors`) and their Python runtime need the original weights and are not in these files. These files hold the language model and the vision encoder.
58
+
59
+ ## How to run
60
+
61
+ ```sh
62
+ llama-server -m clairic-Q4_K_M.gguf --mmproj mmproj-clairic-BF16.gguf \
63
+ --jinja -ngl 99 -c 32768 --chat-template-kwargs '{"enable_thinking":false}'
64
+ ```
65
+
66
+ Run it with thinking off, as above, the way Cloudflare's runtime does. For JSON that follows a schema, pass the schema in the request (`response_format` with `json_schema` in llama-server, or `--json-schema` in llama-cli); llama.cpp turns it into a grammar.
67
+
68
+ ## How these were made
69
+
70
+ 1. Convert Cloudflare's BF16 checkpoint with llama.cpp's `convert_hf_to_gguf.py --no-mtp` (commit `e4b620af19f02960dea7a3a81de7c5805aa3a333`), and the vision encoder with `--mmproj` (BF16). The checkpoint's multi-token-prediction block is left out, as Cloudflare's config turns it off.
71
+ 2. Build the importance matrix with `llama-imatrix`: 300 chunks of 4,096 tokens of chat-formatted text rendered with the model's template, thinking off (databricks-dolly-15k in English, KoAlpaca-v1.1a in Korean, python_code_instructions_18k_alpaca for code, gsm8k for math, MasterControlAIML/JSON-Unstructured-Structured for schema-guided JSON, and paraloq/json_data_extraction as Clairic's field-extraction prompts), with `--process-output`.
72
+ 3. Make each quant with `llama-quantize --imatrix IM --tensor-type ssm_beta_alpha=f16 <bf16 gguf> <out> <QUANT>` (Q8_0 without the importance matrix): every weight matrix gets llama.cpp's own mix for that type; the Gated DeltaNet beta/alpha projection stays F16 (all but 0.033 % of its BF16 values are exact in F16, the largest difference 3e-8); norms, `ssm_a`, `ssm_dt` and the conv1d kernels stay F32.
73
+
74
+ The model: 26.90B parameters in the language model and 0.46B in the vision encoder; 64 layers (48 Gated DeltaNet linear-attention layers, 16 full-attention layers), 24 query and 4 KV heads of dimension 256, hidden size 5,120, context 262,144, vocabulary 248,320.
75
+
76
+ ## License and notices
77
+
78
+ - **License:** Apache-2.0, copied in `LICENSE` (Cloudflare's text).
79
+ - **What we changed:** we quantized the weights and converted them to GGUF.
80
+ - **Notices:** `NOTICE` names the source model and its copyright holders.
81
+ - Xylolabs is not affiliated with or endorsed by Cloudflare.
82
+
83
+ ## Cloudflare's original model description
84
+
85
+ This section is Cloudflare's model card, copied from [Cloudflare/clairic](https://huggingface.co/Cloudflare/clairic) (Apache-2.0).
86
+
87
+ - It describes Cloudflare's original model, not these files. Its usage code needs the original weights and Cloudflare's runtime; for the GGUF files, see "How to run" above.
88
+ - We changed only the heading levels (two deeper).
89
+
90
+
91
+ ### Clairic
92
+
93
+ Clairic is a 27B multimodal model that turns a state and a schema of typed fields
94
+ into structured answers. It supports text and image inputs, extraction, numerical
95
+ estimation, and forecasting. Each field has its own value and scoring information;
96
+ the response also reports input truncation and token usage.
97
+
98
+ See [Clairic Flash](https://huggingface.co/Cloudflare/clairic-flash) for the other model
99
+ in the Clairic family.
100
+
101
+ #### Model
102
+
103
+ - **Base model:** [Qwen3.8-27B](https://huggingface.co/Qwen/Qwen3.8-27B).
104
+ - **Inputs:** a text or JSON state, optional images, and a mapping of field names to specifications.
105
+ - **Outputs:** typed values, lists, nulls, estimates, and forecast paths.
106
+ - **Scoring:** extraction confidence and null probabilities, plus optional quantiles for estimates.
107
+ - **Runtime:** PyTorch and Transformers, with local Python request helpers.
108
+
109
+ #### Usage
110
+
111
+ Use Python 3.11 or later and install the packages listed in `requirements.txt`. Inference uses PyTorch and
112
+ Transformers; `xgrammar` supplies schema constraints through a Transformers logits
113
+ processor.
114
+
115
+ Download the repository, load the model and processor, and call `systemone` with a
116
+ System One: Extract request.
117
+
118
+ ```python
119
+ import sys
120
+
121
+ from huggingface_hub import snapshot_download
122
+
123
+ path = snapshot_download("Cloudflare/clairic")
124
+ sys.path.insert(0, path)
125
+ from clairic_model import load_release_model, systemone
126
+
127
+ model, processor = load_release_model(path, device="cuda")
128
+
129
+ response = systemone(
130
+ model,
131
+ processor,
132
+ {
133
+ "state": (
134
+ "Invoice from Northwind Supply. Issued 2026-09-02. "
135
+ "Items: Pens; Paper. Total: $1080.00."
136
+ ),
137
+ "fields": {
138
+ "vendor": {"type": "text", "instructions": "The invoice vendor."},
139
+ "total": {"type": "number", "decimals": 2},
140
+ "issued": {"type": "date"},
141
+ "items": {
142
+ "type": "list",
143
+ "items": "text",
144
+ "instructions": "The purchased item names, in order.",
145
+ },
146
+ },
147
+ },
148
+ )
149
+ print(response["answers"])
150
+ ```
151
+
152
+ ##### Images
153
+
154
+ Pass PIL images alongside the state. Embedded base64 image inputs are also accepted.
155
+
156
+ ```python
157
+ from PIL import Image
158
+
159
+ response = systemone(
160
+ model,
161
+ processor,
162
+ {
163
+ "state": "Read the attached receipt.",
164
+ "images": [Image.open("receipt.png")],
165
+ "fields": {
166
+ "merchant": {"type": "text", "instructions": "The merchant name."},
167
+ "total": {"type": "number", "decimals": 2},
168
+ },
169
+ },
170
+ )
171
+ print(response["answers"])
172
+ ```
173
+
174
+ ##### Estimates and forecasts
175
+
176
+ Declare a range for estimated values. Forecasts also specify a horizon and interval.
177
+ Set `include_quantiles` to return the available quantiles.
178
+
179
+ ```python
180
+ response = systemone(
181
+ model,
182
+ processor,
183
+ {
184
+ "state": "Daily demand for the last seven days: 41, 45, 43, 47, 49, 46, 48.",
185
+ "fields": {
186
+ "next_day": {"type": "estimate", "min": 0, "max": 100},
187
+ "next_three_days": {
188
+ "type": "forecast",
189
+ "min": 0,
190
+ "max": 100,
191
+ "horizon": 3,
192
+ "interval": "day",
193
+ },
194
+ },
195
+ "options": {"include_quantiles": True},
196
+ },
197
+ )
198
+ print(response["answers"])
199
+ ```
200
+
201
+ #### Input format
202
+
203
+ | Field | Description |
204
+ |---|---|
205
+ | `model` | Optional `clairic` or serving alias `clairic-27b`; `@cf/cloudflare/` aliases are accepted |
206
+ | `state` | Source text; the Python helper serializes JSON values to text |
207
+ | `images` | Optional PIL images or embedded base64 images |
208
+ | `documents` | Optional embedded PDF data URIs or `content_type` / `base64` objects |
209
+ | `fields` | Mapping of output field names to typed specifications |
210
+ | `reference_date` | Optional ISO date for relative date instructions |
211
+ | `options.include_quantiles` | Include available estimate and forecast quantiles |
212
+ | `options.return_state_text` | Include the retained source text in the response |
213
+
214
+ Field specifications support `text`, `number`, `date`, `time`, `datetime`, `duration`,
215
+ `boolean`, `enum`, `object`, `list`, `compute`, `estimate`, and `forecast`.
216
+ `instructions` describes what to return. Numeric fields can specify units and
217
+ rounding; lists declare their item schema; estimates and forecasts require bounds.
218
+ `nullable` defaults to true. `source_only: true` selects literal printed numbers,
219
+ dates, times, datetimes, or number/date lists. `knowledge: true` permits knowledge
220
+ answers for text, numbers, and supported list children. `compute` selects the typed
221
+ numeric head. Unsupported options and invalid combinations are rejected.
222
+
223
+ Embedded inputs are limited to 4 MiB each and 8 MiB combined. Images and rendered
224
+ PDF pages share a four-image/page limit. Image `rotation` accepts 0, 90, 180, or 270
225
+ clockwise degrees after EXIF orientation. Remote media URLs are not accepted.
226
+
227
+ #### Response
228
+
229
+ `systemone` returns a dictionary with `model`, `answers`, `truncated`, and `usage`.
230
+ Answers are keyed by the requested field names. Generated scalar extraction answers
231
+ retain `valid`, `complete`, full-sequence `confidence`, and independently scored `p_null`.
232
+ Uniquely matched text evidence includes character spans in `state`; image-only or
233
+ ambiguous evidence has null spans. Lists preserve item order and duplicates.
234
+ Estimates and forecasts include their typed values and, when requested, quantiles.
235
+
236
+ Scores are model probabilities and should be evaluated for the application's own
237
+ acceptance thresholds. Inspect `truncated` and any answer completeness indicators
238
+ before relying on a result.
239
+
240
+ Usage includes retries and supplemental work. The response model ID is `clairic`.
241
+ The Python API raises validation or request errors for invalid inputs, a queue-full
242
+ error for simultaneous requests, and an inference error for failed generation.
243
+ Use `await model.predict_async(request)` in an async application; cancellation
244
+ drains owned work before admitting another request.
245
+
246
+ #### Files
247
+
248
+ | File | Purpose |
249
+ |---|---|
250
+ | `model*.safetensors`, `model.safetensors.index.json`, `config.json` | Model weights and configuration |
251
+ | `clair_head.safetensors`, `clair_head_config.json` | Typed output components |
252
+ | `clairic_model.py` and supporting Python modules | Transformers loading and request handling |
253
+ | Tokenizer and processor files | Text and image preprocessing |
254
+ | `requirements.txt` | Python dependencies |
255
+ | `LICENSE` | Apache-2.0 license |
256
+
257
+ #### License
258
+
259
+ Released under the Apache-2.0 license.
clairic-Q4_K_M.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ebf84adb20098f0ba8c4c0aa6a29afd036f71d75bb661750cb78289bc2ce5263
3
+ size 16775952192
kl.png ADDED