Open-source inference server and production cluster for all the models your agent needs.
Python bgecolbertdata-pipelinedeep-learningembeddingsinferenceinference-serverinformation-retrievalllmmlmlopsnatural-language-processingnlppythonrerankingretrievalretrieval-augmented-generationsemantic-searchspladevector-search
feat(models): add LightOnOCR-3-0.8B (#974)
Shai Shmuel0ffffd125470
diff --git a/packages/sie_server/models/lightonai__LightOnOCR-3-0.8B.yaml b/packages/sie_server/models/lightonai__LightOnOCR-3-0.8B.yamlnew file mode 100644index 000000000..7075d63c1--- /dev/null+++ b/packages/sie_server/models/lightonai__LightOnOCR-3-0.8B.yaml@@ -0,0 +1,130 @@+sie_id: lightonai/LightOnOCR-3-0.8B+hf_id: lightonai/LightOnOCR-3-0.8B+hf_revision: 36d8636925327c671bd8e479c517a004f7566bd9+inputs:+ text: false+ image: true+ audio: false+ video: false+tasks:+ encode: null+ score: null+ extract: {}+# Settings follow github.com/lightonai/LightOnOCR at 36755d461be079737860a5f03ae0c803501269e9+# (README, lightonocr/models.py and render.py, benchmarks/ocr_bench/providers/__init__.py) and the model card.+#+# Mode: omit `instruction` for plain Markdown transcription. Send exactly `grounding` to get a+# `` block marker, in 0-1000 page coordinates, before each layout block.+# These are the only two trained prompts. The adapter rejects any other prompt and thinking.+#+# Page image: the SGLang profiles bound each page to 65,536-5,242,880 pixels, the 5 MP cap that+# upstream's published benchmark scores used on 400 DPI pages. The processor downscales a larger+# page, keeping its aspect ratio, to at most 5,120 image tokens (one per 32x32 px cell): a 400 DPI+# US Letter page drops from 14,628 to 5,022. It applies the bound only when given both values.+# Pages rendered at 400 DPI and downscaled to a 2048 px longest edge, as the model card and the+# upstream client do, stay under the cap and reach the model as sent. The `transformers` profile+# keeps the checkpoint's 65,536-16,777,216 pixel range.+#+# Sampling: temperature 0.1, top_p 1.0, one beam. The upstream README says "use temperature 0.1,+# not greedy decoding", and the benchmark pipeline uses 0.1. The model card examples use 0.2.+#+# Output cap: 4,096 new tokens in a 24,576-token context, the max_tokens of the model card's vLLM+# example; the 4B descriptor keeps the upstream benchmark's 12,288. On the full olmOCR-bench split+# 12 of 1,403 official-recipe pages reach 4,096 (mostly tables and tiny text); a larger cap mostly+# spends GPU time on pages that loop. On the SGLang profiles a request's max_new_tokens replaces the+# default in either direction, and SGLang refuses a request whose page plus max_new_tokens exceeds+# the context. The `transformers` profile accepts 1-4,096 and rejects a larger value.+#+# Normalization: none beyond trimming leading and trailing whitespace, which the default SGLang+# profile applies; grounding markers are kept. The `transformers` profile returns the decoded text+# untrimmed. The upstream client repairs escaped math dollars by default. Upstream's published+# olmOCR-bench scores also drop header/footer/page-number blocks and apply its Markdown+# post-processing.+# The explicit `markdown` profile defaults to `grounding` and applies that published conversion:+# omit margin/aside blocks and leading unmarked text, repair escaped math dollars, then PP3.+# This is a lossy output policy; footnotes remain and all-margin pages can return empty text.+# Native opt-in: set loadtime `output_postprocess: lightonocr3_markdown` and send `grounding`.+#+# Serving: the default profile runs the checkpoint on SGLang (sglang-vision-extract bundle) with+# continuous batching, no system prompt, the chat template's enable_thinking=False, and only the+# two trained prompts accepted. The `transformers` profile runs the same contract in-process in the+# transformers5 bundle.+#+# Throughput: up to 256 pages are dispatched to the engine at once. SIE's HTTP client to SGLang+# allows 256 connections (max_connections=256 in+# SGLangGenerationAdapter._get_or_create_http_client), so 256 is the highest value that cannot+# exhaust that pool; past it, requests wait for a connection and fail with a PoolTimeout after 10 s+# unless SIE_SGLANG_GENERATE_POOL_TIMEOUT_S is raised. How many dispatched pages decode at once is+# decided by SGLang's own running-request limit. The radix cache is off: every page is a new image,+# so it saves nothing, and with it on SGLang turns overlap scheduling off for this hybrid (Gated+# DeltaNet) model. FlashInfer serves the attention layers. Sampling is unchanged and outputs stay+# within bf16 run-to-run variance.+#+# Memory: the 0.70 L4 reservation and the measurements below are inherited from the 4B descriptor's+# calibration and have not been re-measured on this 0.8B checkpoint. SGLang keeps+# (1 - mem_fraction_static) of the memory free at launch as runtime headroom. On the 4B, one page at+# the checkpoint's 16 MP limit peaks 4.8 GiB above the memory in use after load, in the vision+# encoder; on an L4, 0.75 and 0.85 run out of memory there and the engine exits, which fails every+# page in flight, while 0.70 leaves 0.7 GiB free at that peak. The 5 MP page cap lowers the peak.+max_sequence_length: 24576+profiles:+ default:+ max_batch_tokens: 16384+ compute_precision: bfloat16+ adapter_path: sie_server.adapters.sglang_vision_extract.adapter:SGLangVisionExtractAdapter+ adapter_options:+ loadtime:+ mem_fraction_static: 0.70+ served_model_name: lightonai/LightOnOCR-3-0.8B+ trust_remote_code: false+ max_concurrent_requests: 256+ meter_pages: true+ max_new_tokens: 4096+ temperature: 0.1+ top_p: 1.0+ chat_template_kwargs:+ enable_thinking: false+ allowed_instructions:+ - grounding+ attention_backend: flashinfer+ extra_launch_args:+ - --disable-radix-cache+ - --mm-process-config+ - '{"image":{"min_pixels":65536,"max_pixels":5242880}}'+ runtime:+ max_new_tokens: 4096+ num_beams: 1+ markdown:+ extends: default+ adapter_options:+ # Profile inheritance replaces loadtime, so retain every engine/sampling option.+ loadtime:+ mem_fraction_static: 0.70+ served_model_name: lightonai/LightOnOCR-3-0.8B+ trust_remote_code: false+ max_concurrent_requests: 256+ meter_pages: true+ max_new_tokens: 4096+ temperature: 0.1+ top_p: 1.0+ chat_template_kwargs:+ enable_thinking: false+ allowed_instructions:+ - grounding+ attention_backend: flashinfer+ extra_launch_args:+ - --disable-radix-cache+ - --mm-process-config+ - '{"image":{"min_pixels":65536,"max_pixels":5242880}}'+ default_prompt: grounding+ output_postprocess: lightonocr3_markdown+ transformers:+ max_batch_tokens: 16384+ compute_precision: bfloat16+ adapter_path: sie_server.adapters.lighton_ocr.adapter:LightOnOCR3Adapter+ adapter_options:+ loadtime:+ max_new_tokens: 4096+ temperature: 0.1+ top_p: 1.0+ runtime: {}diff --git a/packages/sie_server/tests/config/test_lightonocr3_profiles.py b/packages/sie_server/tests/config/test_lightonocr3_profiles.pyindex a3eb88a1d..7bc3bebf9 100644--- a/packages/sie_server/tests/config/test_lightonocr3_profiles.py+++ b/packages/sie_server/tests/config/test_lightonocr3_profiles.py@@ -1,6 +1,7 @@"""Public LightOnOCR-3 catalog pin, generation contract and bundle routing."""import json+from dataclasses import dataclassfrom pathlib import Pathfrom typing import Anyfrom unittest.mock import Mock@@ -17,18 +18,43 @@ _MODELS = _SERVER / "models"_BUNDLES = _SERVER / "bundles"_ADAPTER = "sie_server.adapters.lighton_ocr.adapter"_SGLANG_ADAPTER = "sie_server.adapters.sglang_vision_extract.adapter"-_MODEL = "lightonai/LightOnOCR-3-4B"-_REVISION = "b71010f095dc3735de7ee6b9969bff8f8f50b39a"-_CONFIG = _MODELS / "lightonai__LightOnOCR-3-4B.yaml"-_GENERATION = {"max_new_tokens": 12288, "do_sample": True, "num_beams": 1, "temperature": 0.1, "top_p": 1.0}+_GENERATION = {"do_sample": True, "num_beams": 1, "temperature": 0.1, "top_p": 1.0}_PAGE_PIXELS = {"min_pixels": 65536, "max_pixels": 5242880}_LAUNCH_ARGS = ["--disable-radix-cache", "--mm-process-config", '{"image":{"min_pixels":65536,"max_pixels":5242880}}']-def test_catalog_pins_checkpoint_and_upstream_generation() -> None:- config = yaml.safe_load(_CONFIG.read_text())- assert config["sie_id"] == config["hf_id"] == _MODEL- assert config["hf_revision"] == _REVISION+@dataclass(frozen=True)+class _Checkpoint:+ test_id: str+ model: str+ revision: str+ max_new_tokens: int+ concurrency: int++ @property+ def config_path(self) -> Path:+ return _MODELS / f"{self.model.replace('/', '__')}.yaml"+++# Shipped max_new_tokens and max_concurrent_requests. The 0.8B caps output at the model-card 4,096+# and dispatches 256 pages, the SIE->SGLang httpx pool ceiling (sglang/generation.py).+_CATALOG = (+ _Checkpoint("4B", "lightonai/LightOnOCR-3-4B", "b71010f095dc3735de7ee6b9969bff8f8f50b39a", 12288, 128),+ _Checkpoint("0.8B", "lightonai/LightOnOCR-3-0.8B", "36d8636925327c671bd8e479c517a004f7566bd9", 4096, 256),+)++[email protected](params=_CATALOG, ids=lambda checkpoint: checkpoint.test_id)+def catalog(request: pytest.FixtureRequest) -> _Checkpoint:+ return request.param+++def test_catalog_pins_checkpoint_and_upstream_generation(catalog: _Checkpoint) -> None:+ model, revision, config_path = catalog.model, catalog.revision, catalog.config_path+ max_new_tokens, concurrency = catalog.max_new_tokens, catalog.concurrency+ config = yaml.safe_load(config_path.read_text())+ assert config["sie_id"] == config["hf_id"] == model+ assert config["hf_revision"] == revisionassert config["inputs"] == {"text": False, "image": True, "audio": False, "video": False}assert config["tasks"] == {"encode": None, "score": None, "extract": {}}assert config["max_sequence_length"] == 24576@@ -38,111 +64,123 @@ def test_catalog_pins_checkpoint_and_upstream_generation() -> None:assert default["compute_precision"] == "bfloat16"loadtime = default["adapter_options"]["loadtime"]assert {key: loadtime[key] for key in ("max_new_tokens", "temperature", "top_p")} == {- "max_new_tokens": 12288,+ "max_new_tokens": max_new_tokens,"temperature": 0.1,"top_p": 1.0,}+ assert loadtime["served_model_name"] == modelassert loadtime["chat_template_kwargs"] == {"enable_thinking": False}assert loadtime["allowed_instructions"] == ["grounding"]assert loadtime["trust_remote_code"] is Falseassert loadtime["meter_pages"] is True- assert loadtime["max_concurrent_requests"] == 128+ assert loadtime["max_concurrent_requests"] == concurrencyassert loadtime["attention_backend"] == "flashinfer"assert loadtime["extra_launch_args"] == _LAUNCH_ARGSassert "system_prompt" not in loadtimeassert "extra_env" not in loadtimeassert "default_prompt" not in loadtimeassert "output_postprocess" not in loadtime- assert default["adapter_options"]["runtime"] == {"max_new_tokens": 12288, "num_beams": 1}+ assert default["adapter_options"]["runtime"] == {"max_new_tokens": max_new_tokens, "num_beams": 1}transformers = config["profiles"]["transformers"]assert transformers["adapter_path"] == f"{_ADAPTER}:LightOnOCR3Adapter"assert transformers["compute_precision"] == "bfloat16"assert transformers["adapter_options"] == {- "loadtime": {"max_new_tokens": 12288, "temperature": 0.1, "top_p": 1.0},+ "loadtime": {"max_new_tokens": max_new_tokens, "temperature": 0.1, "top_p": 1.0},"runtime": {},}-def test_loader_builds_pinned_sglang_default(monkeypatch: pytest.MonkeyPatch) -> None:+def test_loader_builds_pinned_sglang_default(catalog: _Checkpoint, monkeypatch: pytest.MonkeyPatch) -> None:+ revision, config_path = catalog.revision, catalog.config_path+ max_new_tokens, concurrency = catalog.max_new_tokens, catalog.concurrencyengine_load = Mock()monkeypatch.setattr(SGLangVisionExtractAdapter, "load", engine_load)- config = load_model_config(_CONFIG)+ config = load_model_config(config_path)validate_pinned_revision(config)adapter = load_adapter(config, _MODELS, device="cuda:0")assert isinstance(adapter, SGLangVisionExtractAdapter)- assert adapter._revision == _REVISION+ assert adapter._revision == revisionassert adapter._max_seq_length == 24576- assert adapter._max_new_tokens == 12288+ assert adapter._max_new_tokens == max_new_tokensassert (adapter._temperature, adapter._top_p) == (0.1, 1.0)assert adapter._system_prompt is Noneassert adapter._trust_remote_code is False- assert adapter.max_concurrent_dispatch() == 128+ assert adapter.max_concurrent_dispatch() == concurrencyassert adapter._extra_launch_args == _LAUNCH_ARGSengine_load.assert_not_called()-def test_transformers_profile_builds_profile_generation() -> None:- config = load_model_config(_CONFIG)+def test_transformers_profile_builds_profile_generation(catalog: _Checkpoint) -> None:+ model, revision, config_path = catalog.model, catalog.revision, catalog.config_path+ max_new_tokens = catalog.max_new_tokens+ config = load_model_config(config_path)profile = config.resolve_profile("transformers")assert profile.adapter_path == f"{_ADAPTER}:LightOnOCR3Adapter"loadtime: dict[str, Any] = dict(profile.loadtime)- adapter = LightOnOCR3Adapter(_MODEL, revision=config.hf_revision, **loadtime)- assert adapter._model_name_or_path == _MODEL- assert adapter._revision == _REVISION+ adapter = LightOnOCR3Adapter(model, revision=config.hf_revision, **loadtime)+ assert adapter._model_name_or_path == model+ assert adapter._revision == revisionassert adapter._compute_precision == "bfloat16"assert adapter._output_postprocess is None- assert adapter._generation_options({}) == _GENERATION+ assert adapter._generation_options({}) == {"max_new_tokens": max_new_tokens, **_GENERATION}assert adapter._generation_options({"max_new_tokens": 1024})["max_new_tokens"] == 1024with pytest.raises(ValueError, match="max_new_tokens"):- adapter._generation_options({"max_new_tokens": 12289})+ adapter._generation_options({"max_new_tokens": max_new_tokens + 1})-def test_markdown_profile_retains_default_generation_context_and_engine_options() -> None:- config = load_model_config(_CONFIG)+def test_markdown_profile_retains_default_generation_context_and_engine_options(+ catalog: _Checkpoint,+) -> None:+ model, revision, config_path = catalog.model, catalog.revision, catalog.config_path+ max_new_tokens, concurrency = catalog.max_new_tokens, catalog.concurrency+ config = load_model_config(config_path)default = config.resolve_profile("default")markdown = config.resolve_profile("markdown")assert config.max_sequence_length == 24576assert markdown.max_batch_tokens == default.max_batch_tokens == 16384assert markdown.compute_precision == default.compute_precision == "bfloat16"assert markdown.adapter_path == default.adapter_path == f"{_SGLANG_ADAPTER}:SGLangVisionExtractAdapter"- assert dict(markdown.runtime) == dict(default.runtime) == {"max_new_tokens": 12288, "num_beams": 1}+ assert dict(markdown.runtime) == dict(default.runtime) == {"max_new_tokens": max_new_tokens, "num_beams": 1}assert dict(markdown.loadtime) == {**default.loadtime,"default_prompt": "grounding","output_postprocess": "lightonocr3_markdown",}variants = expand_profile_variants([config])- variant = variants[f"{_MODEL}:markdown"]+ variant = variants[f"{model}:markdown"]validate_pinned_revision(variant)adapter = load_adapter(variant, _MODELS, device="cuda:0")assert isinstance(adapter, SGLangVisionExtractAdapter)- assert adapter._revision == _REVISION+ assert adapter._revision == revisionassert adapter._compute_precision == "bfloat16"assert adapter._max_seq_length == 24576assert adapter._output_postprocess == "lightonocr3_markdown"assert adapter._resolve_prompt_and_label(None, {}) == ("grounding", "markdown")- assert adapter._max_new_tokens == 12288+ assert adapter._max_new_tokens == max_new_tokensassert (adapter._temperature, adapter._top_p) == (0.1, 1.0)assert adapter._chat_template_kwargs == {"enable_thinking": False}assert adapter._allowed_instructions == frozenset({"grounding"})assert adapter._meter_pages is True- assert adapter.max_concurrent_dispatch() == 128+ assert adapter.max_concurrent_dispatch() == concurrencyassert adapter._extra_launch_args == _LAUNCH_ARGS-def test_sglang_profiles_keep_their_l4_calibrated_reservation() -> None:- profiles = yaml.safe_load(_CONFIG.read_text())["profiles"]+def test_sglang_profiles_keep_their_l4_reservation_and_concurrency(catalog: _Checkpoint) -> None:+ profiles = yaml.safe_load(catalog.config_path.read_text())["profiles"]for name in ("default", "markdown"):loadtime = profiles[name]["adapter_options"]["loadtime"]assert loadtime["mem_fraction_static"] == 0.70- assert loadtime["max_concurrent_requests"] == 128+ assert loadtime["max_concurrent_requests"] == catalog.concurrency-def test_sglang_profiles_cap_a_page_at_5_mp_within_the_context(monkeypatch: pytest.MonkeyPatch) -> None:+def test_sglang_profiles_cap_a_page_at_5_mp_within_the_context(+ catalog: _Checkpoint, monkeypatch: pytest.MonkeyPatch+) -> None:+ model, config_path = catalog.model, catalog.config_pathmonkeypatch.setattr(SGLangVisionExtractAdapter, "load", Mock())- config = load_model_config(_CONFIG)+ config = load_model_config(config_path)variants = expand_profile_variants([config])- for variant in (config, variants[f"{_MODEL}:markdown"]):+ for variant in (config, variants[f"{model}:markdown"]):adapter = load_adapter(variant, _MODELS, device="cuda:0")assert isinstance(adapter, SGLangVisionExtractAdapter)args = adapter._extra_launch_args@@ -152,12 +190,13 @@ def test_sglang_profiles_cap_a_page_at_5_mp_within_the_context(monkeypatch: pyteassert adapter.image_token_budget + adapter._max_new_tokens < config.max_sequence_length-def test_default_routes_to_sglang_vision_extract_bundle_only() -> None:+def test_default_routes_to_sglang_vision_extract_bundle_only(catalog: _Checkpoint) -> None:+ model = catalog.modelassert _ADAPTER in yaml.safe_load((_BUNDLES / "transformers5.yaml").read_text())["adapters"]for bundle in sorted(_BUNDLES.glob("*.yaml")):expected = bundle.name == "sglang-vision-extract.yaml"- assert (_MODEL in match_bundle_models(bundle, _MODELS)) == expected, bundle.name- assert (f"{_MODEL}:markdown" in match_bundle_models(bundle, _MODELS)) == expected, bundle.name- assert (f"{_MODEL}:transformers" in match_bundle_models(bundle, _MODELS)) == (+ assert (model in match_bundle_models(bundle, _MODELS)) == expected, bundle.name+ assert (f"{model}:markdown" in match_bundle_models(bundle, _MODELS)) == expected, bundle.name+ assert (f"{model}:transformers" in match_bundle_models(bundle, _MODELS)) == (bundle.name == "transformers5.yaml")