Skip to content

armgit / sie

Public Imported from GitHub
0

Open-source inference server and production cluster for all the models your agent needs.

fix(examples): support the LightOn photo transcription output limit

svonava2884f7333ead
diff --git a/examples/photo-transcription/README.md b/examples/photo-transcription/README.md
index e9da37477..1b2d58d69 100644
--- a/examples/photo-transcription/README.md
+++ b/examples/photo-transcription/README.md
@@ -55,8 +55,23 @@ An alternative endpoint can be supplied with `--sie-url`. Choose a model already
served there and freeze its checkpoint/runtime configuration separately. For
models with a plain default OCR task, omit `--instruction`; do not carry a
Florence task token into another model. The collector sends each full JPEG,
-original item ID, `profile=default`, `max_new_tokens=8192` and `num_beams=1`.
-`--max-new-tokens` accepts a smaller predeclared limit, never a larger one.
+original item ID, `profile=default` and `num_beams=1`. Its default output limit is
+8192 tokens; `--max-new-tokens` accepts up to 12288 for
+`lightonai/LightOnOCR-3-4B`, and up to 8192 for other models.
+
+The [recorded LightOnOCR-3-4B comparison](https://huggingface.co/datasets/superlinked/sie-task-evidence/tree/37c4f1efdfdca1c6459849ae1b02bec62156fe65/ocr-photo24-native-results/2026-10-10/addendum-03)
+used the plain default task with no instruction and a 12288-token output limit.
+To collect with those request controls against your `SIE_URL`:
+
+```bash
+python collect.py data native-lighton \
+ --model lightonai/LightOnOCR-3-4B \
+ --max-new-tokens 12288
+```
+
+The linked evidence records the checkpoint, runtime and review used for that
+comparison. The command collects new transcriptions; review them as described
+below before scoring. It does not rerun the saved provider arms or their reviews.
The public SDK uses an injected HTTP transport to save the actual MessagePack
request and reply bodies. It records at most one inference POST attempt per
diff --git a/examples/photo-transcription/collect.py b/examples/photo-transcription/collect.py
index 611536369..62cf504ab 100644
--- a/examples/photo-transcription/collect.py
+++ b/examples/photo-transcription/collect.py
@@ -27,8 +27,9 @@ def collect(
import httpx # Optional: only native collection needs the SDK transport.
from sie_sdk import SIEClient # Optional for the offline scorer.
- if not model or not 1 <= max_new_tokens <= 8192:
- raise ValueError("A model and a bounded output limit are required")
+ output_limit = 12288 if model == "lightonai/LightOnOCR-3-4B" else 8192
+ if not model or not 1 <= max_new_tokens <= output_limit:
+ raise ValueError(f"A model and an output limit between 1 and {output_limit} are required")
manifest, _ = load_packet(packet)
output.mkdir(parents=True, exist_ok=False)
calls: list[dict[str, Any]] = []
@@ -150,7 +151,9 @@ def main() -> None:
parser.add_argument("--model", required=True)
parser.add_argument("--sie-url", default=os.environ.get("SIE_URL"))
parser.add_argument("--instruction")
- parser.add_argument("--max-new-tokens", type=int, default=8192)
+ parser.add_argument(
+ "--max-new-tokens", type=int, default=8192, help="Up to 12288 for LightOnOCR-3-4B; up to 8192 for other models"
+ )
args = parser.parse_args()
if not args.sie_url:
parser.error("Provide --sie-url or SIE_URL for an existing remote deployment")
diff --git a/examples/photo-transcription/tests/test_fidelity.py b/examples/photo-transcription/tests/test_fidelity.py
index 5125c12a4..5c4d508d0 100644
--- a/examples/photo-transcription/tests/test_fidelity.py
+++ b/examples/photo-transcription/tests/test_fidelity.py
@@ -166,7 +166,13 @@ def mock_transport(monkeypatch, handler):
@pytest.mark.parametrize("base_url", ["https://ocr.example.test", "https://ocr.example.test/prefix"])
-def test_actual_sdk_sends_full_jpeg_and_exact_controls_once(packet, tmp_path, monkeypatch, base_url):
+ ("model", "instruction", "max_new_tokens"),
+ [("test/native", "Text Recognition:", 8192), ("lightonai/LightOnOCR-3-4B", None, 12288)],
+)
+def test_actual_sdk_sends_full_jpeg_and_exact_controls_once(
+ packet, tmp_path, monkeypatch, base_url, model, instruction, max_new_tokens
+):
seen = []
def handle(request):
@@ -174,7 +180,7 @@ def test_actual_sdk_sends_full_jpeg_and_exact_controls_once(packet, tmp_path, mo
payload = msgpack.unpackb(request.content, raw=False)
item = payload["items"][0]
body = {
- "model": "test/native",
+ "model": model,
"items": [
{"id": item["id"], "entities": [{"text": "Full source transcript", "label": "text", "score": 1.0}]}
],
@@ -187,7 +193,7 @@ def test_actual_sdk_sends_full_jpeg_and_exact_controls_once(packet, tmp_path, mo
monkeypatch.setenv("SIE_BASE_URL", base_url)
monkeypatch.setenv("SIE_API_KEY", "synthetic-fixture-credential")
output = tmp_path / "run"
- report = collector.collect(packet, output, "test/native", base_url, "Text Recognition:")
+ report = collector.collect(packet, output, model, base_url, instruction, max_new_tokens)
assert report["physical_inference_posts"] == 24
assert len(seen) == 24
manifest, _ = load_packet(packet)
@@ -195,20 +201,49 @@ def test_actual_sdk_sends_full_jpeg_and_exact_controls_once(packet, tmp_path, mo
body = msgpack.unpackb(request.content, raw=False)
assert body["items"][0]["id"] == source["id"]
assert body["items"][0]["images"][0]["data"] == (packet / source["input_image"]["path"]).read_bytes()
- assert body["params"] == {
- "instruction": "Text Recognition:",
- "options": {"profile": "default", "max_new_tokens": 8192, "num_beams": 1},
- }
+ assert body["items"][0]["images"][0]["format"] == "jpeg"
+ expected_params = {"options": {"profile": "default", "max_new_tokens": max_new_tokens, "num_beams": 1}}
+ if instruction is not None:
+ expected_params["instruction"] = instruction
+ assert body["params"] == expected_params
assert (output / "wire/00-request.msgpack").read_bytes() == seen[0].content
assert seen[0].headers["Authorization"] == "Bearer synthetic-fixture-credential"
assert all(b"synthetic-fixture-credential" not in path.read_bytes() for path in output.rglob("*") if path.is_file())
calls = [json.loads(line) for line in (output / "calls.jsonl").read_text().splitlines()]
- assert all(row["returned_model"] == "test/native" for row in calls)
+ assert all(row["returned_model"] == model for row in calls)
assert len(json.loads((output / "review-template.json").read_text())) == 24
with pytest.raises(FileExistsError):
collector.collect(packet, output, "test/native", "https://ocr.example.test")
+ ("model", "max_new_tokens", "limit"),
+ [
+ ("lightonai/LightOnOCR-3-4B", 12289, 12288),
+ ("lightonai/LightOnOCR-3-4B", 0, 12288),
+ ("zai-org/GLM-OCR", 8193, 8192),
+ ("lightonai/LightOnOCR-3-4B-other", 12288, 8192),
+ ("test/native", 0, 8192),
+ ("", 8192, 8192),
+ ],
+)
+def test_model_output_bounds_fail_before_transport_or_output(
+ packet, tmp_path, monkeypatch, model, max_new_tokens, limit
+):
+ seen = []
+
+ def handle(request):
+ seen.append(request)
+ raise AssertionError("Invalid controls must not reach the endpoint")
+
+ mock_transport(monkeypatch, handle)
+ output = tmp_path / "invalid"
+ with pytest.raises(ValueError, match=f"between 1 and {limit}"):
+ collector.collect(packet, output, model, "https://ocr.example.test", max_new_tokens=max_new_tokens)
+ assert seen == []
+ assert not output.exists()
+
+
def test_loading_error_is_one_post_and_preserves_all_remaining_cases(packet, tmp_path, monkeypatch):
seen = []