Buckets:
| Name | Size | Uploaded | Xet hash |
|---|---|---|---|
| benchmarks | 7 items | ||
| clairic_sm120 | 5 items | ||
| patches | 3 items | ||
| quantization | 2 items | ||
| ENGINEERING_REPORT.md | 21.2 kB xet | 76a45bc3 | |
| README.md | 21.2 kB xet | 81a445fd | |
| pyproject.toml | 726 Bytes xet | b0abfb1b |
clairic-sm120-serve — Concurrent SGLang Serving Engine, SM120 Triton Kernels, Quantization Pipeline, and SGLang Patch Set for Cloudflare/clairic
geudrik/clairic-sm120-serve provides the serving stack, custom SM120 Triton kernels, quantization scripts, SGLang v0.5.23 unified diff set, and benchmark suite for running Cloudflare/clairic (27.3B hybrid multimodal structured extraction, estimation, and forecasting model) concurrently on a single NVIDIA RTX PRO 6000 Blackwell (sm_120, 96 GB GDDR7).
Paired with geudrik/clairic-27b-nvfp4-sm120, this stack increases concurrent mixed-workload throughput from 0.225 req/s (1.44 fields/s) to 1.788 req/s (11.40 fields/s, 7.95x), lowers p95 tail latency at concurrency 16 from 71.15 s to 9.53 s (7.47x lower), accelerates ClairicHead GPU readout by 11.20x to 49.07x, compresses model weights from 55.60 GiB to 21.12 GiB, and preserves 51/51 (100.0%) exact golden field parity against the BF16 reference.
Repository Ecosystem
| Repository / Resource | Contents | Size | Role |
|---|---|---|---|
geudrik/clairic-sm120-serve |
clairic_sm120 Python package, CLI (clairic-sm120-serve), patches/sglang-v0.5.23-clairic-sm120.patch, quantization/, benchmarks/ |
Code + JSON | Serving engine, Triton kernels, SGLang patch set, quantization & benchmark harness |
geudrik/clairic-27b-nvfp4-sm120 |
Boundary-protected Mixed NVFP4 + FP8 checkpoint + bundled clair_head, clairic_runtime, patches/, benchmarks/results/ |
21.12 GiB |
Highest concurrent throughput (7.95x, 1.788 req/s) with 51/51 (100%) golden parity |
geudrik/clairic-27b-fp8-sm120 |
Block-128 Dynamic FP8 (W8A8 e4m3fn) checkpoint + bundled clair_head, clairic_runtime, patches/, benchmarks/results/ |
28.75 GiB |
Tightest confidence calibration (mean abs Δ conf = 0.0093, 6.04x, 1.358 req/s, 51/51 parity) |
hf://buckets/geudrik/clairic-sm120-work |
Raw JSON benchmark outputs and reference golden responses | 136 KB |
Persistent raw measurement archive |
1. Model Architecture and SM120 Bottlenecks Resolved
Cloudflare/clairic combines a fine-tuned Qwen3_5ForConditionalGeneration 27.33B backbone (64 decoder layers: 48 Gated DeltaNet linear_attention blocks + 16 gated full_attention GQA blocks with 24 query heads, 4 KV heads, head_dim = 256, vocab_size = 248,320, and a 27-layer vision transformer) with a 290 MB FP32 2-layer cross-attention readout module (ClairicHead in clair_head.safetensors).
- Autoregressive extraction (
_ar_all): Standard fields (text,number,boolean,enum,object,list, and literal printed dates) execute parallelxgrammar-constrained greedy autoregressive prompts (parallel-ar-json-scalar-v1) withoutClairicHead. Post-grammar-mask log probabilities over the chosen token andnull/falsetokens establishconfidenceandp_null. - Non-autoregressive typed readout (
read_typed):compute,duration,estimate,forecast(with quantiles), and non-literal temporal fields insert<|fim_pad|>answer slots into a single prompt pass (use_cache=False) and read final-layer hidden states throughClairicHead.
Profiling Cloudflare/clairic's built-in TransformersEngine on RTX PRO 6000 (sm_120) exposed three bottlenecks:
- Single-Request Queue Serialization and Frontend State Coupling:
TransformersEngineruns eager PyTorchsdpabehind a single worker thread (batch_size = 8,batch_token_budget = 8192), raisingClairQueueFullabove concurrency1, whileClairic27BModel(clairic_runtime/large.py) disables 27B list-gating,po_image_supplement, andmedia_state_promptifRuntimeSettings.max_concurrency != 1.- Resolution (
clairic_sm120/engine.py):ClairicConcurrentServicemaintains anasyncio.Queuepool of24–32isolatedClairic27BModelslots (max_concurrency = 1per slot, preserving 100% of 27B multimodal and list behaviors without shared-state races) multiplexing GPU execution onto a singleSGLangClairicEnginewith piecewise prefill and decode CUDA graphs.
- One-Shot Extraction Memory Sizing (
147.75 MiBGated DeltaNet State vs.64 KiB/tokKV Cache):- Across 16 GQA layers (
4KV heads,head_dim = 256), BF16 KV cache costs only64 KiB/token(6.1 GiBper100,000active tokens), whereas each FP32 Gated DeltaNet recurrent +conv1dstate slot across 48 layers costs147.75 MiB. - Incoming
Clairicrequests are one-shot extractions with a fresh randomuuid.uuid4().hexcache_saltper request (clairic_runtime/backend.py), so cross-request prefix caching has a 0% hit rate. Any state slot retained after a request finishes is dead VRAM. - Resolution:
clairic-sm120-servedefaults to native BF16 KV cache (--kv-cache-dtype auto),16,384chunked prefill,~19 GiBdynamic ViT/activation headroom (--mem-fraction-static 0.80), and either a bounded in-flight ephemeral pool (--max-mamba-cache-size 180for intra-request multi-field fan-out) or--disable-radix-cache(1GDN slot per active sequence, freeing30+ GiBof GDDR7 forClairicHeador low-fanout workloads).
- Across 16 GQA layers (
ClairicHeadTorchDispatchModeOverhead and[B, 248,320]Logprob HBM Traffic:- Reference
ClairicHeadruns underReadoutMath(a PythonTorchDispatchModedecomposing linear layers into FP32 chunks), recomputesmemory_normper layer acrossrouteandanswer_slot_states, materializes[F, S, 64]FP32 span tensors, and materializes[rows, 248,320]FP32log_softmaxtensors. Similarly, SGLang's greedySampler.forwardallocates[B, 248,320]FP32log_softmaxand runsBseparatetorch.tensor(..., pin_memory=True).to(device)operations per decode step. - Resolution (
clairic_sm120/kernels.py+patches/sglang-v0.5.23-clairic-sm120.patch): Custom SM120 Triton kernels executeClairicHead(11.20x–49.07xfaster) and greedy vocabulary logprob reductions (9.16xfaster) directly inside SGLang's GPU worker.
- Reference
2. SGLang v0.5.23 Unified Diff Set (patches/)
patches/sglang-v0.5.23-clairic-sm120.patch applies cleanly against sgl-project/sglang tag v0.5.23 (including /sgl-workspace/sglang inside lmsysorg/sglang:v0.5.23-cu130 and wheel-installed site-packages/sglang).
Summary of Patch Changes
python/sglang/srt/layers/clairic_sm120.py(new module): Self-contained SM120 Triton kernels (fused_span_argmax_prob,fused_vocab_argmax_logprob,fast_read_slots,fast_read_layout_gpu_only) plusmaybe_run_extend(ClairicHeadGPU readout writing ~2 KB compact vectors to/dev/shm) andrun_fused_greedy_logprob(batched H2D + single-pass Triton greedy logprob reduction).python/sglang/srt/layers/logits_processor.py&python/sglang/srt/layers/sampler.pyhunks:
--- a/python/sglang/srt/layers/logits_processor.py
+++ b/python/sglang/srt/layers/logits_processor.py
@@ -15,6 +15,7 @@
import dataclasses
import logging
+import os
@@ -77,6 +78,11 @@
logger = logging.getLogger(__name__)
+
+_CLAIRIC_NATIVE_PATCH = True
+_CLAIRIC_HEAD_ENABLED = bool(os.environ.get("CLAIRIC_HEAD_DIR"))
+if _CLAIRIC_HEAD_ENABLED:
+ from sglang.srt.layers import clairic_sm120 as _clairic_sm120
@@ -568,6 +574,9 @@ class LogitsProcessor(nn.Module):
forward_mode=logits_metadata.forward_mode,
)
+ if _CLAIRIC_HEAD_ENABLED:
+ _clairic_sm120.maybe_run_extend(hidden_states, lm_head, logits_metadata)
--- a/python/sglang/srt/layers/sampler.py
+++ b/python/sglang/srt/layers/sampler.py
@@ -80,6 +80,10 @@
SYNC_TOKEN_IDS_ACROSS_TP = get_bool_env_var("SYNC_TOKEN_IDS_ACROSS_TP")
SGLANG_RETURN_ORIGINAL_LOGPROB = get_bool_env_var("SGLANG_RETURN_ORIGINAL_LOGPROB")
+_CLAIRIC_NATIVE_PATCH = True
+_CLAIRIC_FUSED_SAMPLER = get_bool_env_var("CLAIRIC_FUSED_SAMPLER")
+if _CLAIRIC_FUSED_SAMPLER:
+ from sglang.srt.layers import clairic_sm120 as _clairic_sm120
@@ -206,6 +210,21 @@ class Sampler(nn.Module):
if sampling_info.is_all_greedy:
+ if (
+ _CLAIRIC_FUSED_SAMPLER
+ and return_logprob
+ and target_logprobs is None
+ and not return_sampling_mask
+ and _clairic_sm120.can_run_fused_greedy(logits, top_logprobs_nums)
+ ):
+ batch_next_token_ids = _clairic_sm120.run_fused_greedy_logprob(
+ logits, logits_output, token_ids_logprobs
+ )
+ _trace_e2e_sampler("token_sync_enter")
+ self._sync_token_ids_across_tp(batch_next_token_ids, sampling_info)
+ _trace_e2e_sampler("token_sync_returned")
+ _trace_e2e_sampler("forward_returned")
+ return batch_next_token_ids
Applying the Patch
# Automatic helper (supports both /sgl-workspace/sglang git checkouts and pip wheel site-packages)
python3 patches/apply_sglang_patch.py --check
python3 patches/apply_sglang_patch.py
# Or directly via git apply on an SGLang v0.5.23 checkout:
git -C /sgl-workspace/sglang apply patches/sglang-v0.5.23-clairic-sm120.patch
When sglang.srt.layers.clairic_sm120 is present, SGLangClairicEngine.load uses the native patch directly; on unpatched environments, it falls back automatically to clairic_sm120/sgl_hook/sitecustomize.py.
3. Benchmarks on NVIDIA RTX PRO 6000 (sm_120, 96 GB GDDR7)
Testbed & Conditions: Single NVIDIA RTX PRO 6000 Blackwell Server Edition (97,887 MiB), Linux x86_64, Docker image lmsysorg/sglang:v0.5.23-cu130 (sglang==0.5.23, torch==2.14.1+cu130, triton==3.8.0, flashinfer==0.7.2, modelopt==0.47.0; transformers==5.10.2 isolated in /tmp/tf510 for exact TransformersEngine baseline and PTQ loading). All raw JSON outputs are stored in benchmarks/results/.
Workload Suite (benchmarks/workload_suite.py): 8 deterministic mixed cases totaling 51 extracted/computed fields per pass across text invoices (case1), nested JSON table row objects (case2), rendered receipt image OCR (case3), 2-page purchase-order images totaling 85,525 input tokens (case4), pure ClairicHead compute/duration/estimate/forecast with quantiles (case5), hybrid receipt image + AR + ClairicHead (case6), 2,358-token incident report (case7), and 4-field triage (case8).
3.1 Concurrent Mixed-Workload Scaling (C = 1 .. 32)
| Configuration | Checkpoint Size | Golden Match | Mean Abs Δ Conf | C=1 req/s (p50 / p95) |
C=4 req/s (p50 / p95) |
C=8 req/s (p50 / p95) |
C=16 req/s (p50 / p95) |
C=32 req/s (p50 / p95) |
Peak Speedup |
|---|---|---|---|---|---|---|---|---|---|
Baseline TransformersEngine (BF16, SDPA) |
55.60 GiB |
Ref 51/51 |
0.0000 |
0.225 (3.55s / 17.53s) |
0.226 (15.20s / 28.17s) |
0.225 (23.47s / 35.53s) |
0.225 (41.40s / 71.15s) |
Queue-serialized | 1.00x |
SGLang SM120 + Kernels (BF16, mamba=150) |
55.60 GiB |
51/51 (100%) |
0.0037 |
0.563 (1.61s / 3.97s) |
0.781 (4.28s / 9.49s) |
0.819 (7.88s / 9.76s) |
0.846 (16.11s / 18.91s) |
0.671 (27.20s / 47.50s) |
3.76x |
Block-128 Dynamic FP8 (clairic-27b-fp8-sm120) |
28.75 GiB |
51/51 (100%) |
0.0093 |
0.847 (1.00s / 2.55s) |
1.215 (2.94s / 6.13s) |
1.302 (5.61s / 6.15s) |
1.342 (9.54s / 11.91s) |
1.358 (20.01s / 23.37s) |
6.04x |
Boundary-Protected NVFP4 + FP8 (clairic-27b-nvfp4-sm120) |
21.12 GiB |
51/51 (100%) |
0.0424 |
1.074 (0.76s / 2.20s) |
1.552 (2.27s / 4.70s) |
1.683 (4.30s / 4.75s) |
1.677 (7.40s / 9.53s) |
1.788 (14.34s / 17.77s) |
7.95x |
| Ablation: All-64-MLP NVFP4 + FP8 | 19.81 GiB |
50/51 (98.0%) |
0.0478 |
1.126 (0.71s / 2.14s) |
1.631 (2.17s / 4.53s) |
1.669 (4.39s / 4.79s) |
1.840 (6.67s / 8.69s) |
1.863 (13.60s / 17.09s) |
8.28x |
Ablation: FP8 + Dormant Shard-18 NEXTN MTP |
28.75 GiB |
47/51 (92.2%) |
0.0815 |
0.945 (0.83s / 2.44s) |
1.165 (3.14s / 6.83s) |
1.142 (5.67s / 7.00s) |
1.144 (8.86s / 13.96s) |
0.927 (19.98s / 34.19s) |
5.18x |
3.2 Per-Workload Single-Request Latency
| Case ID | Modality & Schema | Fields | Baseline BF16 | SGLang BF16 | Block-128 FP8 | Boundary-FP8 + NVFP4 |
|---|---|---|---|---|---|---|
case1_text_invoice |
Text scalars + list + enum | 9 | 2.30 s |
1.66 s |
1.07 s |
0.81–1.71 s |
case2_text_table_objects |
Nested JSON object list | 4 | 2.36 s |
1.86 s |
1.17 s |
0.92 s |
case3_image_receipt |
Rendered receipt image OCR | 7 | 6.33 s |
6.52 s |
2.62 s |
2.41 s |
case4_two_page_po_images |
2-page PO images (85,525 input tok) |
8 | 17.46 s |
3.36 s |
2.61 s |
2.38 s (7.34x) |
case5_clairic_head_typed |
compute, duration, estimate, forecast |
5 | 22.49 s* |
0.19 s |
0.13 s |
0.10 s (100 ms) |
case6_hybrid_multimodal_ar_and_head |
Receipt image + AR + ClairicHead |
5 | 7.16 s |
1.28 s |
0.56 s |
0.48 s (14.92x) |
case7_long_context_mixed |
2,358-token incident report |
9 | 5.55 s |
4.71 s |
2.55 s |
1.87 s |
case8_compact_triage |
Compact 4-field triage | 4 | 0.52 s |
0.45 s |
0.27 s |
0.21 s |
*Baseline case5 includes first-call Triton GDN compilation; steady-state isolated ClairicHead GPU readout speedups are reported below.
3.3 Custom SM120 Triton Kernel Microbenchmarks (benchmarks/bench_and_verify_kernels.py)
| Kernel / Subsystem | Tested Shape | Reference Latency (Peak HBM) | SM120 Kernel Latency (Peak HBM) | Speedup | Numerical Agreement |
|---|---|---|---|---|---|
fused_span_argmax_prob |
F=8, S=16,384, W=64 |
0.214 ms (32.5 MiB) |
0.044 ms (0.03 MiB) |
4.84x |
100% exact argmax; 4.46e-10 max prob diff |
fused_span_argmax_prob |
F=16, S=65,273, W=64 |
1.776 ms (258.0 MiB) |
0.063 ms (0.13 MiB) |
28.01x |
100% exact argmax; 2.62e-10 max prob diff |
fused_vocab_argmax_logprob (masked) |
B=32, V=248,320 + xgrammar bitmask |
0.156 ms (75.8 MiB) |
0.039 ms (0.03 MiB) |
4.03x |
100% exact argmax; 1.91e-06 max lp diff |
fused_vocab_argmax_logprob (masked) |
B=128, V=248,320 + xgrammar bitmask |
0.575 ms (303.1 MiB) |
0.063 ms (0.12 MiB) |
9.16x |
100% exact argmax; 9.54e-07 max lp diff |
fast_read_slots (GEMM + vocab reduce) |
rows=1024, H=5120, V=248,320 |
14.230 ms (485 MiB @ 256) |
7.081 ms (121.5 MiB @ 256) |
2.01x |
100% exact token ID; 9.54e-07 max lp diff |
fast_read_layout_gpu_only (ClairicHead) |
S=3,167, 5 typed fields |
84.20 ms (279.8 MiB) |
7.52 ms (177.2 MiB) |
11.20x |
100% discrete exact; 1.4e-4 max float rel diff |
fast_read_layout_gpu_only (ClairicHead) |
S=34,808, 5 typed fields |
704.70 ms (1,787.4 MiB) |
14.36 ms (608.4 MiB) |
49.07x |
100% discrete exact; 1.4e-4 max float rel diff |
4. Production Serving Quickstart
Inside lmsysorg/sglang:v0.5.23-cu130 (or any Python >=3.11 + SGLang 0.5.23 CUDA 13.0 environment):
git clone https://huggingface.co/geudrik/clairic-sm120-serve
cd clairic-sm120-serve
pip install -e .
# Optional: apply the native SGLang patch in-place (otherwise sitecustomize hook activates automatically)
python3 patches/apply_sglang_patch.py
Mode A: Mixed Multi-Field Extraction (Ephemeral Intra-Request Pool, Native BF16 KV, ~19 GiB Headroom)
hf download geudrik/clairic-27b-nvfp4-sm120 --local-dir /models/clairic-27b-nvfp4-sm120
clairic-sm120-serve \
--model-path /models/clairic-27b-nvfp4-sm120 \
--kv-cache-dtype auto \
--mem-fraction-static 0.80 \
--max-mamba-cache-size 180 \
--max-running-requests 60 \
--chunked-prefill-size 16384 \
--pool-size 24 \
--host 0.0.0.0 \
--port 8000
Mode B: One-Shot ClairicHead / Low-Fanout Extraction (--disable-radix-cache, Frees 30+ GiB GDDR7)
clairic-sm120-serve \
--model-path /models/clairic-27b-nvfp4-sm120 \
--disable-radix-cache \
--kv-cache-dtype auto \
--mem-fraction-static 0.72 \
--max-running-requests 96 \
--chunked-prefill-size 16384 \
--pool-size 32 \
--host 0.0.0.0 \
--port 8000
5. End-to-End Reproduction Instructions
Run all commands inside lmsysorg/sglang:v0.5.23-cu130 on an NVIDIA RTX PRO 6000 (sm_120, 96 GB) with Cloudflare/clairic staged at /tmp/clairic:
# 1. Install runtime dependencies and isolated transformers==5.10.2 for reference baseline & ModelOpt PTQ
pip install --no-cache-dir pypdfium2 jsonschema einops
pip install --no-cache-dir --no-deps --target /tmp/tf510 "transformers==5.10.2" "tokenizers==0.22.2"
# 2. Clone serving & benchmark repo and apply SGLang v0.5.23 patch
git clone https://huggingface.co/geudrik/clairic-sm120-serve /workspace/clairic-sm120-serve
cd /workspace/clairic-sm120-serve
pip install --no-deps -e .
python3 patches/apply_sglang_patch.py
# 3. Reproduce reference TransformersEngine BF16 baseline & golden responses
PYTHONPATH=/tmp/tf510:/workspace/clairic-sm120-serve/benchmarks \
python3 benchmarks/run_baseline_and_profile.py \
--model-dir /tmp/clairic \
--golden-out /tmp/golden_responses.json \
--report-out /tmp/baseline_sm120.json
# 4. Reproduce isolated SM120 Triton kernel microbenchmarks & numerical verification
PYTHONPATH=/tmp/tf510:/workspace/clairic-sm120-serve/clairic_sm120:/workspace/clairic-sm120-serve/benchmarks \
python3 benchmarks/bench_and_verify_kernels.py \
--model-dir /tmp/clairic \
--output /tmp/kernel_benchmarks_sm120.json
# 5. Reproduce Block-128 Dynamic FP8 checkpoint (28.75 GiB, ~37s on SM120)
python3 quantization/quantize_fp8_block128.py \
--src-dir /tmp/clairic \
--dst-dir /tmp/clairic-fp8 \
--scale-dtype bfloat16
# 6. Reproduce Boundary-Protected Mixed NVFP4 + FP8 checkpoint (21.12 GiB, ~46s on SM120)
PYTHONPATH=/tmp/tf510 \
python3 quantization/quantize_nvfp4_mixed.py \
--src-dir /tmp/clairic \
--dst-dir /tmp/clairic-nvfp4-v2
# 7. Reproduce SGLang SM120 golden parity & C=1..32 concurrency sweep
PYTHONPATH=/workspace/clairic-sm120-serve:/workspace/clairic-sm120-serve/clairic_sm120:/workspace/clairic-sm120-serve/benchmarks \
python3 benchmarks/bench_sglang_engine.py \
--label sglang_nvfp4_boundary_fp8_sm120 \
--model-path /tmp/clairic-nvfp4-v2 \
--head-source-path /tmp/clairic \
--golden-json /tmp/golden_responses.json \
--output-json /tmp/bench_nvfp4_boundary_fp8.json \
--kv-cache-dtype fp8_e4m3 \
--mem-fraction-static 0.86 \
--max-mamba-cache-size 370 \
--max-running-requests 60 \
--pool-size 24
# 8. Verify live FastAPI + Uvicorn HTTP endpoints (/v1/extract, /systemone, /health, HTTP 400 validation)
PYTHONPATH=/workspace/clairic-sm120-serve:/workspace/clairic-sm120-serve/clairic_sm120:/workspace/clairic-sm120-serve/benchmarks \
python3 benchmarks/verify_http_server.py \
--model-path /tmp/clairic-nvfp4-v2 \
--head-source-path /tmp/clairic \
--output-json /tmp/http_live_verification.json
6. Qualification Scope and Known Limitations
- Hardware Scope: Qualified on a single NVIDIA RTX PRO 6000 Blackwell Server Edition (
sm_120, 96 GB) with SGLang0.5.23(cu130).geudrik/clairic-27b-nvfp4-sm120requires Blackwell (sm_100/sm_120) FP4 Tensor Cores;geudrik/clairic-27b-fp8-sm120runs on both Hopper (sm_90) and Blackwell (sm_100/sm_120). - Dormant Shard-18
MTP(NEXTN):Cloudflare/clairicretains baseQwen/Qwen3.8-27Bmtp.layers.0weights in shard 18 with"mtp_num_hidden_layers": 0. Because those draft weights were not fine-tuned alongsideClairicand reserve extra Mamba/KV memory, enablingNEXTNlowersC = 32throughput by32%(1.358 -> 0.927 req/s) and degrades typed fields (47/51); leavemtp_num_hidden_layers = 0. - Multi-GPU Tensor Parallelism:
tp_size > 1has not been tested with the single-rank/dev/shmClairicHeadreadout IPC path.
- Total size
- 2.9 MB
- Files
- 64
- Last updated
- Nov 29
- Pre-warmed CDN
- US EU US EU