vllm.model_executor.models.unlimited_ocr2
¶
Optional page-count stopping guard for Unlimited-OCR-2.
Classes:
-
PageCountGuard–Per-request page-count state machine over the generated tokens.
-
PageCountGuardLogitsProcessor–Page-count guard for Unlimited-OCR-2 multi-page parsing.
PageCountGuard
¶
Per-request page-count state machine over the generated tokens.
CPU-friendly core of the processor: token bookkeeping is plain Python ints/lists, only the one-row logits edit touches torch.
Methods:
-
seed_expected_pages–Count the prompt's page markers; called once the prompt is known.
-
step–Apply the guard to one row of logits, in place.
PageCountGuardLogitsProcessor
¶
Bases: LogitsProcessor
Page-count guard for Unlimited-OCR-2 multi-page parsing.
In the multi-page layout ("<PAGE><image>" * n_pages + "Multi page
parsing.") the model must emit exactly one <PAGE> marker per prompt
page marker. This request-level guard enforces that contract, mirroring
the reference _uocr_page_count_guard:
- while fewer
<PAGE>markers than prompt pages have been generated, EOS is masked so a page cannot be terminated early; - once the page count is reached EOS is allowed, and generating further
<PAGE>markers forces EOS; - each page is capped at
max_page_tokensgenerated tokens -- hitting the cap forces<PAGE>(next page) or EOS (last page); - prompts without a
<PAGE>marker (single-page requests) pass through.
Forced transitions yield to existing token masks from other sampling constraints when their target token is unavailable. EOS is retained if suppressing it would leave no finite logits.
Register it via the CLI::
--logits-processors \
vllm.model_executor.models.unlimited_ocr2:PageCountGuardLogitsProcessor
Per-request parameters are read from SamplingParams.extra_args
(page_token_id, eos_token_id, max_page_tokens); the token ids
fall back to hf_config.sparse_attention_config.page_token_id and
hf_config.eos_token_id when not given. The processor is inactive for
requests (or v1 configs) where no page token id can be resolved.
GPU state is keyed by the persistent request slot. The prompt is scanned once; subsequent steps scan only newly committed output tokens.