Run this model with HF Jobs

Run OpenTensorLab/OCRia-1-W4A16-AutoRound on Hugging Face's managed compute, monitor its progress, and retrieve the results when it's done.

Paste one of these prompts into your coding agent:

Fine-tune on my dataset

Use HF Jobs and TRL to fine-tune https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-AutoRound. Ask me which dataset to train on, then push the fine-tuned model to a new model repo. Run `hf jobs --help` first to learn the CLI.

Run batch inference

Use HF Jobs to run batch inference with https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-AutoRound on the inputs in a mounted HF Bucket. Ask me which Bucket to use, then write the outputs back to it and keep each input ID. Run `hf jobs --help` first to learn the CLI.

Evaluate on a benchmark

Use HF Jobs to evaluate https://huggingface.co/OpenTensorLab/OCRia-1-W4A16-AutoRound. Ask me which benchmark to run, then save the scores and the per-example results to a new dataset repo. Run `hf jobs --help` first to learn the CLI.
File size: 3,585 Bytes
90d9faa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Copyright (c) 2026 LlamaIndex, Inc. All rights reserved.
# Licensed under the OCRia-1 Model and Code License (LICENSE at the root of this repository).
# This is not open-source software: see the license for permitted uses.
"""CUDA smoke: synthetic text/table pages, fast pixel isolation, and legacy stability.

Run from the repository root with PYTHONPATH=. python tests/check_cuda_layout.py.
"""

import argparse
import json
from pathlib import Path


def check(model: str) -> dict:
    import time
    import numpy as np
    import torch
    from PIL import Image, ImageDraw, ImageFont
    from ocria_grounding import (
        load,
        load_fast_layout,
        ground_layout,
        transcribe,
        to_layout_items_page,
    )
    import ocria_grounding.layout as layout
    import ocria_grounding.ground as legacy_ground

    t = time.perf_counter()
    g = load(model)
    backend = load_fast_layout()
    load_seconds = time.perf_counter() - t
    result = {
        "device": torch.cuda.get_device_name(),
        "model_load_seconds": load_seconds,
        "pages": [],
    }
    for index, text in enumerate(
        [
            "FAST LAYOUT TEST\n\nA short paragraph on a test page.\nThe second line has more words.",
            "INVOICE\n\nItem        Quantity        Price\nApples      3               6.00\nPears       2               4.00\n\nTotal                       10.00",
        ]
    ):
        image = Image.new("RGB", (640, 480), "white")
        draw = ImageDraw.Draw(image)
        draw.multiline_text(
            (35, 35),
            text,
            fill="black",
            font=ImageFont.load_default(size=20),
            spacing=14,
        )
        started = time.perf_counter()
        answer = transcribe(g, image, max_new_tokens=256)
        transcription = time.perf_counter() - started
        old = ground_layout(g, image, answer)
        old_page = layout.Page

        def reject_pixels(*args: object, **kwargs: object) -> None:
            raise AssertionError("fast-layout touched pixel postprocessing")

        layout.Page = reject_pixels
        legacy_ground.Page = reject_pixels
        try:
            fast = ground_layout(
                g, image, answer, method="fast-layout", fast_backend=backend
            )
        finally:
            layout.Page = old_page
            legacy_ground.Page = old_page
        after = ground_layout(g, image, answer)
        assert old == after, "Fast layout changed subsequent default output"
        serialized = to_layout_items_page(fast)
        for item in fast["items"]:
            assert np.isfinite(item["box"]).all()
            assert item["box"][2] >= item["box"][0] and item["box"][3] >= item["box"][1]
        assert fast["items"], "No fast layout items"
        result["pages"].append(
            {
                "index": index,
                "answer": answer,
                "default_items": len(old["items"]),
                "fast_items": len(fast["items"]),
                "default_before_after_equal": True,
                "transcription_seconds": transcription,
                "timings_ms": fast["timings_ms"],
                "serialization_items": len(serialized["items"]),
            }
        )
    result["peak_gpu_memory_bytes"] = torch.cuda.max_memory_allocated()
    return result


if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--model", default=str(Path(__file__).resolve().parents[1]))
    args = parser.parse_args()
    print(json.dumps(check(args.model), indent=2))