Image-Text-to-Text
Transformers
Safetensors
English
qwen3_5
text-generation-inference
llm-compressor
vllm
clef
fp8
w8a8
cloudflare
systemone
qwen3.8
post-train
image-text-to-typed-output
multimodal
structured-output
classification
custom-code
conversational
compressed-tensors
Instructions to use prithivMLmods/clef-FP8 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use prithivMLmods/clef-FP8 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="prithivMLmods/clef-FP8") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("prithivMLmods/clef-FP8") model = AutoModelForMultimodalLM.from_pretrained("prithivMLmods/clef-FP8", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use prithivMLmods/clef-FP8 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "prithivMLmods/clef-FP8" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "prithivMLmods/clef-FP8", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/prithivMLmods/clef-FP8
- SGLang
How to use prithivMLmods/clef-FP8 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "prithivMLmods/clef-FP8" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "prithivMLmods/clef-FP8", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "prithivMLmods/clef-FP8" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "prithivMLmods/clef-FP8", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use prithivMLmods/clef-FP8 with Docker Model Runner:
docker model run hf.co/prithivMLmods/clef-FP8
Update README.md
Browse files
README.md
CHANGED
|
@@ -20,4 +20,157 @@ tags:
|
|
| 20 |
- structured-output
|
| 21 |
- classification
|
| 22 |
- custom-code
|
| 23 |
-
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
- structured-output
|
| 21 |
- classification
|
| 22 |
- custom-code
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
# **clef-FP8**
|
| 26 |
+
|
| 27 |
+
FP8 (W8A8, dynamic) quantization of [Cloudflare/clef](https://huggingface.co/Cloudflare/clef),
|
| 28 |
+
a 27B multimodal model that turns a state and a schema of typed questions into decisions. Clef
|
| 29 |
+
reads text, JSON, images, or video and returns a probability for every allowed option of every
|
| 30 |
+
question in a single forward pass, with no free-form generation and no output parsing. This repo quantizes only the backbone's linear layers. The vision encoder, embeddings, `lm_head`,
|
| 31 |
+
and linear-attention layers are left in their original precision. For model behavior, input
|
| 32 |
+
format, and the Jev/SystemOne API, see the
|
| 33 |
+
[original Clef card](https://huggingface.co/Cloudflare/clef).
|
| 34 |
+
|
| 35 |
+
## Quantization
|
| 36 |
+
|
| 37 |
+
| | |
|
| 38 |
+
|---|---|
|
| 39 |
+
| **Modality** | Image-Text-to-Text |
|
| 40 |
+
| **Quantization scheme** | FP8_DYNAMIC (W8A8) |
|
| 41 |
+
| **Weights** | FP8, per-channel |
|
| 42 |
+
| **Activations** | FP8, per-token, dynamic |
|
| 43 |
+
| **Calibration data** | Not required |
|
| 44 |
+
| **Format** | compressed-tensors (safetensors) |
|
| 45 |
+
| **Tooling** | [LLM Compressor](https://github.com/vllm-project/llm-compressor) |
|
| 46 |
+
| **License** | Apache 2.0 |
|
| 47 |
+
|
| 48 |
+
| Setting | Value |
|
| 49 |
+
|---|---|
|
| 50 |
+
| **targets** | `Linear` |
|
| 51 |
+
| **ignore** | `lm_head`, `embed_tokens`, `visual`, `model.visual`, `linear_attn` |
|
| 52 |
+
| **scheme** | `FP8_DYNAMIC` |
|
| 53 |
+
| **bypass_divisibility_checks** | `false` |
|
| 54 |
+
| **requires_calibration_data** | `false` |
|
| 55 |
+
|
| 56 |
+
### recipe.yaml
|
| 57 |
+
|
| 58 |
+
```yaml
|
| 59 |
+
default_stage:
|
| 60 |
+
default_modifiers:
|
| 61 |
+
QuantizationModifier:
|
| 62 |
+
targets: [Linear]
|
| 63 |
+
ignore: ['re:.*lm_head', 're:.*embed_tokens$', 're:.*visual.*', 're:.*model.visual.*',
|
| 64 |
+
're:.*linear_attn.*']
|
| 65 |
+
scheme: FP8_DYNAMIC
|
| 66 |
+
bypass_divisibility_checks: false
|
| 67 |
+
requires_calibration_data: false
|
| 68 |
+
```
|
| 69 |
+
|
| 70 |
+
Because the scheme is `FP8_DYNAMIC`, weight scales are computed directly from the weights and
|
| 71 |
+
activation scales are computed per token at runtime. No calibration dataset is needed.
|
| 72 |
+
|
| 73 |
+
## Files
|
| 74 |
+
|
| 75 |
+
| File | Purpose |
|
| 76 |
+
|---|---|
|
| 77 |
+
| `model-*.safetensors`, `model.safetensors.index.json`, `config.json` | FP8 backbone (compressed-tensors) with the BF16 vision encoder |
|
| 78 |
+
| `recipe.yaml` | LLM Compressor recipe used for quantization |
|
| 79 |
+
| `joint_head.safetensors`, `joint_head_config.json` | Joint schema head, copied unchanged from Clef |
|
| 80 |
+
| `joint_schema_model.py` | Record encoding, batching, model, `load_release_model`, `systemone` |
|
| 81 |
+
| `tokenizer.json`, `tokenizer_config.json`, `chat_template.jinja`, `processor_config.json` | Tokenizer and image/video processor |
|
| 82 |
+
|
| 83 |
+
## Usage
|
| 84 |
+
|
| 85 |
+
Install `compressed-tensors` alongside `transformers` so the FP8 checkpoint can be loaded:
|
| 86 |
+
|
| 87 |
+
```bash
|
| 88 |
+
pip install torch transformers compressed-tensors pillow
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
Usage is the same as for Clef:
|
| 92 |
+
|
| 93 |
+
```python
|
| 94 |
+
import sys
|
| 95 |
+
|
| 96 |
+
import torch
|
| 97 |
+
from huggingface_hub import snapshot_download
|
| 98 |
+
|
| 99 |
+
path = snapshot_download("prithivMLmods/clef-FP8")
|
| 100 |
+
sys.path.insert(0, path)
|
| 101 |
+
from joint_schema_model import collate_records, encode_record, load_release_model
|
| 102 |
+
|
| 103 |
+
model, processor = load_release_model(path, device="cuda")
|
| 104 |
+
|
| 105 |
+
record = {
|
| 106 |
+
"state": {"invoice": {"vendor": "Acme", "total": 1250.0, "currency": "USD", "status": "overdue"}},
|
| 107 |
+
"questions": {
|
| 108 |
+
"status": {
|
| 109 |
+
"type": "choice",
|
| 110 |
+
"instructions": "What is the invoice status?",
|
| 111 |
+
"criteria": {"paid": "Invoice is paid.", "overdue": "Invoice is past due.", "draft": "Not sent."},
|
| 112 |
+
},
|
| 113 |
+
"large": {"type": "noul", "instructions": "Is the total above 1000 USD?"},
|
| 114 |
+
},
|
| 115 |
+
}
|
| 116 |
+
|
| 117 |
+
encoded = encode_record(processor.tokenizer, record, processor=processor)
|
| 118 |
+
batch = collate_records([encoded], processor.tokenizer.pad_token_id, torch.device("cuda"))
|
| 119 |
+
with torch.inference_mode():
|
| 120 |
+
logits = model(batch)[0]
|
| 121 |
+
|
| 122 |
+
for question, question_logits in zip(encoded.questions, logits):
|
| 123 |
+
probabilities = question_logits.float().softmax(-1).tolist()
|
| 124 |
+
print(question.question_id, dict(zip(question.option_ids, probabilities)))
|
| 125 |
+
```
|
| 126 |
+
|
| 127 |
+
The `systemone(model, processor, request)` helper and image/video inputs work as described in the
|
| 128 |
+
Clef card.
|
| 129 |
+
|
| 130 |
+
**Hardware:** FP8 W8A8 compute needs a GPU with FP8 support (Ada, Hopper, or newer). On older
|
| 131 |
+
GPUs, FP8 weights may only give memory savings, depending on the runtime.
|
| 132 |
+
|
| 133 |
+
## Reproducing the quantization
|
| 134 |
+
|
| 135 |
+
```python
|
| 136 |
+
from transformers import AutoModelForImageTextToText, AutoProcessor
|
| 137 |
+
from llmcompressor import oneshot
|
| 138 |
+
|
| 139 |
+
src = "Cloudflare/clef" # local path from snapshot_download works too
|
| 140 |
+
dst = "clef-FP8"
|
| 141 |
+
|
| 142 |
+
model = AutoModelForImageTextToText.from_pretrained(src, torch_dtype="auto", device_map="auto")
|
| 143 |
+
processor = AutoProcessor.from_pretrained(src)
|
| 144 |
+
|
| 145 |
+
oneshot(model=model, recipe="recipe.yaml") # data-free, no dataset argument
|
| 146 |
+
|
| 147 |
+
model.save_pretrained(dst, save_compressed=True)
|
| 148 |
+
processor.save_pretrained(dst)
|
| 149 |
+
```
|
| 150 |
+
|
| 151 |
+
Then copy these files from the original Clef repo into `clef-FP8/` unchanged:
|
| 152 |
+
`joint_head.safetensors`, `joint_head_config.json`, `joint_schema_model.py`.
|
| 153 |
+
|
| 154 |
+
## Evaluation
|
| 155 |
+
|
| 156 |
+
I have **not** run the Decision Index or the workflow evals on this FP8 checkpoint. The numbers
|
| 157 |
+
in the [Clef card](https://huggingface.co/Cloudflare/clef) are for the BF16 model and should not be
|
| 158 |
+
assumed to carry over exactly. FP8 dynamic quantization is generally close to lossless, but Clef
|
| 159 |
+
outputs per-option probabilities, so small shifts in calibration (confidence values) are possible
|
| 160 |
+
even when the argmax decisions match. If you depend on calibrated probabilities or thresholds,
|
| 161 |
+
validate on your own data before switching.
|
| 162 |
+
|
| 163 |
+
## Notes and limitations
|
| 164 |
+
|
| 165 |
+
- **Joint head:** the joint schema head is stored separately and is kept in its original
|
| 166 |
+
precision, because the recipe quantizes only the backbone. If you modify `load_release_model` or
|
| 167 |
+
re-export the model, make sure the head is not quantized.
|
| 168 |
+
- **Excluded modules:** `linear_attn`, the vision encoder, embeddings, and `lm_head` stay
|
| 169 |
+
unquantized, so the size reduction is somewhat smaller than a full 2x versus BF16.
|
| 170 |
+
- **Loading path:** this checkpoint is intended for the custom `joint_schema_model.py` loader.
|
| 171 |
+
General-purpose serving engines will not run the joint head.
|
| 172 |
+
|
| 173 |
+
## License
|
| 174 |
+
|
| 175 |
+
Apache-2.0, following [Cloudflare/clef](https://huggingface.co/Cloudflare/clef) and the base model
|
| 176 |
+
[Qwen/Qwen3.8-27B](https://huggingface.co/Qwen/Qwen3.8-27B).
|