Image-Text-to-Text
Transformers
Safetensors
qwen3_5
clairic
cloudflare
systemone
multimodal
structured-output
information-extraction
custom-code
conversational
Instructions to use Cloudflare/clairic-flash with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use Cloudflare/clairic-flash with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="Cloudflare/clairic-flash") 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("Cloudflare/clairic-flash") model = AutoModelForMultimodalLM.from_pretrained("Cloudflare/clairic-flash", 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 Cloudflare/clairic-flash with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Cloudflare/clairic-flash" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Cloudflare/clairic-flash", "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/Cloudflare/clairic-flash
- SGLang
How to use Cloudflare/clairic-flash 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 "Cloudflare/clairic-flash" \ --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": "Cloudflare/clairic-flash", "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 "Cloudflare/clairic-flash" \ --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": "Cloudflare/clairic-flash", "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 Cloudflare/clairic-flash with Docker Model Runner:
docker model run hf.co/Cloudflare/clairic-flash
Download clairic_runtime/gdn/chunk_o.py from Cloudflare/clairic-flash: direct link, hf CLI and curl.
- Browser
- Download file 5.04 kB
-
https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/gdn/chunk_o.py
- Command line
-
hf download hf://Cloudflare/clairic-flash/clairic_runtime/gdn/chunk_o.py
-
curl -L -o chunk_o.py https://huggingface.co/Cloudflare/clairic-flash/resolve/main/clairic_runtime/gdn/chunk_o.py
5.04 kB
| # Adapted from https://github.com/fla-org/flash-linear-attention/blob/main/fla/ops/common/chunk_o.py | |
| # -*- coding: utf-8 -*- | |
| # Copyright (c) 2023-2025, Songlin Yang, Yu Zhang | |
| # Standalone import layout; see LICENSES and NOTICE for retained notices. | |
| from typing import Optional | |
| import torch | |
| import triton | |
| import triton.language as tl | |
| from .index import prepare_chunk_indices | |
| from .op import exp, safe_exp | |
| from .utils import check_shared_mem, is_nvidia_hopper | |
| BKV_LIST = [64, 128] if check_shared_mem() else [32, 64] | |
| NUM_WARPS = [2, 4] if is_nvidia_hopper else [2, 4, 8] | |
| # @triton.autotune( | |
| # configs=[ | |
| # triton.Config({"BK": BK, "BV": BV}, num_warps=num_warps, num_stages=num_stages) | |
| # for BK in BKV_LIST | |
| # for BV in BKV_LIST | |
| # for num_warps in NUM_WARPS | |
| # for num_stages in [2, 3, 4] | |
| # ], | |
| # key=["H", "K", "V", "BT"], | |
| # ) | |
| def chunk_fwd_kernel_o( | |
| q: tl.tensor, | |
| k: tl.tensor, | |
| v: tl.tensor, | |
| h: tl.tensor, | |
| g: tl.tensor, | |
| o: tl.tensor, | |
| cu_seqlens: tl.tensor, | |
| chunk_indices: tl.tensor, | |
| scale: tl.float32, | |
| T: tl.int32, | |
| H: tl.constexpr, | |
| Hg: tl.constexpr, | |
| K: tl.constexpr, | |
| V: tl.constexpr, | |
| BT: tl.constexpr, | |
| BK: tl.constexpr, | |
| BV: tl.constexpr, | |
| USE_G: tl.constexpr, | |
| IS_VARLEN: tl.constexpr, | |
| ) -> None: | |
| i_v, i_t, i_bh = tl.program_id(0), tl.program_id(1), tl.program_id(2) | |
| i_b, i_h = i_bh // H, i_bh % H | |
| if IS_VARLEN: | |
| i_tg = i_t | |
| i_n, i_t = tl.load(chunk_indices + i_t * 2).to(tl.int32), tl.load( | |
| chunk_indices + i_t * 2 + 1 | |
| ).to(tl.int32) | |
| bos, eos = tl.load(cu_seqlens + i_n).to(tl.int32), tl.load( | |
| cu_seqlens + i_n + 1 | |
| ).to(tl.int32) | |
| T = eos - bos | |
| NT = tl.cdiv(T, BT) | |
| else: | |
| NT = tl.cdiv(T, BT) | |
| i_tg = i_b * NT + i_t | |
| bos, eos = i_b * T, i_b * T + T | |
| # offset calculation | |
| q += (bos * Hg + i_h // (H // Hg)) * K | |
| k += (bos * Hg + i_h // (H // Hg)) * K | |
| v += (bos * H + i_h) * V | |
| o += (bos * H + i_h) * V | |
| h += (i_tg * H + i_h).to(tl.int64) * V * K | |
| b_o = tl.zeros([BT, BV], dtype=tl.float32) | |
| b_A = tl.zeros([BT, BT], dtype=tl.float32) | |
| for i_k in range(tl.cdiv(K, BK)): | |
| p_q = tl.make_block_ptr( | |
| q, (T, K), (Hg * K, 1), (i_t * BT, i_k * BK), (BT, BK), (1, 0) | |
| ) | |
| p_k = tl.make_block_ptr( | |
| k, (K, T), (1, Hg * K), (i_k * BK, i_t * BT), (BK, BT), (0, 1) | |
| ) | |
| p_h = tl.make_block_ptr( | |
| h, (V, K), (K, 1), (i_v * BV, i_k * BK), (BV, BK), (1, 0) | |
| ) | |
| # [BT, BK] | |
| b_q = tl.load(p_q, boundary_check=(0, 1)) | |
| # [BK, BT] | |
| b_k = tl.load(p_k, boundary_check=(0, 1)) | |
| # [BV, BK] | |
| b_h = tl.load(p_h, boundary_check=(0, 1)) | |
| # [BT, BK] @ [BK, BV] -> [BT, BV] | |
| b_o += tl.dot(b_q, tl.trans(b_h)) | |
| # [BT, BK] @ [BK, BT] -> [BT, BT] | |
| b_A += tl.dot(b_q, b_k) | |
| if USE_G: | |
| g += bos * H + i_h | |
| p_g = tl.make_block_ptr(g, (T,), (H,), (i_t * BT,), (BT,), (0,)) | |
| b_g = tl.load(p_g, boundary_check=(0,)) | |
| b_o = b_o * exp(b_g)[:, None] | |
| b_A = b_A * safe_exp(b_g[:, None] - b_g[None, :]) | |
| o_i = tl.arange(0, BT) | |
| m_A = o_i[:, None] >= o_i[None, :] | |
| b_A = tl.where(m_A, b_A, 0) | |
| p_v = tl.make_block_ptr( | |
| v, (T, V), (H * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0) | |
| ) | |
| p_o = tl.make_block_ptr( | |
| o, (T, V), (H * V, 1), (i_t * BT, i_v * BV), (BT, BV), (1, 0) | |
| ) | |
| b_v = tl.load(p_v, boundary_check=(0, 1)) | |
| # to fix mma -> mma layout conversion | |
| # already solved by triton v3.2 or higher | |
| b_o = b_o * scale + tl.dot(b_A.to(b_v.dtype), b_v) * scale | |
| tl.store(p_o, b_o.to(p_o.dtype.element_ty), boundary_check=(0, 1)) | |
| def chunk_fwd_o( | |
| q: torch.Tensor, | |
| k: torch.Tensor, | |
| v: torch.Tensor, | |
| h: torch.Tensor, | |
| g: Optional[torch.Tensor] = None, # cumsum of log decay | |
| scale: Optional[float] = None, | |
| cu_seqlens: Optional[torch.LongTensor] = None, | |
| chunk_size: int = 64, | |
| ) -> torch.Tensor: | |
| B, T, Hg, K, V = *q.shape, v.shape[-1] | |
| H = v.shape[-2] | |
| BT = min(chunk_size, max(16, triton.next_power_of_2(T))) | |
| chunk_indices = ( | |
| prepare_chunk_indices(cu_seqlens, BT) if cu_seqlens is not None else None | |
| ) | |
| NT = triton.cdiv(T, BT) if cu_seqlens is None else len(chunk_indices) | |
| if scale is None: | |
| scale = k.shape[-1] ** -0.5 | |
| o = torch.zeros_like(v) | |
| def grid(meta: dict[str, int]) -> tuple[int, int, int]: | |
| return (triton.cdiv(V, meta["BV"]), NT, B * H) | |
| chunk_fwd_kernel_o[grid]( | |
| q, | |
| k, | |
| v, | |
| h, | |
| g, | |
| o, | |
| cu_seqlens, | |
| chunk_indices, | |
| scale, | |
| T=T, | |
| H=H, | |
| Hg=Hg, | |
| K=K, | |
| V=V, | |
| BT=BT, | |
| BK=128, | |
| BV=64, | |
| USE_G=g is not None, | |
| IS_VARLEN=cu_seqlens is not None, | |
| num_warps=4, | |
| num_stages=2, | |
| ) | |
| return o | |